diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/atomic.h | 1 | ||||
-rw-r--r-- | runtime/wti.c | 7 |
2 files changed, 6 insertions, 2 deletions
diff --git a/runtime/atomic.h b/runtime/atomic.h index 4cb832f2..f5ae9357 100644 --- a/runtime/atomic.h +++ b/runtime/atomic.h @@ -50,6 +50,7 @@ # define ATOMIC_STORE_1_TO_INT(data) __sync_fetch_and_or(&(data), 1) # define ATOMIC_STORE_INT_TO_INT(data, val) __sync_fetch_and_or(&(data), (val)) # define ATOMIC_CAS(data, oldVal, newVal) __sync_bool_compare_and_swap(&(data), (oldVal), (newVal)); +# define ATOMIC_CAS_VAL(data, oldVal, newVal) __sync_val_compare_and_swap(&(data), (oldVal), (newVal)); #else /* note that we gained parctical proof that theoretical problems DO occur * if we do not properly address them. See this blog post for details: diff --git a/runtime/wti.c b/runtime/wti.c index c9fc4879..9c137f57 100644 --- a/runtime/wti.c +++ b/runtime/wti.c @@ -146,8 +146,11 @@ wtiSetState(wti_t *pThis, qWrkCmd_t tCmd, int bActiveOnly, int bLockMutex) /* DO NOTHING */ break; } - /* better do a CAS? */ - ATOMIC_STORE_INT_TO_INT(pThis->tCurrCmd, tCmd); /* apply the new state */ + /* apply the new state */ + unsigned val = ATOMIC_CAS_VAL(pThis->tCurrCmd, tCurrCmd, tCmd); + if(val != tCurrCmd) { + DBGPRINTF("wtiSetState PROBLEM, tCurrCmd %d overwritten with %d, wanted to set %d\n", tCurrCmd, val, tCmd); + } } END_MTX_PROTECTED_OPERATIONS(&pThis->mut); |