Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- add atomic_dec_u64
  • Loading branch information
Memphiz authored and perexg committed May 13, 2015
1 parent aa97cb4 commit 51449ef
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/atomic.h
Expand Up @@ -51,6 +51,21 @@ atomic_add_u64(volatile uint64_t *ptr, uint64_t incr)
#endif
}

static inline uint64_t
atomic_dec_u64(volatile uint64_t *ptr, uint64_t decr)
{
#if ENABLE_ATOMIC64
return __sync_fetch_and_sub(ptr, decr);
#else
uint64_t ret;
pthread_mutex_lock(&atomic_lock);
ret = *ptr;
*ptr -= decr;
pthread_mutex_unlock(&atomic_lock);
return ret;
#endif
}

static inline uint64_t
atomic_pre_add_u64(volatile uint64_t *ptr, uint64_t incr)
{
Expand Down

0 comments on commit 51449ef

Please sign in to comment.