mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-07 08:03:13 +00:00
setup sharedptr
This commit is contained in:
parent
dbce1538fd
commit
1187bb6cc2
@ -13,7 +13,7 @@ requires "nim >= 1.2.0",
|
||||
"sqlite3_abi",
|
||||
"stew",
|
||||
"unittest2",
|
||||
"patty",
|
||||
"pretty",
|
||||
"threading",
|
||||
"upraises >= 0.1.0 & < 0.2.0"
|
||||
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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"
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user