diff --git a/datastore/threads/databuffer.nim b/datastore/threads/databuffer.nim index be08c02..9e192e7 100644 --- a/datastore/threads/databuffer.nim +++ b/datastore/threads/databuffer.nim @@ -27,8 +27,10 @@ proc `=destroy`*(x: var DataBufferHolder) = # echo "buffer: FREE: ", repr x.buf.pointer deallocShared(x.buf) -proc len*(a: DataBuffer): int = a[].size -proc capacity*(a: DataBuffer): int = a[].cap +proc len*(a: DataBuffer): int = + 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) diff --git a/datastore/threads/threadproxyds.nim b/datastore/threads/threadproxyds.nim index 77c4f1f..ad77bf0 100644 --- a/datastore/threads/threadproxyds.nim +++ b/datastore/threads/threadproxyds.nim @@ -242,7 +242,7 @@ proc queryTask[DB]( (?!QResult).err(qh.error()) else: # otherwise manually an set empty ok result - ctx[].res.ok (KeyId.none, DataBuffer.new()) + ctx[].res.ok (KeyId.none, DataBuffer(), ) discard ctx[].signal.fireSync() var handle = qh.get() @@ -260,7 +260,7 @@ proc queryTask[DB]( discard ctx[].signal.fireSync() # set final result - (?!QResult).ok((KeyId.none, DataBuffer.new())) + (?!QResult).ok((KeyId.none, DataBuffer())) method query*( self: ThreadDatastore, @@ -313,16 +313,17 @@ method query*( iter.next = next return success iter -proc new*( - self: type ThreadDatastore, - ds: Datastore, - withLocks = static false, - tp: Taskpool): ?!ThreadDatastore = +proc new*(self: type ThreadDatastore, + backend: ThreadBackendKinds, + withLocks = static false, + tp: Taskpool + ): ?!ThreadDatastore = doAssert tp.numThreads > 1, "ThreadDatastore requires at least 2 threads" success ThreadDatastore( tp: tp, - ds: ds, + ds: ThreadBackend(), withLocks: withLocks, queryLock: newAsyncLock(), - semaphore: AsyncSemaphore.new(tp.numThreads - 1)) + semaphore: AsyncSemaphore.new(tp.numThreads - 1) + )