Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/include/X11
File: Xthreads.h
/*
[0] Fix | Delete
*
[1] Fix | Delete
Copyright 1993, 1998 The Open Group
[2] Fix | Delete
[3] Fix | Delete
Permission to use, copy, modify, distribute, and sell this software and its
[4] Fix | Delete
documentation for any purpose is hereby granted without fee, provided that
[5] Fix | Delete
the above copyright notice appear in all copies and that both that
[6] Fix | Delete
copyright notice and this permission notice appear in supporting
[7] Fix | Delete
documentation.
[8] Fix | Delete
[9] Fix | Delete
The above copyright notice and this permission notice shall be included in
[10] Fix | Delete
all copies or substantial portions of the Software.
[11] Fix | Delete
[12] Fix | Delete
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
[13] Fix | Delete
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
[14] Fix | Delete
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
[15] Fix | Delete
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
[16] Fix | Delete
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
[17] Fix | Delete
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[18] Fix | Delete
[19] Fix | Delete
Except as contained in this notice, the name of The Open Group shall not be
[20] Fix | Delete
used in advertising or otherwise to promote the sale, use or other dealings
[21] Fix | Delete
in this Software without prior written authorization from The Open Group.
[22] Fix | Delete
* *
[23] Fix | Delete
*/
[24] Fix | Delete
[25] Fix | Delete
#ifndef _XTHREADS_H_
[26] Fix | Delete
# define _XTHREADS_H_
[27] Fix | Delete
[28] Fix | Delete
/* Redefine these to XtMalloc/XtFree or whatever you want before including
[29] Fix | Delete
* this header file.
[30] Fix | Delete
*/
[31] Fix | Delete
# ifndef xmalloc
[32] Fix | Delete
# define xmalloc malloc
[33] Fix | Delete
# endif
[34] Fix | Delete
# ifndef xfree
[35] Fix | Delete
# define xfree free
[36] Fix | Delete
# endif
[37] Fix | Delete
[38] Fix | Delete
# ifdef CTHREADS
[39] Fix | Delete
# include <cthreads.h>
[40] Fix | Delete
typedef cthread_t xthread_t;
[41] Fix | Delete
typedef struct condition xcondition_rec;
[42] Fix | Delete
typedef struct mutex xmutex_rec;
[43] Fix | Delete
# define xthread_init() cthread_init()
[44] Fix | Delete
# define xthread_self cthread_self
[45] Fix | Delete
# define xthread_fork(func,closure) cthread_fork(func,closure)
[46] Fix | Delete
# define xthread_yield() cthread_yield()
[47] Fix | Delete
# define xthread_exit(v) cthread_exit(v)
[48] Fix | Delete
# define xthread_set_name(t,str) cthread_set_name(t,str)
[49] Fix | Delete
# define xmutex_init(m) mutex_init(m)
[50] Fix | Delete
# define xmutex_clear(m) mutex_clear(m)
[51] Fix | Delete
# define xmutex_lock(m) mutex_lock(m)
[52] Fix | Delete
# define xmutex_unlock(m) mutex_unlock(m)
[53] Fix | Delete
# define xmutex_set_name(m,str) mutex_set_name(m,str)
[54] Fix | Delete
# define xcondition_init(cv) condition_init(cv)
[55] Fix | Delete
# define xcondition_clear(cv) condition_clear(cv)
[56] Fix | Delete
# define xcondition_wait(cv,m) condition_wait(cv,m)
[57] Fix | Delete
# define xcondition_signal(cv) condition_signal(cv)
[58] Fix | Delete
# define xcondition_broadcast(cv) condition_broadcast(cv)
[59] Fix | Delete
# define xcondition_set_name(cv,str) condition_set_name(cv,str)
[60] Fix | Delete
# else /* !CTHREADS */
[61] Fix | Delete
# if defined(SVR4)
[62] Fix | Delete
# include <thread.h>
[63] Fix | Delete
# include <synch.h>
[64] Fix | Delete
typedef thread_t xthread_t;
[65] Fix | Delete
typedef thread_key_t xthread_key_t;
[66] Fix | Delete
typedef cond_t xcondition_rec;
[67] Fix | Delete
typedef mutex_t xmutex_rec;
[68] Fix | Delete
# if defined(__UNIXWARE__)
[69] Fix | Delete
extern xthread_t (*_x11_thr_self)();
[70] Fix | Delete
# define xthread_self (_x11_thr_self)
[71] Fix | Delete
# else
[72] Fix | Delete
# define xthread_self thr_self
[73] Fix | Delete
# endif
[74] Fix | Delete
# define xthread_fork(func,closure) thr_create(NULL,0,func,closure,THR_NEW_LWP|THR_DETACHED,NULL)
[75] Fix | Delete
# define xthread_yield() thr_yield()
[76] Fix | Delete
# define xthread_exit(v) thr_exit(v)
[77] Fix | Delete
# define xthread_key_create(kp,d) thr_keycreate(kp,d)
[78] Fix | Delete
# ifdef __sun
[79] Fix | Delete
# define xthread_key_delete(k) 0
[80] Fix | Delete
# else
[81] Fix | Delete
# define xthread_key_delete(k) thr_keydelete(k)
[82] Fix | Delete
# endif
[83] Fix | Delete
# define xthread_set_specific(k,v) thr_setspecific(k,v)
[84] Fix | Delete
# define xthread_get_specific(k,vp) thr_getspecific(k,vp)
[85] Fix | Delete
# define xmutex_init(m) mutex_init(m,USYNC_THREAD,0)
[86] Fix | Delete
# define xmutex_clear(m) mutex_destroy(m)
[87] Fix | Delete
# define xmutex_lock(m) mutex_lock(m)
[88] Fix | Delete
# define xmutex_unlock(m) mutex_unlock(m)
[89] Fix | Delete
# define xcondition_init(cv) cond_init(cv,USYNC_THREAD,0)
[90] Fix | Delete
# define xcondition_clear(cv) cond_destroy(cv)
[91] Fix | Delete
# define xcondition_wait(cv,m) cond_wait(cv,m)
[92] Fix | Delete
# define xcondition_signal(cv) cond_signal(cv)
[93] Fix | Delete
# define xcondition_broadcast(cv) cond_broadcast(cv)
[94] Fix | Delete
# else /* !SVR4 */
[95] Fix | Delete
# ifdef WIN32
[96] Fix | Delete
# include <X11/Xwindows.h>
[97] Fix | Delete
typedef DWORD xthread_t;
[98] Fix | Delete
typedef DWORD xthread_key_t;
[99] Fix | Delete
struct _xthread_waiter {
[100] Fix | Delete
HANDLE sem;
[101] Fix | Delete
struct _xthread_waiter *next;
[102] Fix | Delete
};
[103] Fix | Delete
typedef struct {
[104] Fix | Delete
CRITICAL_SECTION cs;
[105] Fix | Delete
struct _xthread_waiter *waiters;
[106] Fix | Delete
} xcondition_rec;
[107] Fix | Delete
typedef CRITICAL_SECTION xmutex_rec;
[108] Fix | Delete
extern void _Xthread_init(void);
[109] Fix | Delete
# define xthread_init() _Xthread_init()
[110] Fix | Delete
# define xthread_self GetCurrentThreadId
[111] Fix | Delete
# define xthread_fork(func,closure) { \
[112] Fix | Delete
DWORD _tmptid; \
[113] Fix | Delete
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, (LPVOID)closure, 0, \
[114] Fix | Delete
&_tmptid); \
[115] Fix | Delete
}
[116] Fix | Delete
# define xthread_yield() Sleep(0)
[117] Fix | Delete
# define xthread_exit(v) ExitThread((DWORD)(v))
[118] Fix | Delete
# define xthread_key_create(kp,d) *(kp) = TlsAlloc()
[119] Fix | Delete
# define xthread_key_delete(k) TlsFree(k)
[120] Fix | Delete
# define xthread_set_specific(k,v) TlsSetValue(k,v)
[121] Fix | Delete
# define xthread_get_specific(k,vp) TlsGetValue(k)
[122] Fix | Delete
# define xmutex_init(m) InitializeCriticalSection(m)
[123] Fix | Delete
# define xmutex_clear(m) DeleteCriticalSection(m)
[124] Fix | Delete
# define _XMUTEX_NESTS
[125] Fix | Delete
# define xmutex_lock(m) EnterCriticalSection(m)
[126] Fix | Delete
# define xmutex_unlock(m) LeaveCriticalSection(m)
[127] Fix | Delete
# define xcondition_init(cv) { \
[128] Fix | Delete
InitializeCriticalSection(&(cv)->cs); \
[129] Fix | Delete
(cv)->waiters = NULL; \
[130] Fix | Delete
}
[131] Fix | Delete
# define xcondition_clear(cv) DeleteCriticalSection(&(cv)->cs)
[132] Fix | Delete
extern struct _xthread_waiter *_Xthread_waiter();
[133] Fix | Delete
# define xcondition_wait(cv,m) { \
[134] Fix | Delete
struct _xthread_waiter *_tmpthr = _Xthread_waiter(); \
[135] Fix | Delete
EnterCriticalSection(&(cv)->cs); \
[136] Fix | Delete
_tmpthr->next = (cv)->waiters; \
[137] Fix | Delete
(cv)->waiters = _tmpthr; \
[138] Fix | Delete
LeaveCriticalSection(&(cv)->cs); \
[139] Fix | Delete
LeaveCriticalSection(m); \
[140] Fix | Delete
WaitForSingleObject(_tmpthr->sem, INFINITE); \
[141] Fix | Delete
EnterCriticalSection(m); \
[142] Fix | Delete
}
[143] Fix | Delete
# define xcondition_signal(cv) { \
[144] Fix | Delete
EnterCriticalSection(&(cv)->cs); \
[145] Fix | Delete
if ((cv)->waiters) { \
[146] Fix | Delete
ReleaseSemaphore((cv)->waiters->sem, 1, NULL); \
[147] Fix | Delete
(cv)->waiters = (cv)->waiters->next; \
[148] Fix | Delete
} \
[149] Fix | Delete
LeaveCriticalSection(&(cv)->cs); \
[150] Fix | Delete
}
[151] Fix | Delete
# define xcondition_broadcast(cv) { \
[152] Fix | Delete
struct _xthread_waiter *_tmpthr; \
[153] Fix | Delete
EnterCriticalSection(&(cv)->cs); \
[154] Fix | Delete
for (_tmpthr = (cv)->waiters; _tmpthr; _tmpthr = _tmpthr->next) \
[155] Fix | Delete
ReleaseSemaphore(_tmpthr->sem, 1, NULL); \
[156] Fix | Delete
(cv)->waiters = NULL; \
[157] Fix | Delete
LeaveCriticalSection(&(cv)->cs); \
[158] Fix | Delete
}
[159] Fix | Delete
# else /* !WIN32 */
[160] Fix | Delete
# ifdef USE_TIS_SUPPORT
[161] Fix | Delete
/*
[162] Fix | Delete
* TIS support is intended for thread safe libraries.
[163] Fix | Delete
* This should not be used for general client programming.
[164] Fix | Delete
*/
[165] Fix | Delete
# include <tis.h>
[166] Fix | Delete
typedef pthread_t xthread_t;
[167] Fix | Delete
typedef pthread_key_t xthread_key_t;
[168] Fix | Delete
typedef pthread_cond_t xcondition_rec;
[169] Fix | Delete
typedef pthread_mutex_t xmutex_rec;
[170] Fix | Delete
# define xthread_self tis_self
[171] Fix | Delete
# define xthread_fork(func,closure) { pthread_t _tmpxthr; \
[172] Fix | Delete
pthread_create(&_tmpxthr,NULL,func,closure); }
[173] Fix | Delete
# define xthread_yield() pthread_yield_np()
[174] Fix | Delete
# define xthread_exit(v) pthread_exit(v)
[175] Fix | Delete
# define xthread_key_create(kp,d) tis_key_create(kp,d)
[176] Fix | Delete
# define xthread_key_delete(k) tis_key_delete(k)
[177] Fix | Delete
# define xthread_set_specific(k,v) tis_setspecific(k,v)
[178] Fix | Delete
# define xthread_get_specific(k,vp) *(vp) = tis_getspecific(k)
[179] Fix | Delete
# define XMUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
[180] Fix | Delete
# define xmutex_init(m) tis_mutex_init(m)
[181] Fix | Delete
# define xmutex_clear(m) tis_mutex_destroy(m)
[182] Fix | Delete
# define xmutex_lock(m) tis_mutex_lock(m)
[183] Fix | Delete
# define xmutex_unlock(m) tis_mutex_unlock(m)
[184] Fix | Delete
# define xcondition_init(c) tis_cond_init(c)
[185] Fix | Delete
# define xcondition_clear(c) tis_cond_destroy(c)
[186] Fix | Delete
# define xcondition_wait(c,m) tis_cond_wait(c,m)
[187] Fix | Delete
# define xcondition_signal(c) tis_cond_signal(c)
[188] Fix | Delete
# define xcondition_broadcast(c) tis_cond_broadcast(c)
[189] Fix | Delete
# else
[190] Fix | Delete
# ifdef USE_NBSD_THREADLIB
[191] Fix | Delete
/*
[192] Fix | Delete
* NetBSD threadlib support is intended for thread safe libraries.
[193] Fix | Delete
* This should not be used for general client programming.
[194] Fix | Delete
*/
[195] Fix | Delete
# include <threadlib.h>
[196] Fix | Delete
typedef thr_t xthread_t;
[197] Fix | Delete
typedef thread_key_t xthread_key_t;
[198] Fix | Delete
typedef cond_t xcondition_rec;
[199] Fix | Delete
typedef mutex_t xmutex_rec;
[200] Fix | Delete
# define xthread_self thr_self
[201] Fix | Delete
# define xthread_fork(func,closure) { thr_t _tmpxthr; \
[202] Fix | Delete
/* XXX Create it detached? --thorpej */ \
[203] Fix | Delete
thr_create(&_tmpxthr,NULL,func,closure); }
[204] Fix | Delete
# define xthread_yield() thr_yield()
[205] Fix | Delete
# define xthread_exit(v) thr_exit(v)
[206] Fix | Delete
# define xthread_key_create(kp,d) thr_keycreate(kp,d)
[207] Fix | Delete
# define xthread_key_delete(k) thr_keydelete(k)
[208] Fix | Delete
# define xthread_set_specific(k,v) thr_setspecific(k,v)
[209] Fix | Delete
# define xthread_get_specific(k,vp) *(vp) = thr_getspecific(k)
[210] Fix | Delete
# define XMUTEX_INITIALIZER MUTEX_INITIALIZER
[211] Fix | Delete
# define xmutex_init(m) mutex_init(m, 0)
[212] Fix | Delete
# define xmutex_clear(m) mutex_destroy(m)
[213] Fix | Delete
# define xmutex_lock(m) mutex_lock(m)
[214] Fix | Delete
# define xmutex_unlock(m) mutex_unlock(m)
[215] Fix | Delete
# define xcondition_init(c) cond_init(c, 0, 0)
[216] Fix | Delete
# define xcondition_clear(c) cond_destroy(c)
[217] Fix | Delete
# define xcondition_wait(c,m) cond_wait(c,m)
[218] Fix | Delete
# define xcondition_signal(c) cond_signal(c)
[219] Fix | Delete
# define xcondition_broadcast(c) cond_broadcast(c)
[220] Fix | Delete
# else
[221] Fix | Delete
# include <pthread.h>
[222] Fix | Delete
typedef pthread_t xthread_t;
[223] Fix | Delete
typedef pthread_key_t xthread_key_t;
[224] Fix | Delete
typedef pthread_cond_t xcondition_rec;
[225] Fix | Delete
typedef pthread_mutex_t xmutex_rec;
[226] Fix | Delete
# define xthread_self pthread_self
[227] Fix | Delete
# define xthread_yield() pthread_yield()
[228] Fix | Delete
# define xthread_exit(v) pthread_exit(v)
[229] Fix | Delete
# define xthread_set_specific(k,v) pthread_setspecific(k,v)
[230] Fix | Delete
# define xmutex_clear(m) pthread_mutex_destroy(m)
[231] Fix | Delete
# define xmutex_lock(m) pthread_mutex_lock(m)
[232] Fix | Delete
# define xmutex_unlock(m) pthread_mutex_unlock(m)
[233] Fix | Delete
# ifndef XPRE_STANDARD_API
[234] Fix | Delete
# define xthread_key_create(kp,d) pthread_key_create(kp,d)
[235] Fix | Delete
# define xthread_key_delete(k) pthread_key_delete(k)
[236] Fix | Delete
# define xthread_get_specific(k,vp) *(vp) = pthread_getspecific(k)
[237] Fix | Delete
# define xthread_fork(func,closure) { pthread_t _tmpxthr; \
[238] Fix | Delete
pthread_create(&_tmpxthr,NULL,func,closure); }
[239] Fix | Delete
# define XMUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
[240] Fix | Delete
# define xmutex_init(m) pthread_mutex_init(m, NULL)
[241] Fix | Delete
# define xcondition_init(c) pthread_cond_init(c, NULL)
[242] Fix | Delete
# else /* XPRE_STANDARD_API */
[243] Fix | Delete
# define xthread_key_create(kp,d) pthread_keycreate(kp,d)
[244] Fix | Delete
# define xthread_key_delete(k) 0
[245] Fix | Delete
# define xthread_get_specific(k,vp) pthread_getspecific(k,vp)
[246] Fix | Delete
# define xthread_fork(func,closure) { pthread_t _tmpxthr; \
[247] Fix | Delete
pthread_create(&_tmpxthr,pthread_attr_default,func,closure); }
[248] Fix | Delete
# define xmutex_init(m) pthread_mutex_init(m, pthread_mutexattr_default)
[249] Fix | Delete
# define xcondition_init(c) pthread_cond_init(c, pthread_condattr_default)
[250] Fix | Delete
# endif /* XPRE_STANDARD_API */
[251] Fix | Delete
# define xcondition_clear(c) pthread_cond_destroy(c)
[252] Fix | Delete
# define xcondition_wait(c,m) pthread_cond_wait(c,m)
[253] Fix | Delete
# define xcondition_signal(c) pthread_cond_signal(c)
[254] Fix | Delete
# define xcondition_broadcast(c) pthread_cond_broadcast(c)
[255] Fix | Delete
# if defined(_DECTHREADS_)
[256] Fix | Delete
static xthread_t _X_no_thread_id;
[257] Fix | Delete
# define xthread_have_id(id) !pthread_equal(id, _X_no_thread_id)
[258] Fix | Delete
# define xthread_clear_id(id) id = _X_no_thread_id
[259] Fix | Delete
# define xthread_equal(id1,id2) pthread_equal(id1, id2)
[260] Fix | Delete
# endif /* _DECTHREADS_ */
[261] Fix | Delete
# if defined(__linux__)
[262] Fix | Delete
# define xthread_have_id(id) !pthread_equal(id, 0)
[263] Fix | Delete
# define xthread_clear_id(id) id = 0
[264] Fix | Delete
# define xthread_equal(id1,id2) pthread_equal(id1, id2)
[265] Fix | Delete
# endif /* linux */
[266] Fix | Delete
# if defined(_CMA_VENDOR_) && defined(_CMA__IBM) && (_CMA_VENDOR_ == _CMA__IBM)
[267] Fix | Delete
# ifdef DEBUG /* too much of a hack to enable normally */
[268] Fix | Delete
/* see also cma__obj_set_name() */
[269] Fix | Delete
# define xmutex_set_name(m,str) ((char**)(m)->field1)[5] = (str)
[270] Fix | Delete
# define xcondition_set_name(cv,str) ((char**)(cv)->field1)[5] = (str)
[271] Fix | Delete
# endif /* DEBUG */
[272] Fix | Delete
# endif /* _CMA_VENDOR_ == _CMA__IBM */
[273] Fix | Delete
# endif /* USE_NBSD_THREADLIB */
[274] Fix | Delete
# endif /* USE_TIS_SUPPORT */
[275] Fix | Delete
# endif /* WIN32 */
[276] Fix | Delete
# endif /* SVR4 */
[277] Fix | Delete
# endif /* CTHREADS */
[278] Fix | Delete
typedef xcondition_rec *xcondition_t;
[279] Fix | Delete
typedef xmutex_rec *xmutex_t;
[280] Fix | Delete
# ifndef xcondition_malloc
[281] Fix | Delete
# define xcondition_malloc() (xcondition_t)xmalloc(sizeof(xcondition_rec))
[282] Fix | Delete
# endif
[283] Fix | Delete
# ifndef xcondition_free
[284] Fix | Delete
# define xcondition_free(c) xfree((char *)c)
[285] Fix | Delete
# endif
[286] Fix | Delete
# ifndef xmutex_malloc
[287] Fix | Delete
# define xmutex_malloc() (xmutex_t)xmalloc(sizeof(xmutex_rec))
[288] Fix | Delete
# endif
[289] Fix | Delete
# ifndef xmutex_free
[290] Fix | Delete
# define xmutex_free(m) xfree((char *)m)
[291] Fix | Delete
# endif
[292] Fix | Delete
# ifndef xthread_have_id
[293] Fix | Delete
# define xthread_have_id(id) id
[294] Fix | Delete
# endif
[295] Fix | Delete
# ifndef xthread_clear_id
[296] Fix | Delete
# define xthread_clear_id(id) id = 0
[297] Fix | Delete
# endif
[298] Fix | Delete
# ifndef xthread_equal
[299] Fix | Delete
# define xthread_equal(id1,id2) ((id1) == (id2))
[300] Fix | Delete
# endif
[301] Fix | Delete
/* aids understood by some debuggers */
[302] Fix | Delete
# ifndef xthread_set_name
[303] Fix | Delete
# define xthread_set_name(t,str)
[304] Fix | Delete
# endif
[305] Fix | Delete
# ifndef xmutex_set_name
[306] Fix | Delete
# define xmutex_set_name(m,str)
[307] Fix | Delete
# endif
[308] Fix | Delete
# ifndef xcondition_set_name
[309] Fix | Delete
# define xcondition_set_name(cv,str)
[310] Fix | Delete
# endif
[311] Fix | Delete
[312] Fix | Delete
#endif /* _XTHREADS_H_ */
[313] Fix | Delete
[314] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function