20 #ifndef OPAL_CONDITION_SPINLOCK_H
21 #define OPAL_CONDITION_SPINLOCK_H
23 #include "opal_config.h"
24 #ifdef HAVE_SYS_TIME_H
30 #if OPAL_HAVE_POSIX_THREADS
32 #elif OPAL_HAVE_SOLARIS_THREADS
51 volatile int c_waiting;
52 volatile int c_signaled;
53 #if OPAL_HAVE_POSIX_THREADS
54 pthread_cond_t c_cond;
55 #elif OPAL_HAVE_SOLARIS_THREADS
70 #if OPAL_ENABLE_DEBUG && !OPAL_ENABLE_MULTI_THREADS
71 if (opal_mutex_check_locks && 0 == m->m_lock_debug) {
\
72 opal_output(0,
"Warning -- mutex not locked in condition_wait"); \
78 #if OPAL_HAVE_POSIX_THREADS && OPAL_ENABLE_MULTI_THREADS
79 rc = pthread_cond_wait(&c->c_cond, &m->m_lock_pthread);
80 #elif OPAL_HAVE_SOLARIS_THREADS && OPAL_ENABLE_MULTI_THREADS
81 rc = cond_wait(&c->c_cond, &m->m_lock_solaris);
87 OPAL_CR_TEST_CHECKPOINT_READY_STALL();
91 while (c->c_signaled == 0) {
94 OPAL_CR_TEST_CHECKPOINT_READY_STALL();
99 while (c->c_signaled == 0) {
101 OPAL_CR_TEST_CHECKPOINT_READY_STALL();
105 #if OPAL_ENABLE_DEBUG && !OPAL_ENABLE_MULTI_THREADS
119 struct timeval absolute;
122 #if OPAL_ENABLE_DEBUG && !OPAL_ENABLE_MULTI_THREADS
123 if (opal_mutex_check_locks && 0 == m->m_lock_debug) {
\
124 opal_output(0,
"Warning -- mutex not locked in condition_wait"); \
131 #if OPAL_HAVE_POSIX_THREADS && OPAL_ENABLE_MULTI_THREADS
132 rc = pthread_cond_timedwait(&c->c_cond, &m->m_lock_pthread, abstime);
133 #elif OPAL_HAVE_SOLARIS_THREADS && OPAL_ENABLE_MULTI_THREADS
136 to.tv_sec = abstime->tv_sec;
137 to.tv_nsec = abstime->tv_nsec;
138 rc = cond_timedwait(&c->c_cond, &m->m_lock_solaris, &to);
140 absolute.tv_sec = abstime->tv_sec;
141 absolute.tv_usec = abstime->tv_nsec * 1000;
142 gettimeofday(&tv,NULL);
143 if (c->c_signaled == 0) {
147 gettimeofday(&tv,NULL);
149 }
while (c->c_signaled == 0 &&
150 (tv.tv_sec <= absolute.tv_sec ||
151 (tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec)));
155 absolute.tv_sec = abstime->tv_sec;
156 absolute.tv_usec = abstime->tv_nsec * 1000;
157 gettimeofday(&tv,NULL);
158 if (c->c_signaled == 0) {
161 gettimeofday(&tv,NULL);
162 }
while (c->c_signaled == 0 &&
163 (tv.tv_sec <= absolute.tv_sec ||
164 (tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec)));
168 #if OPAL_ENABLE_DEBUG && !OPAL_ENABLE_MULTI_THREADS
172 if (c->c_signaled != 0) c->c_signaled--;
181 #if OPAL_HAVE_POSIX_THREADS && OPAL_ENABLE_MULTI_THREADS
183 pthread_cond_signal(&c->c_cond);
185 #elif OPAL_HAVE_SOLARIS_THREADS && OPAL_ENABLE_MULTI_THREADS
187 cond_signal(&c->c_cond);
196 c->c_signaled = c->c_waiting;
197 #if OPAL_HAVE_POSIX_THREADS && OPAL_ENABLE_MULTI_THREADS
199 if( 1 == c->c_waiting ) {
200 pthread_cond_signal(&c->c_cond);
202 pthread_cond_broadcast(&c->c_cond);
205 #elif OPAL_HAVE_SOLARIS_THREADS && OPAL_ENABLE_MULTI_THREADS
207 cond_broadcast(&c->c_cond);
Progress engine for Open MPI.
static void opal_mutex_lock(opal_mutex_t *mutex)
Acquire a mutex.
Definition: condition.h:49
Definition: mutex_unix.h:53
Functions for multi-threaded applications using Libevent.
static void opal_mutex_unlock(opal_mutex_t *mutex)
Release a mutex.
OPAL_DECLSPEC void opal_output(int output_id, const char *format,...) __opal_attribute_format__(__printf__
Main function to send output to a stream.
#define opal_using_threads()
Check and see if the process is using multiple threads.
Definition: mutex.h:157
Base object.
Definition: opal_object.h:182
Definition: ompi_time.h:160
OPAL_DECLSPEC void opal_progress(void)
Progress all pending events.
Definition: opal_progress.c:165
Mutual exclusion functions.
Checkpoint functionality for Open MPI.
#define OBJ_CLASS_DECLARATION(NAME)
Declaration for class descriptor.
Definition: opal_object.h:236