Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #53 from blazej-smorawski/vdm-add-memcpy-fn
Browse files Browse the repository at this point in the history
masync: vdm threads add data function pointers array
  • Loading branch information
pbalcer authored Feb 28, 2022
2 parents ab6de83 + 1ae12b8 commit edddf76
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
35 changes: 30 additions & 5 deletions src/data_mover_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
#define DATA_MOVER_THREADS_DEFAULT_NTHREADS 12
#define DATA_MOVER_THREADS_DEFAULT_RINGBUF_SIZE 128

struct data_mover_threads_op_fns {
memcpy_fn op_memcpy;
};

struct data_mover_threads {
struct vdm base; /* must be first */

struct data_mover_threads_op_fns op_fns;
struct ringbuf *buf;
size_t nthreads;
os_thread_t *threads;
Expand All @@ -38,22 +43,41 @@ struct data_mover_threads_op {
uint64_t started;
};

/*
* Standard implementation of memcpy used if none was specified by the user.
*/
void *std_memcpy(void *dst, const void *src, size_t n, unsigned flags) {
return memcpy(dst, src, n);
}

static struct data_mover_threads_op_fns op_fns_default = {
.op_memcpy = std_memcpy
};

void data_mover_threads_set_memcpy_fn(struct data_mover_threads *dmt,
memcpy_fn op_memcpy) {
dmt->op_fns.op_memcpy = op_memcpy;
}

/*
* data_mover_threads_do_operation -- implementation of the various
* operations supported by this data mover
*/
static void
data_mover_threads_do_operation(struct data_mover_threads_op *op)
data_mover_threads_do_operation(struct data_mover_threads_op *op,
struct data_mover_threads *dmt)
{
switch (op->op.type) {
case VDM_OPERATION_MEMCPY: {
struct vdm_operation_data_memcpy *mdata
= &op->op.data.memcpy;
memcpy(mdata->dest, mdata->src, mdata->n);
memcpy_fn op_memcpy = dmt->op_fns.op_memcpy;
op_memcpy(mdata->dest,
mdata->src, mdata->n, mdata->flags);
} break;
default:
ASSERT(0); /* unreachable */
break;
ASSERT(0); /* unreachable */
break;
}

if (op->desired_notifier == FUTURE_NOTIFIER_WAKER) {
Expand Down Expand Up @@ -82,7 +106,7 @@ data_mover_threads_loop(void *arg)
if ((op = ringbuf_dequeue(buf)) == NULL)
return NULL;

data_mover_threads_do_operation(op);
data_mover_threads_do_operation(op, dmt_threads);
}
}

Expand Down Expand Up @@ -232,6 +256,7 @@ data_mover_threads_new(size_t nthreads, size_t ringbuf_size,

dmt_threads->desired_notifier = desired_notifier;
dmt_threads->base = data_mover_threads_vdm;
dmt_threads->op_fns = op_fns_default;

dmt_threads->buf = ringbuf_new(ringbuf_size);
if (dmt_threads->buf == NULL)
Expand Down
8 changes: 5 additions & 3 deletions src/include/libminiasync/data_mover_threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
extern "C" {
#endif

struct data_mover_threads;
typedef void *(*memcpy_fn)(void *dst, const void *src,
size_t n, unsigned flags);

struct data_mover_threads;
struct data_mover_threads *data_mover_threads_new(size_t nthreads,
size_t ringbuf_size, enum future_notifier_type desired_notifier);
struct data_mover_threads *data_mover_threads_default();

struct vdm *data_mover_threads_get_vdm(struct data_mover_threads *dmt);

void data_mover_threads_delete(struct data_mover_threads *dmt);
void data_mover_threads_set_memcpy_fn(struct data_mover_threads *dmt,
memcpy_fn op_memcpy);

#ifdef __cplusplus
}
Expand Down

0 comments on commit edddf76

Please sign in to comment.