Skip to content

Commit

Permalink
fixes alignment on opaque types as discueed with @tidwall
Browse files Browse the repository at this point in the history
  • Loading branch information
deckarep committed May 11, 2024
1 parent d5d9d4f commit d829d94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions neco.c
Original file line number Diff line number Diff line change
Expand Up @@ -7063,6 +7063,7 @@ struct neco_mutex {


static_assert(sizeof(neco_mutex) >= sizeof(struct neco_mutex), "");
static_assert(_Alignof(neco_mutex) == _Alignof(struct neco_mutex), "");

static int mutex_init(neco_mutex *mutex) {
struct neco_mutex *mu = (void*)mutex;
Expand Down Expand Up @@ -7319,6 +7320,7 @@ struct neco_waitgroup {
};

static_assert(sizeof(neco_waitgroup) >= sizeof(struct neco_waitgroup), "");
static_assert(_Alignof(neco_waitgroup) == _Alignof(struct neco_waitgroup), "");

inline
static int check_waitgroup(struct neco_waitgroup *wg) {
Expand Down Expand Up @@ -7466,6 +7468,7 @@ struct neco_cond {
};

static_assert(sizeof(neco_cond) >= sizeof(struct neco_cond), "");
static_assert(_Alignof(neco_cond) == _Alignof(struct neco_cond), "");

static int cond_init0(struct neco_cond *cv) {
memset(cv, 0, sizeof(struct neco_cond));
Expand Down
6 changes: 3 additions & 3 deletions neco.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int neco_gen_close(neco_gen *gen);
/// to a variable or set of variables and helps to avoid data inconsistencies
/// due to race conditions.
/// @{
typedef struct { char _[48]; } neco_mutex;
typedef struct { _Alignas(16) char _[48]; } neco_mutex;

#define NECO_MUTEX_INITIALIZER { 0 }

Expand All @@ -128,7 +128,7 @@ int neco_mutex_tryrdlock(neco_mutex *mutex);
/// At the same time, neco_waitgroup_wait() can be used to block until all
/// coroutines are completed.
/// @{
typedef struct { char _[48]; } neco_waitgroup;
typedef struct { _Alignas(16) char _[48]; } neco_waitgroup;

#define NECO_WAITGROUP_INITIALIZER { 0 }

Expand All @@ -143,7 +143,7 @@ int neco_waitgroup_wait_dl(neco_waitgroup *waitgroup, int64_t deadline);
/// A condition variable is a synchronization mechanism that allows coroutines
/// to suspend execution until some condition is true.
/// @{
typedef struct { char _[48]; } neco_cond;
typedef struct { _Alignas(16) char _[48]; } neco_cond;
#define NECO_COND_INITIALIZER { 0 }

int neco_cond_init(neco_cond *cond);
Expand Down

0 comments on commit d829d94

Please sign in to comment.