mthread_thread_t r;
{
/* Compare two thread ids */
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
return(l == r);
}
/* Register procedure proc for execution in a thread. */
mthread_thread_t thread;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (proc == NULL)
return(EINVAL);
* this thread are automatically freed.
*/
mthread_tcb_t *tcb;
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
if (!isokthreadid(detach))
return(ESRCH);
/* Make a thread stop running and store the result value. */
mthread_tcb_t *tcb;
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
tcb = mthread_find_tcb(current_thread);
* threads.
*/
- if (!initialized) {
- no_threads = 0;
- used_threads = 0;
- need_reset = 0;
- running_main_thread = 1;/* mthread_init can only be called from the
- * main thread. Calling it from a thread will
- * not enter this clause.
- */
-
- if (mthread_getcontext(&(mainthread.m_context)) == -1)
- mthread_panic("Couldn't save state for main thread");
- current_thread = MAIN_THREAD;
-
- mthread_init_valid_mutexes();
- mthread_init_valid_conditions();
- mthread_init_valid_attributes();
- mthread_init_keys();
- mthread_init_scheduler();
-
- initialized = 1;
- }
+ if (initialized) return;
+
+ no_threads = 0;
+ used_threads = 0;
+ need_reset = 0;
+ running_main_thread = 1; /* mthread_init can only be called from the
+ * main thread. Calling it from a thread will
+ * not enter this clause.
+ */
+
+ if (mthread_getcontext(&(mainthread.m_context)) == -1)
+ mthread_panic("Couldn't save state for main thread");
+ current_thread = MAIN_THREAD;
+
+ mthread_init_valid_mutexes();
+ mthread_init_valid_conditions();
+ mthread_init_valid_attributes();
+ mthread_init_keys();
+ mthread_init_scheduler();
+
+ initialized = 1;
}
mthread_tcb_t *tcb;
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
if (!isokthreadid(join))
return(ESRCH);
{
/* Run procedure proc just once */
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
if (once == NULL || proc == NULL)
return(EINVAL);
{
/* Return the thread id of the thread calling this function. */
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
return(current_thread);
}
{
/* Invalidate attribute and deallocate resources. */
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
/* Initialize the attribute to a known state. */
struct __mthread_attr *a;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EAGAIN);
/* Get detachstate of a thread attribute */
struct __mthread_attr *a;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
/* Set detachstate of a thread attribute */
struct __mthread_attr *a;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
/* Get stack attribute */
struct __mthread_attr *a;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
/* Get stack size attribute */
struct __mthread_attr *a;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
/* Set stack attribute */
struct __mthread_attr *a;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
/* Set stack size attribute */
struct __mthread_attr *a;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
/* Check to see if attribute is on the list of valid attributes */
struct __mthread_attr *loopitem;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
loopitem = va_front;
/* Return true when no attributes are in use */
struct __mthread_attr *loopitem;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
loopitem = va_front;
mthread_thread_t t;
mthread_tcb_t *tcb;
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
if (cond == NULL)
return(EINVAL);
mthread_thread_t t;
mthread_tcb_t *tcb;
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
if (cond == NULL)
return(EINVAL);
/* Initialize condition variable to a known state. cattr is ignored */
struct __mthread_cond *c;
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
if (cond == NULL)
return(EINVAL);
mthread_thread_t t;
mthread_tcb_t *tcb;
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
if (cond == NULL)
return(EINVAL);
/* Check to see if cond is on the list of valid conditions */
struct __mthread_cond *loopitem;
- mthread_init();
+ MTHREAD_CHECK_INIT();
loopitem = vc_front;
{
/* Return true in case no condition variables are in use. */
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
return(vc_front == NULL);
}
struct __mthread_cond *c;
struct __mthread_mutex *m;
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
if (cond == NULL || mutex == NULL)
return(EINVAL);
*/
mthread_key_t k;
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
keys_used = 1;
/* We do not yet allocate storage space for the values here, because we can
/* Free up a key, as well as any associated storage space.
*/
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
if (key < 0 || key >= MTHREAD_KEYS_MAX || !keys[key].used)
return(EINVAL);
/* Get this thread's local value for the given key. The default is NULL.
*/
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
if (key < 0 || key >= MTHREAD_KEYS_MAX || !keys[key].used)
return(NULL);
*/
void **p;
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
if (key < 0 || key >= MTHREAD_KEYS_MAX || !keys[key].used)
return(EINVAL);
#endif
/*===========================================================================*
- * mthread_init_valid_mutexes *
+ * mthread_init_valid_mutexes *
*===========================================================================*/
void mthread_init_valid_mutexes(void)
{
mthread_thread_t t;
mthread_tcb_t *tcb;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (mutex == NULL)
return(EINVAL);
struct __mthread_mutex *m;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (mutex == NULL)
return(EAGAIN);
struct __mthread_mutex *m;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (mutex == NULL)
return(EINVAL);
struct __mthread_mutex *m;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (mutex == NULL)
return(EINVAL);
struct __mthread_mutex *m;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (mutex == NULL)
return(EINVAL);
/* Check to see if mutex is on the list of valid mutexes */
struct __mthread_mutex *loopitem;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
loopitem = vm_front;
int r = 1;
struct __mthread_mutex *loopitem;
- mthread_init(); /* Make sure mthreads is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
#ifdef MTHREAD_STRICT
loopitem = vm_front;
#ifdef MTHREAD_STRICT
int mthread_mutex_valid(mthread_mutex_t *mutex);
+# define MTHREAD_CHECK_INIT() mthread_init()
#else
# define mthread_mutex_valid(x) ((*x)->mm_magic == MTHREAD_INIT_MAGIC)
+# define MTHREAD_CHECK_INIT()
#endif
#ifdef MDEBUG
mthread_tcb_t *new_tcb, *old_tcb;
ucontext_t *new_ctx, *old_ctx;
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
old_thread = current_thread;
mthread_tcb_t *tcb;
mthread_thread_t t;
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
/* Detached threads cannot clean themselves up. This is a perfect moment to
* do it */
* this function will lead to a deadlock.
*/
- mthread_init(); /* Make sure libmthread is initialized */
+ MTHREAD_CHECK_INIT(); /* Make sure libmthread is initialized */
if (yield_all) mthread_panic("Deadlock: two threads trying to yield_all");
yield_all = 1;