54 #include <sys/sched.h>
58 #if defined(OPSYS_SUN)
107 #if defined( HAVE_PTHREAD_MUTEXATTR_SETTYPE )
108 pthread_mutexattr_t mutexattr;
110 iRC = pthread_mutexattr_init(&mutexattr);
113 #if defined( HAVE_PTHREAD_MUTEX_RECURSIVE_NP )
114 iRC = pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE_NP);
115 #elif defined( HAVE_PTHREAD_MUTEX_RECURSIVE )
116 iRC = pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
117 #elif defined( HAVE_PTHREAD_MUTEX_ERRORCHECK )
118 iRC = pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK);
120 fprintf(stderr,
" *** ERROR: Unknown 2nd argument to pthread_mutexattr_settype()!\n");
125 iRC = pthread_mutex_init(&(this->
semMutex), &mutexattr);
129 iRC = pthread_mutexattr_destroy(&mutexattr);
133 iRC = pthread_cond_init(&(this->
semCond), NULL);
136 iRC = pthread_mutex_init(&(this->
semMutex), NULL);
139 iRC = pthread_cond_init(&(this->
semCond), NULL);
144 fprintf(stderr,
" *** ERROR: At RexxSemaphore(), pthread_mutex_init - RC = %d !\n", iRC);
147 fprintf(stderr,
" *** ERROR: Application was not built thread safe!\n");
159 pthread_cond_destroy(&(this->
semCond));
160 pthread_mutex_destroy(&(this->
semMutex));
170 rc = pthread_mutex_lock(&(this->
semMutex));
172 rc = pthread_cond_broadcast(&(this->
semCond));
173 rc = pthread_mutex_unlock(&(this->
semMutex));
179 int schedpolicy, i_prio;
180 struct sched_param schedparam;
182 pthread_getschedparam(pthread_self(), &schedpolicy, &schedparam);
183 i_prio = schedparam.sched_priority;
184 schedparam.sched_priority = 100;
185 pthread_setschedparam(pthread_self(),SCHED_OTHER, &schedparam);
186 rc = pthread_mutex_lock(&(this->
semMutex));
190 #ifdef CONCURRENCY_DEBUG
195 dbgprintf(
CONCURRENCY_TRACE "...... ... (SysSemaphore)%s.wait : before pthread_cond_wait(0x%x, 0x%x) from %s (0x%x)\n", concurrencyInfos.
threadId, concurrencyInfos.
activation, concurrencyInfos.
variableDictionary, concurrencyInfos.
reserveCount, concurrencyInfos.
lock,
semVariable, &(this->semCond), &(this->semMutex), ds, di);
199 #ifdef CONCURRENCY_DEBUG
204 dbgprintf(
CONCURRENCY_TRACE "...... ... (SysSemaphore)%s.wait : after pthread_cond_wait(0x%x, 0x%x) from %s (0x%x)\n", concurrencyInfos.
threadId, concurrencyInfos.
activation, concurrencyInfos.
variableDictionary, concurrencyInfos.
reserveCount, concurrencyInfos.
lock,
semVariable, &(this->semCond), &(this->semMutex), ds, di);
209 pthread_mutex_unlock(&(this->
semMutex));
210 schedparam.sched_priority = i_prio;
211 pthread_setschedparam(pthread_self(),SCHED_OTHER, &schedparam);
216 struct timespec timestruct;
220 timestruct.tv_nsec = 0;
221 timestruct.tv_sec = t/1000+time(Tpnt);
222 pthread_mutex_lock(&(this->
semMutex));
225 #ifdef CONCURRENCY_DEBUG
230 dbgprintf(
CONCURRENCY_TRACE "...... ... (SysSemaphore)%s.wait : before pthread_cond_timedwait(0x%x, 0x%x, ×truct) from %s (0x%x)\n", concurrencyInfos.
threadId, concurrencyInfos.
activation, concurrencyInfos.
variableDictionary, concurrencyInfos.
reserveCount, concurrencyInfos.
lock,
semVariable, &(this->semCond), &(this->semMutex), ds, di);
234 result = pthread_cond_timedwait(&(this->
semCond),&(this->
semMutex),×truct);
235 #ifdef CONCURRENCY_DEBUG
240 dbgprintf(
CONCURRENCY_TRACE "...... ... (SysSemaphore)%s.wait : after pthread_cond_timedwait(0x%x, 0x%x, ×truct) from %s (0x%x)\n", concurrencyInfos.
threadId, concurrencyInfos.
activation, concurrencyInfos.
variableDictionary, concurrencyInfos.
reserveCount, concurrencyInfos.
lock,
semVariable, &(this->semCond), &(this->semMutex), ds, di);
244 pthread_mutex_unlock(&(this->
semMutex));
246 return result != ETIMEDOUT;
251 pthread_mutex_lock(&(this->
semMutex));
253 pthread_mutex_unlock(&(this->
semMutex));
288 #if defined( HAVE_PTHREAD_MUTEXATTR_SETTYPE )
289 pthread_mutexattr_t mutexattr;
291 iRC = pthread_mutexattr_init(&mutexattr);
294 #if defined( HAVE_PTHREAD_MUTEX_RECURSIVE_NP )
295 iRC = pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE_NP);
296 #elif defined( HAVE_PTHREAD_MUTEX_RECURSIVE )
297 iRC = pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
298 #elif defined( HAVE_PTHREAD_MUTEX_ERRORCHECK )
299 iRC = pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK);
301 fprintf(stderr,
" *** ERROR: Unknown 2nd argument to pthread_mutexattr_settype()!\n");
306 iRC = pthread_mutex_init(&(this->
mutexMutex), &mutexattr);
310 iRC = pthread_mutexattr_destroy(&mutexattr);
313 iRC = pthread_mutex_init(&(this->
mutexMutex), NULL);
317 fprintf(stderr,
" *** ERROR: At RexxMutex(), pthread_mutex_init - RC = %d !\n", iRC);
#define CONCURRENCY_TRACE
pthread_mutex_t mutexMutex
SysMutex(const char *variable)
const char * mutexVariable
SysSemaphore(const char *variable)
void wait(const char *ds, int di)
static void GetConcurrencyInfos(struct ConcurrencyInfos &concurrencyInfos)
static bool traceConcurrency()
RexxVariableDictionary * variableDictionary
RexxActivation * activation
unsigned short reserveCount
void dbgprintf(const char *format,...)