3 karl 1.2 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
|
7 keith.petley 1.1 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Mike Day (mdday@us.ibm.com) and Roger Kumpf (roger_kumpf@hp.com)
27 //
28 keith.petley 1.1 // Modified By: Keith Petley (keithp@veritas.com)
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32
33 #include <sched.h>
34 #include <pthread.h>
35 #include <semaphore.h>
36 #include <signal.h>
37 #include <errno.h>
38 #include <sys/time.h>
39 #include <time.h>
40
41
42 typedef sem_t PEGASUS_SEMAPHORE_TYPE;
43 typedef pthread_t PEGASUS_THREAD_TYPE;
44 typedef pthread_mutex_t PEGASUS_MUTEX_TYPE;
45
46 typedef struct {
47 sem_t sem;
48 pthread_t owner;
49 keith.petley 1.1 } PEGASUS_SEM_HANDLE ;
50
51 typedef struct {
52 pthread_mutex_t mut;
53 pthread_mutexattr_t mutatt;
54 pthread_t owner;
55 } PEGASUS_MUTEX_HANDLE ;
56
57 typedef PEGASUS_MUTEX_HANDLE PEGASUS_CRIT_TYPE;
58
59 typedef void *PEGASUS_CLEANUP_HANDLE ;
60 typedef void *PEGASUS_THREAD_RETURN;
61
62 #define PEGASUS_THREAD_CDECL
63
64 typedef struct {
65 pthread_t thid;
66 pthread_attr_t thatt;
67 } PEGASUS_THREAD_HANDLE ;
68
69 //-----------------------------------------------------------------
70 keith.petley 1.1 /// Conditionals to support native or generic Conditional Semaphore
71 //-----------------------------------------------------------------
72
|
74 keith.petley 1.1
75 typedef pthread_cond_t PEGASUS_COND_TYPE;
76
77 typedef struct {
78 pthread_cond_t cond;
79 pthread_t owner;
80 } PEGASUS_COND_HANDLE;
81
82
83 //-----------------------------------------------------------------
84 /// Conditionals to support native or generic atomic variables
85 //-----------------------------------------------------------------
86
87 // linux offers a built-in integer type for atomic access
88 // other unix platforms HPUX, AIX, may have different types
89 // implementors should use the native type for faster operations
90
|
102 keith.petley 1.1
103 typedef struct {
104 pthread_rwlock_t rwlock;
105 pthread_t owner;
106 } PEGASUS_RWLOCK_HANDLE;
107 #endif //SUNOS_5_6
108
109 PEGASUS_NAMESPACE_BEGIN
110 inline void pegasus_yield(void)
111 {
112 sched_yield();
113 }
114
115
116 // pthreads cancellation calls
117 inline void disable_cancel(void)
118 {
119 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
120 }
121
122 inline void enable_cancel(void)
123 keith.petley 1.1 {
124 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
125 }
126
127 inline void pegasus_sleep(int msec)
128 {
129 struct timespec wait;
130 wait.tv_sec = msec / 1000;
131 wait.tv_nsec = (msec % 1000) * 1000000;
132 nanosleep(&wait, NULL);
133 }
134
135 static inline int pegasus_gettimeofday(struct timeval *tv)
136 {
137 return(gettimeofday(tv, NULL));
138 }
139
140 inline void exit_thread(PEGASUS_THREAD_RETURN rc)
141 {
142 pthread_exit(rc);
143 }
144 keith.petley 1.1
145 inline PEGASUS_THREAD_TYPE pegasus_thread_self(void)
146 {
147 return(pthread_self());
148 }
149
150 // l10n start
151 typedef pthread_key_t PEGASUS_THREAD_KEY_TYPE;
152
153 inline Uint32 pegasus_key_create(PEGASUS_THREAD_KEY_TYPE * key)
154 {
155 // Note: a destructor is not supported
156 // (because not supported on Windows (?))
157 return pthread_key_create(key, NULL);
158 }
159
160 inline Uint32 pegasus_key_delete(PEGASUS_THREAD_KEY_TYPE key)
161 {
162 return pthread_key_delete(key);
163 }
164
165 keith.petley 1.1 inline void * pegasus_get_thread_specific(PEGASUS_THREAD_KEY_TYPE key)
166 {
167 return pthread_getspecific(key);
168 }
169
170 inline Uint32 pegasus_set_thread_specific(PEGASUS_THREAD_KEY_TYPE key,
171 void * value)
172 {
173 return pthread_setspecific(key, value);
174 }
175 // l10n end
176
177 inline void destroy_thread(PEGASUS_THREAD_TYPE th, PEGASUS_THREAD_RETURN rc)
178 {
179 pthread_cancel(th);
180 }
181
182
183 PEGASUS_NAMESPACE_END
|