On Sunday, February 03, 2013 10:38:37 AM z...@apache.org wrote:
> TS-1006: Add a new wrapper: ink_atomic_decrement()
> 
> This is a wrapper of __sync_fetch_and_sub() in GNU env.

And what about non-GNU environments?

> I need this wrapper in reclaimable freelist, as ink_atomic_increment()
> can't work correctly in some situation by unknown reason.
> 
> Signed-off-by: Yunkai Zhang <qiushu....@taobao.com>
> Signed-off-by: Zhao Yongming <ming....@gmail.com>
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
> Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/4397abf7
> Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/4397abf7
> Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/4397abf7
> 
> Branch: refs/heads/master
> Commit: 4397abf76c4fbb7babccc9cc11b0456f2a7a1516
> Parents: 5d8cc8a
> Author: Yunkai Zhang <qiushu....@taobao.com>
> Authored: Sat Feb 2 17:08:18 2013 +0800
> Committer: Zhao Yongming <ming....@gmail.com>
> Committed: Sun Feb 3 10:52:58 2013 +0800
> 
> ----------------------------------------------------------------------
>  lib/ts/ink_atomic.h |    9 ++++++++-
>  1 files changed, 8 insertions(+), 1 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4397abf7/lib/ts/in
> k_atomic.h
> ---------------------------------------------------------------------- diff
> --git a/lib/ts/ink_atomic.h b/lib/ts/ink_atomic.h
> index b22cf24..9425eec 100644
> --- a/lib/ts/ink_atomic.h
> +++ b/lib/ts/ink_atomic.h
> @@ -160,6 +160,13 @@ ink_atomic_increment(volatile Type * mem, Amount count)
> { return __sync_fetch_and_add(mem, (Type)count);
>  }
> 
> +// ink_atomic_decrement(ptr, count)
> +// Decrement @ptr by @count, returning the previous value.
> +template <typename Type, typename Amount> static inline Type
> +ink_atomic_decrement(volatile Type * mem, Amount count) {
> +  return __sync_fetch_and_sub(mem, (Type)count);
> +}
> +
>  // Special hacks for ARM 32-bit
>  #if defined(__arm__) && (SIZEOF_VOIDP == 4)
>  extern ProcessMutex __global_death;
> @@ -213,6 +220,6 @@ ink_atomic_increment<int64_t>(pvint64 mem, int value) {
> 
>  #else /* not gcc > v4.1.2 */
>  #error Need a compiler / libc that supports atomic operations, e.g. gcc
> v4.1.2 or later -#endif
> +#endif
> 
>  #endif                          /* _ink_atomic_h_ */

Reply via email to