aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/utils.c
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2008-12-02 12:14:32 +0000
committerMartin Willi <martin@strongswan.org>2008-12-02 12:14:32 +0000
commitefd0fe21e44f0f757b3cd80cdbaddb8423eeb410 (patch)
tree2da2393fce98cd8bf3b8ab1c7a9c6346c199b3fa /src/libstrongswan/utils.c
parent6905f794bbdfbf82e4ab0fe6e5404db9c8eab3ad (diff)
downloadstrongswan-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.c')
-rw-r--r--src/libstrongswan/utils.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/libstrongswan/utils.c b/src/libstrongswan/utils.c
index 942f2ade0..aa50b86b4 100644
--- a/src/libstrongswan/utils.c
+++ b/src/libstrongswan/utils.c
@@ -20,7 +20,6 @@
#include <sys/stat.h>
#include <string.h>
-#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
@@ -138,19 +137,16 @@ void nop()
{
}
+#ifndef HAVE_GCC_ATOMIC_OPERATIONS
+#include <pthread.h>
+
/**
- * We use a single mutex for all refcount variables. This
- * is not optimal for performance, but the critical section
- * is not that long...
- * TODO: Consider to include a mutex in each refcount_t variable.
+ * We use a single mutex for all refcount variables.
*/
static pthread_mutex_t ref_mutex = PTHREAD_MUTEX_INITIALIZER;
/**
- * Described in header.
- *
- * TODO: May be implemented with atomic CPU instructions
- * instead of a mutex.
+ * Increase refcount
*/
void ref_get(refcount_t *ref)
{
@@ -160,10 +156,7 @@ void ref_get(refcount_t *ref)
}
/**
- * Described in header.
- *
- * TODO: May be implemented with atomic CPU instructions
- * instead of a mutex.
+ * Decrease refcount
*/
bool ref_put(refcount_t *ref)
{
@@ -174,6 +167,7 @@ bool ref_put(refcount_t *ref)
pthread_mutex_unlock(&ref_mutex);
return !more_refs;
}
+#endif /* HAVE_GCC_ATOMIC_OPERATIONS */
/**
* output handler in printf() for time_t