fixing tp setup

This commit is contained in:
Jaremy Creechley 2023-08-24 20:07:03 -07:00 committed by Dmitriy Ryajov
parent 464896bf88
commit 6c5059ecdf
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 23 additions and 14 deletions

View File

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

View File

@ -52,16 +52,20 @@ type
tp: Taskpool
backendDatastore: Datastore
ThreadDatastorePtr* = SharedPtr[ThreadDatastore]
ThreadDatastorePtr* = ptr ThreadDatastore
proc newThreadResult*[T](tp: typedesc[T]): TResult[T] =
newSharedPtr(ThreadResult[T])
proc startupDatastore(
ret: TResult[ThreadDatastorePtr],
backend: ThreadBackend,
) {.raises: [].} =
# ret: TResult[ThreadDatastorePtr],
# backend: ThreadBackend,
) {.raises: [].} =
## starts up a FS instance on a give thread
var
ret: TResult[ThreadDatastorePtr]
backend: ThreadBackend
case backend.kind:
of FSBackend:
let ds = FSDatastore.new(
@ -113,19 +117,23 @@ proc putTask*(
# return TResult[void].new()
proc createThreadDatastore*(
ret: TResult[ThreadDatastorePtr],
ret: var ThreadDatastorePtr,
backend: ThreadBackend,
) =
try:
echo "createThreadDatastore: start"
ret[].value[].tp = Taskpool.new(num_threads = 2) ##\
# var tp = Taskpool.new(num_threads = 2)
ret[].tp = Taskpool.new(num_threads = 2) ##\
## Default to one thread, multiple threads \
## will require more work
ret[].value[].tp.spawn startupDatastore(ret, backend)
echo "ret.tp: ", ret[].tp.repr
ret[].tp.spawn startupDatastore()
# ret[].value[].tp.spawn startupDatastore(ret, backend)
echo "createThreadDatastore: done"
except Exception as exc:
ret[].state = Error
ret[].error = exc.toBuffer()
# ret[].state = Error
# ret[].error = exc.toBuffer()
discard