summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root>2011-07-18 01:27:03 +0000
committerroot <root>2011-07-18 01:27:03 +0000
commit7b5974c9e146f327c9a27f1d97d7fb6a8b95d15d (patch)
tree9506be71a97780feeab695d304b0c337cb4c8a9a
parente8c0c783e3de2e8833b80eeb3210fbd859667203 (diff)
*** empty log message ***
-rw-r--r--ecb.h43
-rw-r--r--eio.c36
2 files changed, 51 insertions, 28 deletions
diff --git a/ecb.h b/ecb.h
index 515f80d..8414e6e 100644
--- a/ecb.h
+++ b/ecb.h
@@ -63,6 +63,49 @@
#endif
#endif
+/*****************************************************************************/
+
+#ifndef ECB_MEMORY_FENCE
+ #if ECB_GCC_VERSION(2,5)
+ #if __x86
+ #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; or.b $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 */
+ #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")
+ #endif
+ #endif
+#endif
+
+#ifndef ECB_MEMORY_FENCE
+ #if ECB_GCC_VERSION(4,4)
+ #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
+ #define ECB_MEMORY_FENCE do { } while (0)
+ #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
+ #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
+ #elif defined(_WIN32) && defined(MemoryBarrier)
+ #define ECB_MEMORY_FENCE MemoryBarrier ()
+ #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
+ #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
+ #endif
+#endif
+
+#ifndef ECB_MEMORY_FENCE
+ #include <pthread.h>
+
+ static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER;
+ #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0)
+ #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
+ #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
+#endif
+
+/*****************************************************************************/
+
#define ECB_C99 (__STDC_VERSION__ >= 199901L)
#if __cplusplus
diff --git a/eio.c b/eio.c
index 4d70cd5..b367868 100644
--- a/eio.c
+++ b/eio.c
@@ -304,7 +304,7 @@ static xcond_t reqwait;
* normal read/write by using a mutex. slows down execution a lot,
* but that's your problem, not mine.
*/
-static xmutex_t preadwritelock = X_MUTEX_INIT;
+static xmutex_t preadwritelock;
#endif
typedef struct etp_worker
@@ -320,7 +320,7 @@ typedef struct etp_worker
ETP_WORKER_COMMON
} etp_worker;
-static etp_worker wrk_first = { &wrk_first, &wrk_first, 0 }; /* NOT etp */
+static etp_worker wrk_first; /* NOT etp */
#define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock)
#define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock)
@@ -455,21 +455,14 @@ reqq_shift (etp_reqq *q)
abort ();
}
-static void ecb_cold
-etp_thread_init (void)
+static int ecb_cold
+etp_init (void (*want_poll)(void), void (*done_poll)(void))
{
-#if !HAVE_PREADWRITE
- X_MUTEX_CREATE (preadwritelock);
-#endif
X_MUTEX_CREATE (wrklock);
X_MUTEX_CREATE (reslock);
X_MUTEX_CREATE (reqlock);
X_COND_CREATE (reqwait);
-}
-static void ecb_cold
-etp_atfork_child (void)
-{
reqq_init (&req_queue);
reqq_init (&res_queue);
@@ -482,23 +475,6 @@ etp_atfork_child (void)
nready = 0;
npending = 0;
- etp_thread_init ();
-}
-
-static void ecb_cold
-etp_once_init (void)
-{
- etp_thread_init ();
- X_THREAD_ATFORK (0, 0, etp_atfork_child);
-}
-
-static int ecb_cold
-etp_init (void (*want_poll)(void), void (*done_poll)(void))
-{
- static pthread_once_t doinit = PTHREAD_ONCE_INIT;
-
- pthread_once (&doinit, etp_once_init);
-
want_poll_cb = want_poll;
done_poll_cb = done_poll;
@@ -1993,6 +1969,10 @@ quit:
int ecb_cold
eio_init (void (*want_poll)(void), void (*done_poll)(void))
{
+#if !HAVE_PREADWRITE
+ X_MUTEX_CREATE (preadwritelock);
+#endif
+
return etp_init (want_poll, done_poll);
}