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 #76 from lplewa/zero
Browse files Browse the repository at this point in the history
masync: replace {0} with proper initialisation
  • Loading branch information
pbalcer authored Apr 4, 2022
2 parents 3b5a9e0 + cc1a325 commit 6c21f8a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
4 changes: 2 additions & 2 deletions examples/basic/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async_print_impl(struct future_context *ctx, struct future_notifier *notifier)
static struct async_print_fut
async_print(void *value)
{
struct async_print_fut future = {0};
struct async_print_fut future = {.output.return_code = 0};
future.data.value = value;

FUTURE_INIT(&future, async_print_impl);
Expand Down Expand Up @@ -105,7 +105,7 @@ print_to_output_map(struct future_context *print_ctx,
static struct async_memcpy_print_fut
async_memcpy_print(struct vdm *vdm, void *dest, void *src, size_t n)
{
struct async_memcpy_print_fut chain = {0};
struct async_memcpy_print_fut chain = {.output.return_code = 0};
FUTURE_CHAIN_ENTRY_INIT(&chain.data.memcpy,
vdm_memcpy(vdm, dest, src, n, 0),
memcpy_to_print_map, (void *)0xd);
Expand Down
2 changes: 2 additions & 0 deletions src/include/libminiasync/future.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ do {\
(_futurep)->base.context.data_size = sizeof((_futurep)->data);\
(_futurep)->base.context.output_size =\
sizeof((_futurep)->output);\
(_futurep)->base.context.padding = 0;\
} while (0)

#define FUTURE_INIT_COMPLETE(_futurep)\
Expand All @@ -158,6 +159,7 @@ do {\
(_futurep)->base.context.data_size = sizeof((_futurep)->data);\
(_futurep)->base.context.output_size =\
sizeof((_futurep)->output);\
(_futurep)->base.context.padding = 0;\
} while (0)

#define FUTURE_AS_RUNNABLE(futurep) (&(futurep)->base)
Expand Down
63 changes: 32 additions & 31 deletions src/include/libminiasync/vdm.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,18 @@ vdm_operation_impl(struct future_context *context, struct future_notifier *n)
* vdm_generic_operation -- creates a new vdm future for a given generic
* operation
*/
static inline struct vdm_operation_future
vdm_generic_operation(struct vdm *vdm, struct vdm_operation *op)
static inline void
vdm_generic_operation(struct vdm *vdm, struct vdm_operation_future *future)
{
struct vdm_operation_future future = {0};
future.data.vdm = vdm;
future.data.operation = *op;
if ((future.data.data = vdm->op_new(vdm, op->type)) == NULL) {
future.output.result = VDM_ERROR_OUT_OF_MEMORY;
FUTURE_INIT_COMPLETE(&future);
future->data.vdm = vdm;
if ((future->data.data =
vdm->op_new(vdm, future->data.operation.type))
== NULL) {
future->output.result = VDM_ERROR_OUT_OF_MEMORY;
FUTURE_INIT_COMPLETE(future);
} else {
FUTURE_INIT(&future, vdm_operation_impl);
FUTURE_INIT(future, vdm_operation_impl);
}

return future;
}

/*
Expand All @@ -175,16 +173,18 @@ vdm_generic_operation(struct vdm *vdm, struct vdm_operation *op)
static inline struct vdm_operation_future
vdm_memcpy(struct vdm *vdm, void *dest, void *src, size_t n, uint64_t flags)
{
struct vdm_operation_future future = {.data.operation = {
.type = VDM_OPERATION_MEMCPY,
.data = {
.memcpy.dest = dest,
.memcpy.flags = flags,
.memcpy.n = n,
.memcpy.src = src,
}
}};
return vdm_generic_operation(vdm, &future.data.operation);
struct vdm_operation_future future;
future.data.operation.type = VDM_OPERATION_MEMCPY;
future.data.operation.data.memcpy.dest = dest;
future.data.operation.data.memcpy.flags = flags;
future.data.operation.data.memcpy.n = n;
future.data.operation.data.memcpy.src = src;
future.output.type = VDM_OPERATION_MEMCPY;
future.output.result = VDM_SUCCESS;
future.output.output.memcpy.dest = NULL;

vdm_generic_operation(vdm, &future);
return future;
}

/*
Expand All @@ -194,16 +194,17 @@ vdm_memcpy(struct vdm *vdm, void *dest, void *src, size_t n, uint64_t flags)
static inline struct vdm_operation_future
vdm_memmove(struct vdm *vdm, void *dest, void *src, size_t n, uint64_t flags)
{
struct vdm_operation_future future = {.data.operation = {
.type = VDM_OPERATION_MEMMOVE,
.data = {
.memcpy.dest = dest,
.memcpy.flags = flags,
.memcpy.n = n,
.memcpy.src = src,
}
}};
return vdm_generic_operation(vdm, &future.data.operation);
struct vdm_operation_future future;
future.data.operation.type = VDM_OPERATION_MEMMOVE;
future.data.operation.data.memmove.dest = dest;
future.data.operation.data.memmove.flags = flags;
future.data.operation.data.memmove.n = n;
future.data.operation.data.memmove.src = src;
future.output.type = VDM_OPERATION_MEMMOVE;
future.output.result = VDM_SUCCESS;
future.output.output.memmove.dest = NULL;
vdm_generic_operation(vdm, &future);
return future;
}

#ifdef __cplusplus
Expand Down
10 changes: 5 additions & 5 deletions tests/future/test_future.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ countup_task(struct future_context *context,
struct countup_fut
async_countup(int max_count)
{
struct countup_fut fut = {0};
struct countup_fut fut = {.output.result = 0};
FUTURE_INIT(&fut, countup_task);
fut.data.counter = 0;
fut.data.max_count = max_count;
Expand Down Expand Up @@ -119,7 +119,7 @@ countdown_task(struct future_context *context,
struct countdown_fut
async_countdown(int count)
{
struct countdown_fut fut = {0};
struct countdown_fut fut = {.output.result = 0};
FUTURE_INIT(&fut, countdown_task);
fut.data.counter = count;
fut.output.result = 0;
Expand Down Expand Up @@ -169,7 +169,7 @@ down_to_result_map(struct future_context *lhs, struct future_context *rhs,
struct up_down_fut
async_up_down(int count)
{
struct up_down_fut fut = {0};
struct up_down_fut fut = {.output.result_sum = 0};
FUTURE_CHAIN_ENTRY_INIT(&fut.data.up, async_countup(count),
up_to_down_map, FAKE_MAP_ARG);
FUTURE_CHAIN_ENTRY_INIT(&fut.data.down, async_countdown(0),
Expand Down Expand Up @@ -209,7 +209,7 @@ FUTURE(multiply_fut, struct multiply_data, struct multiply_output);
struct multiply_fut
async_multiply(int a, int b)
{
struct multiply_fut fut = {0};
struct multiply_fut fut;
FUTURE_INIT_COMPLETE(&fut);
fut.data.a = a;
fut.data.b = b;
Expand Down Expand Up @@ -271,7 +271,7 @@ up_down_to_output(struct future_context *lhs,
struct multiply_up_down_fut
async_multiply_up_down(int count, int num)
{
struct multiply_up_down_fut fut = {0};
struct multiply_up_down_fut fut = {.output.result_sum = 0};
fut.data.count = count;
fut.data.num = num;
FUTURE_CHAIN_ENTRY_LAZY_INIT(&fut.data.mul,
Expand Down
6 changes: 3 additions & 3 deletions tests/vdm/test_vdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ alloc_impl(struct future_context *context, struct future_notifier *notifier)
struct alloc_fut
async_alloc(size_t size)
{
struct alloc_fut fut = {0};
struct alloc_fut fut = {.output.ptr = NULL};
fut.data.n = size;
FUTURE_INIT(&fut, alloc_impl);
return fut;
Expand Down Expand Up @@ -77,7 +77,7 @@ strdup_map_copy_to_output(struct future_context *lhs,
struct strdup_fut
async_strdup(struct vdm *vdm, char *s)
{
struct strdup_fut fut = {0};
struct strdup_fut fut = {.output = {.length = 0, .ptr = NULL}};

size_t len = strlen(s) + 1;
FUTURE_CHAIN_ENTRY_INIT(&fut.data.alloc, async_alloc(len),
Expand Down Expand Up @@ -106,7 +106,7 @@ strdup_init(void *future, struct future_context *chain_fut, void *arg)
struct strdup_fut
async_lazy_strdup(struct vdm *vdm, char *s)
{
struct strdup_fut fut = {0};
struct strdup_fut fut = {.output = {.length = 0, .ptr = NULL}};
fut.data.src = s;
fut.data.length = strlen(s) + 1;

Expand Down

0 comments on commit 6c21f8a

Please sign in to comment.