setup sharedptr

This commit is contained in:
Jaremy Creechley 2023-08-24 20:15:22 -07:00
parent dbce1538fd
commit 1187bb6cc2
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
3 changed files with 12 additions and 11 deletions

View File

@ -13,7 +13,7 @@ requires "nim >= 1.2.0",
"sqlite3_abi",
"stew",
"unittest2",
"patty",
"pretty",
"threading",
"upraises >= 0.1.0 & < 0.2.0"

View File

@ -79,12 +79,13 @@ proc newSharedDataStore*(
var
self = SharedDatastore()
# res = newThreadResult(ThreadDatastorePtr)
res = cast[ThreadDatastorePtr](allocShared0(sizeof(ThreadDatastorePtr)))
res = newThreadResult(ThreadDatastorePtr)
# res[].signal = ThreadSignalPtr.new().valueOr:
# return failure newException(DatastoreError, "error creating signal")
res[].value = newSharedPtr(ThreadDatastore)
res[].signal = ThreadSignalPtr.new().valueOr:
return failure newException(DatastoreError, "error creating signal")
echo "sds:res: ", res.repr
res.createThreadDatastore(backend)
# await wait(res[].signal)
# res[].signal.close()

View File

@ -48,11 +48,11 @@ type
of TestBackend:
count*: int
ThreadDatastore = object
ThreadDatastore* = object
tp: Taskpool
backendDatastore: Datastore
ThreadDatastorePtr* = ptr ThreadDatastore
ThreadDatastorePtr* = SharedPtr[ThreadDatastore]
proc newThreadResult*[T](tp: typedesc[T]): TResult[T] =
newSharedPtr(ThreadResult[T])
@ -117,18 +117,18 @@ proc putTask*(
# return TResult[void].new()
proc createThreadDatastore*(
ret: var ThreadDatastorePtr,
ret: TResult[ThreadDatastorePtr],
backend: ThreadBackend,
) =
try:
echo "createThreadDatastore: start"
# var tp = Taskpool.new(num_threads = 2)
ret[].tp = Taskpool.new(num_threads = 2) ##\
ret[].value[].tp = Taskpool.new(num_threads = 2) ##\
## Default to one thread, multiple threads \
## will require more work
echo "ret.tp: ", ret[].tp.repr
ret[].tp.spawn startupDatastore()
echo "ret.tp: ", ret[].repr
ret[].value[].tp.spawn startupDatastore()
# ret[].value[].tp.spawn startupDatastore(ret, backend)
echo "createThreadDatastore: done"