diff options
author | Martin Willi <martin@strongswan.org> | 2008-12-02 12:14:32 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2008-12-02 12:14:32 +0000 |
commit | efd0fe21e44f0f757b3cd80cdbaddb8423eeb410 (patch) | |
tree | 2da2393fce98cd8bf3b8ab1c7a9c6346c199b3fa /src/libstrongswan/utils.h | |
parent | 6905f794bbdfbf82e4ab0fe6e5404db9c8eab3ad (diff) | |
download | strongswan-efd0fe21e44f0f757b3cd80cdbaddb8423eeb410.tar.bz2 strongswan-efd0fe21e44f0f757b3cd80cdbaddb8423eeb410.tar.xz |
ref_get()/ref_put() use atomic gcc operations if supported, thanks to Thomas Jarosch for the patch
Diffstat (limited to 'src/libstrongswan/utils.h')
-rw-r--r-- | src/libstrongswan/utils.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libstrongswan/utils.h b/src/libstrongswan/utils.h index af619ea4b..298253fdd 100644 --- a/src/libstrongswan/utils.h +++ b/src/libstrongswan/utils.h @@ -248,6 +248,14 @@ void nop(); */ typedef volatile u_int refcount_t; + +#ifdef HAVE_GCC_ATOMIC_OPERATIONS + +#define ref_get(ref) {__sync_fetch_and_add(ref, 1); } +#define ref_put(ref) (!__sync_sub_and_fetch(ref, 1)) + +#else /* !HAVE_GCC_ATOMIC_OPERATIONS */ + /** * Get a new reference. * @@ -268,6 +276,8 @@ void ref_get(refcount_t *ref); */ bool ref_put(refcount_t *ref); +#endif /* HAVE_GCC_ATOMIC_OPERATIONS */ + /** * Get printf hooks for time. * |