Resuming work to move all DB access off the main thread.
This commit is contained in:
38
src/ssb.db.c
38
src/ssb.db.c
@ -635,6 +635,44 @@ bool tf_ssb_db_blob_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef struct _blob_get_async_t
|
||||
{
|
||||
tf_ssb_t* ssb;
|
||||
char id[k_blob_id_len];
|
||||
tf_ssb_db_blob_get_callback_t* callback;
|
||||
void* user_data;
|
||||
|
||||
bool out_found;
|
||||
uint8_t* out_data;
|
||||
size_t out_size;
|
||||
} blob_get_async_t;
|
||||
|
||||
static void _tf_ssb_db_blob_get_async_work(tf_ssb_t* ssb, void* user_data)
|
||||
{
|
||||
blob_get_async_t* async = user_data;
|
||||
async->out_found = tf_ssb_db_blob_get(ssb, async->id, &async->out_data, &async->out_size);
|
||||
}
|
||||
|
||||
static void _tf_ssb_db_blob_get_async_after_work(tf_ssb_t* ssb, int status, void* user_data)
|
||||
{
|
||||
blob_get_async_t* async = user_data;
|
||||
async->callback(async->out_found, async->out_data, async->out_size, async->user_data);
|
||||
tf_free(async->out_data);
|
||||
tf_free(async);
|
||||
}
|
||||
|
||||
void tf_ssb_db_blob_get_async(tf_ssb_t* ssb, const char* id, tf_ssb_db_blob_get_callback_t* callback, void* user_data)
|
||||
{
|
||||
blob_get_async_t* async = tf_malloc(sizeof(blob_get_async_t));
|
||||
*async = (blob_get_async_t) {
|
||||
.ssb = ssb,
|
||||
.callback = callback,
|
||||
.user_data = user_data,
|
||||
};
|
||||
snprintf(async->id, sizeof(async->id), "%s", id);
|
||||
tf_ssb_run_work(ssb, _tf_ssb_db_blob_get_async_work, _tf_ssb_db_blob_get_async_after_work, async);
|
||||
}
|
||||
|
||||
typedef struct _blob_store_work_t
|
||||
{
|
||||
const uint8_t* blob;
|
||||
|
Reference in New Issue
Block a user