ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libeio/xthread.h
(Generate patch)

Comparing libeio/xthread.h (file contents):
Revision 1.8 by root, Wed Mar 31 00:46:18 2010 UTC vs.
Revision 1.13 by root, Tue Jul 19 04:57:10 2011 UTC

1#ifndef XTHREAD_H_ 1#ifndef XTHREAD_H_
2#define XTHREAD_H_ 2#define XTHREAD_H_
3 3
4/* whether word reads are potentially non-atomic. 4/* whether word reads are potentially non-atomic.
5 * this is conservatice, likely most arches this runs 5 * this is conservative, likely most arches this runs
6 * on have atomic word read/writes. 6 * on have atomic word read/writes.
7 */ 7 */
8#ifndef WORDACCESS_UNSAFE 8#ifndef WORDACCESS_UNSAFE
9# if __i386 || __x86_64 9# if __i386 || __x86_64
10# define WORDACCESS_UNSAFE 0 10# define WORDACCESS_UNSAFE 0
14#endif 14#endif
15 15
16///////////////////////////////////////////////////////////////////////////// 16/////////////////////////////////////////////////////////////////////////////
17 17
18#ifdef _WIN32 18#ifdef _WIN32
19typedef int ssize_t;
20 19
21#define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls 20#define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls
22#define _WIN32_WINNT 0x400 21#define _WIN32_WINNT 0x400
23#include <stdio.h>//D 22#include <stdio.h>//D
24#include <fcntl.h> 23#include <fcntl.h>
35#define sigemptyset(s) 34#define sigemptyset(s)
36#define sigfillset(s) 35#define sigfillset(s)
37 36
38typedef pthread_mutex_t xmutex_t; 37typedef pthread_mutex_t xmutex_t;
39#define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER 38#define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
39#define X_MUTEX_CREATE(mutex) pthread_mutex_init (&(mutex), 0)
40#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) 40#define X_LOCK(mutex) pthread_mutex_lock (&(mutex))
41#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) 41#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
42 42
43typedef pthread_cond_t xcond_t; 43typedef pthread_cond_t xcond_t;
44#define X_COND_INIT PTHREAD_COND_INITIALIZER 44#define X_COND_INIT PTHREAD_COND_INITIALIZER
45#define X_COND_CREATE(cond) pthread_cond_init (&(cond), 0)
45#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) 46#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond))
46#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) 47#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex))
47#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) 48#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to))
48 49
49typedef pthread_t xthread_t; 50typedef pthread_t xthread_t;
94#include <limits.h> 95#include <limits.h>
95#include <pthread.h> 96#include <pthread.h>
96 97
97typedef pthread_mutex_t xmutex_t; 98typedef pthread_mutex_t xmutex_t;
98#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) 99#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP)
99# define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP 100# define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
101# define X_MUTEX_CREATE(mutex) \
102 do { \
103 pthread_mutexattr_t attr; \
104 pthread_mutexattr_init (&attr); \
105 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ADAPTIVE_NP); \
106 pthread_mutex_init (&(mutex), &attr); \
107 } while (0)
100#else 108#else
101# define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER 109# define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
110# define X_MUTEX_CREATE(mutex) pthread_mutex_init (&(mutex), 0)
102#endif 111#endif
103#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) 112#define X_LOCK(mutex) pthread_mutex_lock (&(mutex))
104#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) 113#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
105 114
106typedef pthread_cond_t xcond_t; 115typedef pthread_cond_t xcond_t;
107#define X_COND_INIT PTHREAD_COND_INITIALIZER 116#define X_COND_INIT PTHREAD_COND_INITIALIZER
117#define X_COND_CREATE(cond) pthread_cond_init (&(cond), 0)
108#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) 118#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond))
109#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) 119#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex))
110#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) 120#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to))
111 121
112typedef pthread_t xthread_t; 122typedef pthread_t xthread_t;
113#define X_THREAD_PROC(name) static void *name (void *thr_arg) 123#define X_THREAD_PROC(name) static void *name (void *thr_arg)
114#define X_THREAD_ATFORK(prepare,parent,child) pthread_atfork (prepare, parent, child) 124#define X_THREAD_ATFORK(prepare,parent,child) pthread_atfork (prepare, parent, child)
115 125
117#ifndef PTHREAD_STACK_MIN 127#ifndef PTHREAD_STACK_MIN
118# define PTHREAD_STACK_MIN 0 128# define PTHREAD_STACK_MIN 0
119#endif 129#endif
120 130
121#ifndef X_STACKSIZE 131#ifndef X_STACKSIZE
122# define X_STACKSIZE sizeof (long) * 4096 132# define X_STACKSIZE sizeof (void *) * 4096
123#endif 133#endif
124 134
125static int 135static int
126thread_create (xthread_t *tid, void *(*proc)(void *), void *arg) 136thread_create (xthread_t *tid, void *(*proc)(void *), void *arg)
127{ 137{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines