summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root>2011-08-03 15:25:38 +0000
committerroot <root>2011-08-03 15:25:38 +0000
commitf37fb32493b0a4a5b6579d7263494c1589ff204f (patch)
treeb43dba2df83a7262c363ac0a69c52b8c20869bd0
parent63ce26599ad3cc88324cd92d276ca21b5fa2470a (diff)
*** empty log message ***
-rw-r--r--Changes1
-rw-r--r--ecb.h24
-rw-r--r--eio.c10
3 files changed, 22 insertions, 13 deletions
diff --git a/Changes b/Changes
index 4eae96a..9d3e323 100644
--- a/Changes
+++ b/Changes
@@ -59,4 +59,5 @@ TODO: fadvise request
- incorporated some mingw32 changes by traviscline.
- added syncfs support, using direct syscall.
- set thread name on linux (ps -L/Hcx, top, gdb).
+ - remove useless use of volatile variables.
diff --git a/ecb.h b/ecb.h
index 75f1237..8383374 100644
--- a/ecb.h
+++ b/ecb.h
@@ -69,12 +69,12 @@
#if ECB_GCC_VERSION(2,5)
#if __x86
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
- #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
- #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE /* better be safe than sorry */
+ #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */
+ #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */
#elif __amd64
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
#define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory")
- #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence")
+ #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */
#endif
#endif
#endif
@@ -84,19 +84,27 @@
#define ECB_MEMORY_FENCE __sync_synchronize ()
#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); })
#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); })
- #elif _MSC_VER >= 1400 && 0 /* TODO: only true when using volatiles */
- #define ECB_MEMORY_FENCE do { } while (0)
- #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
- #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
+ #elif _MSC_VER >= 1400 /* VC++ 2005 */
+ #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
+ #define ECB_MEMORY_FENCE _ReadWriteBarrier ()
+ #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */
+ #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier ()
#elif defined(_WIN32)
#include <WinNT.h>
- #define ECB_MEMORY_FENCE MemoryBarrier ()
+ #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
#define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
#define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
#endif
#endif
#ifndef ECB_MEMORY_FENCE
+ /*
+ * if you get undefined symbol references to pthread_mutex_lock,
+ * or failure to find pthread.h, then you should implement
+ * the ECB_MEMORY_FENCE operations for your cpu/compiler
+ * OR proide pthread.h and link against the posix thread library
+ * of your system.
+ */
#include <pthread.h>
static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER;
diff --git a/eio.c b/eio.c
index 256f43d..18a903b 100644
--- a/eio.c
+++ b/eio.c
@@ -326,11 +326,11 @@ static void (*done_poll_cb) (void);
static unsigned int max_poll_time; /* reslock */
static unsigned int max_poll_reqs; /* reslock */
-static volatile unsigned int nreqs; /* reqlock */
-static volatile unsigned int nready; /* reqlock */
-static volatile unsigned int npending; /* reqlock */
-static volatile unsigned int max_idle = 4; /* maximum number of threads that can idle indefinitely */
-static volatile unsigned int idle_timeout = 10; /* number of seconds after which an idle threads exit */
+static unsigned int nreqs; /* reqlock */
+static unsigned int nready; /* reqlock */
+static unsigned int npending; /* reqlock */
+static unsigned int max_idle = 4; /* maximum number of threads that can idle indefinitely */
+static unsigned int idle_timeout = 10; /* number of seconds after which an idle threads exit */
static xmutex_t wrklock;
static xmutex_t reslock;