fixup databuffer

This commit is contained in:
Jaremy Creechley 2023-09-26 16:02:42 -07:00
parent abfd12f7a6
commit 892ec385ee
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 14 additions and 11 deletions

View File

@ -27,8 +27,10 @@ proc `=destroy`*(x: var DataBufferHolder) =
# echo "buffer: FREE: ", repr x.buf.pointer # echo "buffer: FREE: ", repr x.buf.pointer
deallocShared(x.buf) deallocShared(x.buf)
proc len*(a: DataBuffer): int = a[].size proc len*(a: DataBuffer): int =
proc capacity*(a: DataBuffer): int = a[].cap if a.isNil: 0 else: a[].size
proc capacity*(a: DataBuffer): int =
if a.isNil: 0 else: a[].cap
proc isNil*(a: DataBuffer): bool = smartptrs.isNil(a) proc isNil*(a: DataBuffer): bool = smartptrs.isNil(a)

View File

@ -242,7 +242,7 @@ proc queryTask[DB](
(?!QResult).err(qh.error()) (?!QResult).err(qh.error())
else: else:
# otherwise manually an set empty ok result # otherwise manually an set empty ok result
ctx[].res.ok (KeyId.none, DataBuffer.new()) ctx[].res.ok (KeyId.none, DataBuffer(), )
discard ctx[].signal.fireSync() discard ctx[].signal.fireSync()
var handle = qh.get() var handle = qh.get()
@ -260,7 +260,7 @@ proc queryTask[DB](
discard ctx[].signal.fireSync() discard ctx[].signal.fireSync()
# set final result # set final result
(?!QResult).ok((KeyId.none, DataBuffer.new())) (?!QResult).ok((KeyId.none, DataBuffer()))
method query*( method query*(
self: ThreadDatastore, self: ThreadDatastore,
@ -313,16 +313,17 @@ method query*(
iter.next = next iter.next = next
return success iter return success iter
proc new*( proc new*(self: type ThreadDatastore,
self: type ThreadDatastore, backend: ThreadBackendKinds,
ds: Datastore,
withLocks = static false, withLocks = static false,
tp: Taskpool): ?!ThreadDatastore = tp: Taskpool
): ?!ThreadDatastore =
doAssert tp.numThreads > 1, "ThreadDatastore requires at least 2 threads" doAssert tp.numThreads > 1, "ThreadDatastore requires at least 2 threads"
success ThreadDatastore( success ThreadDatastore(
tp: tp, tp: tp,
ds: ds, ds: ThreadBackend(),
withLocks: withLocks, withLocks: withLocks,
queryLock: newAsyncLock(), queryLock: newAsyncLock(),
semaphore: AsyncSemaphore.new(tp.numThreads - 1)) semaphore: AsyncSemaphore.new(tp.numThreads - 1)
)