Skip to content

Commit

Permalink
atomic: add ABTD_atomic_exchange_TYPE functions.
Browse files Browse the repository at this point in the history
ABTD_atomic_exchange_TYPE functions replace the __atomic_exchange_n() calls.

No reviewer.
  • Loading branch information
Sangmin Seo committed Nov 11, 2016
1 parent 32cb0cb commit bce6186
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
24 changes: 24 additions & 0 deletions src/include/abtd_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,30 @@ uint64_t ABTD_atomic_fetch_xor_uint64(uint64_t *ptr, uint64_t v)
return __sync_fetch_and_xor(ptr, v);
}

static inline
int32_t ABTD_atomic_exchange_int32(int32_t *ptr, int32_t v)
{
return __atomic_exchange_n(ptr, v, __ATOMIC_SEQ_CST);
}

static inline
uint32_t ABTD_atomic_exchange_uint32(uint32_t *ptr, uint32_t v)
{
return __atomic_exchange_n(ptr, v, __ATOMIC_SEQ_CST);
}

static inline
int64_t ABTD_atomic_exchange_int64(int64_t *ptr, int64_t v)
{
return __atomic_exchange_n(ptr, v, __ATOMIC_SEQ_CST);
}

static inline
uint64_t ABTD_atomic_exchange_uint64(uint64_t *ptr, uint64_t v)
{
return __atomic_exchange_n(ptr, v, __ATOMIC_SEQ_CST);
}

static inline
void ABTD_atomic_mem_barrier(void)
{
Expand Down
4 changes: 2 additions & 2 deletions src/include/abti_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void ABTI_mutex_lock(ABTI_mutex *p_mutex)
int c;
if ((c = ABTD_atomic_cas_uint32(&p_mutex->val, 0, 1)) != 0) {
if (c != 2) {
c = __atomic_exchange_n(&p_mutex->val, 2, __ATOMIC_SEQ_CST);
c = ABTD_atomic_exchange_uint32(&p_mutex->val, 2);
}
while (c != 0) {
ABTI_mutex_wait(p_mutex, 2);
Expand All @@ -165,7 +165,7 @@ void ABTI_mutex_lock(ABTI_mutex *p_mutex)
}
}

c = __atomic_exchange_n(&p_mutex->val, 2, __ATOMIC_SEQ_CST);
c = ABTD_atomic_exchange_uint32(&p_mutex->val, 2);
}
}
LOG_EVENT("%p: lock - acquired\n", p_mutex);
Expand Down
4 changes: 2 additions & 2 deletions src/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void ABTI_mutex_lock_low(ABTI_mutex *p_mutex)

if ((c = ABTD_atomic_cas_uint32(&p_mutex->val, 0, 1)) != 0) {
if (c != 2) {
c = __atomic_exchange_n(&p_mutex->val, 2, __ATOMIC_SEQ_CST);
c = ABTD_atomic_exchange_uint32(&p_mutex->val, 2);
}
while (c != 0) {
ABTI_mutex_wait_low(p_mutex, 2);
Expand All @@ -240,7 +240,7 @@ void ABTI_mutex_lock_low(ABTI_mutex *p_mutex)
}
}

c = __atomic_exchange_n(&p_mutex->val, 2, __ATOMIC_SEQ_CST);
c = ABTD_atomic_exchange_uint32(&p_mutex->val, 2);
}
}
LOG_EVENT("%p: lock_low - acquired\n", p_mutex);
Expand Down

0 comments on commit bce6186

Please sign in to comment.