make memory tracker work without onThreadCreation

This commit is contained in:
Araq 2017-03-14 15:45:35 +01:00
commit 98c7bab8ea
3 changed files with 26 additions and 13 deletions

View file

@ -23,12 +23,6 @@ var
const insertQuery = "INSERT INTO tracking(op, address, size, file, line) values (?, ?, ?, ?, ?)"
when compileOption("threads"):
onThreadCreation do():
if prepare_v2(dbHandle, insertQuery,
insertQuery.len, insertStmt, nil) != SQLITE_OK:
quit "could not bind query to insertStmt " & $sqlite3.errmsg(dbHandle)
template sbind(x: int; value) =
when value is cstring:
let ret = insertStmt.bindText(x, value, value.len.int32, SQLITE_TRANSIENT)
@ -41,6 +35,10 @@ template sbind(x: int; value) =
when defined(memTracker):
proc logEntries(log: TrackLog) {.nimcall, locks: 0, tags: [], gcsafe.} =
if insertStmt.isNil:
if prepare_v2(dbHandle, insertQuery,
insertQuery.len, insertStmt, nil) != SQLITE_OK:
quit "could not bind query to insertStmt " & $sqlite3.errmsg(dbHandle)
for i in 0..log.count-1:
var success = false
let e = log.data[i]