1 kumpf 1.2 //%/////////////////////////////////////////////////////////////////////////////
|
2 ramnath 1.1 //
|
3 kumpf 1.2 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
|
5 ramnath 1.1 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 kumpf 1.2 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10 ramnath 1.1 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
|
13 kumpf 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
14 ramnath 1.1 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
16 kumpf 1.2 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
19 ramnath 1.1 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
24 // Author: Brian Bobryk (Brian.Bobryk@compaq.com)
25 //
26 // Modified By:
27 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
30 #ifndef IPC_TRU64_include
31 #define IPC_TRU64_include
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 ramnath 1.1
41 PEGASUS_NAMESPACE_BEGIN
42
43 typedef sem_t PEGASUS_SEMAPHORE_TYPE;
44 typedef pthread_t PEGASUS_THREAD_TYPE;
45 typedef pthread_mutex_t PEGASUS_MUTEX_TYPE;
46
47 typedef struct {
|
48 ramnath 1.3 PEGASUS_SEMAPHORE_TYPE sem;
49 PEGASUS_THREAD_TYPE owner;
50 } PEGASUS_SEM_HANDLE ;
51
52 /*
53 typedef struct {
|
54 ramnath 1.1 Uint32 waiters;
55 pthread_mutex_t mutex;
56 pthread_cond_t cond;
57 PEGASUS_THREAD_TYPE owner;
58 } PEGASUS_SEM_HANDLE ;
|
59 ramnath 1.3 */
|
60 ramnath 1.1
61 typedef struct {
62 pthread_mutex_t mut;
63 pthread_mutexattr_t mutatt;
64 pthread_t owner;
65 } PEGASUS_MUTEX_HANDLE ;
66
67 typedef PEGASUS_MUTEX_HANDLE PEGASUS_CRIT_TYPE;
68
69 typedef void *PEGASUS_CLEANUP_HANDLE ;
70 typedef void *PEGASUS_THREAD_RETURN;
71
72 #define PEGASUS_THREAD_CDECL
73
74 typedef struct {
75 pthread_t thid;
76 pthread_attr_t thatt;
77 } PEGASUS_THREAD_HANDLE ;
78
79 //-----------------------------------------------------------------
80 /// Conditionals to support native or generic Conditional Semaphore
81 ramnath 1.1 //-----------------------------------------------------------------
82
83 #define PEGASUS_CONDITIONAL_NATIVE = 1
84
85 typedef pthread_cond_t PEGASUS_COND_TYPE;
86
87 typedef struct {
88 pthread_cond_t cond;
89 pthread_t owner;
90 } PEGASUS_COND_HANDLE;
91
92
93 //-----------------------------------------------------------------
94 /// Conditionals to support native or generic atomic variables
95 //-----------------------------------------------------------------
96
97 // linux offers a built-in integer type for atomic access
98 // other unix platforms HPUX, AIX, may have different types
99 // implementors should use the native type for faster operations
100
101 // ATTN: RK - sig_atomic_t is defined on HP-UX, but the atomic_read()
102 ramnath 1.1 // and atomic_write() methods are not defined. Use the non-native
103 // implementation for now.
104
105 // #define PEGASUS_ATOMIC_INT_NATIVE = 1
106
107 // typedef sig_atomic_t PEGASUS_ATOMIC_TYPE ;
108
109
110 //-----------------------------------------------------------------
111 /// Conditionals to support native or generic read/write semaphores
112 //-----------------------------------------------------------------
113
114 #define PEGASUS_READWRITE_NATIVE = 1
115
116 typedef struct {
117 pthread_rwlock_t rwlock;
118 pthread_t owner;
119 } PEGASUS_RWLOCK_HANDLE;
120
121 inline void pegasus_yield(void)
122 {
123 ramnath 1.1 sched_yield();
124 }
125
126
127 // pthreads cancellation calls
128 inline void disable_cancel(void)
129 {
130 pthread_setcanceltype(PTHREAD_CANCEL_DISABLE, NULL);
131 }
132
133 inline void enable_cancel(void)
134 {
135 pthread_setcanceltype(PTHREAD_CANCEL_DISABLE, NULL);
136 }
137
138 inline void pegasus_sleep(int msec)
139 {
140 struct timespec wait;
141 wait.tv_sec = msec / 1000;
|
142 kumpf 1.4 wait.tv_nsec = (msec % 1000) * 1000000;
|
143 ramnath 1.1 nanosleep(&wait, NULL);
144 }
145
146 inline void init_crit(PEGASUS_CRIT_TYPE *crit)
147 {
148 pthread_mutex_init(&(crit->mut), NULL);
149 }
150
151 inline void enter_crit(PEGASUS_CRIT_TYPE *crit)
152 {
153 pthread_mutex_lock(&(crit->mut));
154 }
155
156 inline void try_crit(PEGASUS_CRIT_TYPE *crit)
157 {
158 pthread_mutex_trylock(&(crit->mut));
159 }
160
161 inline void exit_crit(PEGASUS_CRIT_TYPE *crit)
162 {
163 pthread_mutex_unlock(&(crit->mut));
164 ramnath 1.1 }
165
166 inline void destroy_crit(PEGASUS_CRIT_TYPE *crit)
167 {
168 pthread_mutexattr_destroy(&(crit->mutatt));
169 }
170
171 static inline int pegasus_gettimeofday(struct timeval *tv) { return(gettimeofday(tv, NULL)); }
172
173 inline void exit_thread(PEGASUS_THREAD_RETURN rc)
174 {
175 pthread_exit(rc);
176 }
177
178 inline PEGASUS_THREAD_TYPE pegasus_thread_self(void)
179 {
180 return(pthread_self());
181 }
182
183 inline void destroy_thread(PEGASUS_THREAD_TYPE th, PEGASUS_THREAD_RETURN rc)
184 {
185 ramnath 1.1 pthread_cancel(th);
186 }
187
188
189 PEGASUS_NAMESPACE_END
190
191 #endif // IPCTRU64Include
|