Skip to content

Commit b639e9c

Browse files
committed
config BUGFIX workaround for atomic_load spec bug
In the original C11, atomic_load did not work with const variables. Refs #253
1 parent e201015 commit b639e9c

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/config.h.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838

3939
# define ATOMIC_UINT32_T atomic_uint_fast32_t
4040
# define ATOMIC_PTR atomic_uintptr_t
41-
# define ATOMIC_STORE(x, val) atomic_store(&(x), (uintptr_t)(val))
42-
# define ATOMIC_LOAD(x) ((void *)atomic_load(&(x)))
41+
# define ATOMIC_STORE(x, val) atomic_store(&(x), (val))
42+
# define ATOMIC_LOAD(x) atomic_load((atomic_uintptr_t *)&(x))
4343
# define ATOMIC_INC(x) atomic_fetch_add(&(x), 1)
4444
#else
4545
# define ATOMIC_UINT32_T uint32_t
4646
# define ATOMIC_PTR void *
47-
# define ATOMIC_STORE(x, val) (x) = (void *)(val)
48-
# define ATOMIC_LOAD(x) ((void *)(x))
47+
# define ATOMIC_STORE(x, val) (x) = (val)
48+
# define ATOMIC_LOAD(x) (x)
4949
# define ATOMIC_INC(x) __sync_add_and_fetch(&(x), 1)
5050
#endif
5151

src/session.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ nc_session_free(struct nc_session *session, void (*data_free)(void *))
615615

616616
/* stop notifications loop if any */
617617
if ((session->side == NC_CLIENT) && ATOMIC_LOAD(session->opts.client.ntf_tid)) {
618-
ATOMIC_STORE(session->opts.client.ntf_tid, NULL);
618+
ATOMIC_STORE(session->opts.client.ntf_tid, (uintptr_t)NULL);
619619
/* the thread now knows it should quit */
620620
}
621621

src/session_client.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,7 +2214,7 @@ nc_recv_notif_thread(void *arg)
22142214
free(ntarg);
22152215

22162216
/* remember our allocated tid, we will be freeing it */
2217-
ntf_tid = ATOMIC_LOAD(session->opts.client.ntf_tid);
2217+
ntf_tid = (pthread_t *)ATOMIC_LOAD(session->opts.client.ntf_tid);
22182218

22192219
while (ATOMIC_LOAD(session->opts.client.ntf_tid)) {
22202220
msgtype = nc_recv_notif(session, NC_CLIENT_NOTIF_THREAD_SLEEP / 1000, &notif);
@@ -2235,7 +2235,7 @@ nc_recv_notif_thread(void *arg)
22352235
}
22362236

22372237
VRB("Session %u: notification thread exit.", session->id);
2238-
ATOMIC_STORE(session->opts.client.ntf_tid, NULL);
2238+
ATOMIC_STORE(session->opts.client.ntf_tid, (uintptr_t)NULL);
22392239
free(ntf_tid);
22402240
return NULL;
22412241
}
@@ -2276,14 +2276,14 @@ nc_recv_notif_dispatch(struct nc_session *session, void (*notif_clb)(struct nc_s
22762276
return -1;
22772277
}
22782278
/* just so that nc_recv_notif_thread() does not immediately exit, the value does not matter */
2279-
ATOMIC_STORE(session->opts.client.ntf_tid, tid);
2279+
ATOMIC_STORE(session->opts.client.ntf_tid, (uintptr_t)tid);
22802280

22812281
ret = pthread_create(tid, NULL, nc_recv_notif_thread, ntarg);
22822282
if (ret) {
22832283
ERR("Session %u: failed to create a new thread (%s).", strerror(errno));
22842284
free(ntarg);
22852285
free(tid);
2286-
ATOMIC_STORE(session->opts.client.ntf_tid, NULL);
2286+
ATOMIC_STORE(session->opts.client.ntf_tid, (uintptr_t)NULL);
22872287
return -1;
22882288
}
22892289

0 commit comments

Comments
 (0)