home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1995, NeXT Computer, Inc.
- * All Rights Reserved.
- */
-
- #ifndef __MACHEMUL_CTHREADS_H
- #define __MACHEMUL_CTHREADS_H
-
- #include <mach/mach.h>
- #include <mach/ARCH_INCLUDE.h>
- #include OS_INCLUDE(mach/, cthreads.h)
-
-
-
- typedef any_t (*cthread_fn_t) (any_t arg);
- typedef struct cthread *cthread_t;
-
-
- #ifdef CTHREADS_AVAILABLE
-
- /*
- * Mutex variables
- */
-
- MACHEXPORT mutex_t mutex_alloc (void);
- MACHEXPORT void mutex_free (mutex_t m);
- MACHEXPORT void mutex_init (mutex_t m);
- MACHEXPORT void mutex_clear (mutex_t m);
- MACHEXPORT void mutex_lock (mutex_t m);
- MACHEXPORT void mutex_unlock (mutex_t m);
-
-
-
-
- /*
- * Condition variables
- */
-
- MACHEXPORT condition_t condition_alloc (void);
- MACHEXPORT void condition_free (condition_t c);
- MACHEXPORT void condition_init (condition_t c);
- MACHEXPORT void condition_clear (condition_t c);
- MACHEXPORT void condition_wait (condition_t c, mutex_t m);
- MACHEXPORT int condition_wait_timeout (condition_t c, mutex_t m, double timeout);
- MACHEXPORT void condition_broadcast (condition_t c);
- MACHEXPORT void condition_signal (condition_t c);
-
-
-
-
- /*
- * Threads
- */
-
- typedef struct cthread_callback *cthread_callback_t;
-
- struct cthread {
- native_thread_t thread; // The native thread.
- native_key_t key; // Native key (for thread death)
- cthread_fn_t function; // User function.
- any_t arg; // Arg to the user function.
- any_t status; // Exit status.
- any_t data; // Thread data (cthread_set_data).
- unsigned char main:1; // Main thread?
- unsigned char terminated:1; // Thread terminated?
- unsigned char detached:1; // Thread detached?
- unsigned char joining:1; // Join waiting for termination?
- cthread_callback_t callback; // Thread death callback
- any_t callback_arg; // Callback function argument
- struct mutex lock; // Internal lock.
- struct condition condition; // Internal condition.
- struct cthread *next; // Next thread in list.
- port_t mig_reply_port; // MiG reply port
- };
-
- MACHEXPORT cthread_t cthread_fork (cthread_fn_t function, any_t arg);
- MACHEXPORT void cthread_detach (cthread_t t);
- MACHEXPORT any_t cthread_join (cthread_t t);
- MACHEXPORT void cthread_yield (void);
- MACHEXPORT void cthread_exit (any_t result);
- MACHEXPORT kern_return_t cthread_abort (cthread_t t);
- MACHEXPORT cthread_t cthread_self (void);
- MACHEXPORT native_thread_t *cthread_thread (cthread_t t);
- MACHEXPORT void cthread_set_data (cthread_t t, any_t data);
- MACHEXPORT any_t cthread_data (cthread_t t);
- MACHEXPORT void cthread_set_name (cthread_t t, const char *name);
-
-
- #else CTHREADS_AVAILABLE
-
-
- /*
- * cthreads disabled for the single-threaded version of the library.
- */
-
- #define mutex_alloc() (mutex_t)0x00000004
- #define mutex_free(m)
- #define mutex_init(m)
- #define mutex_clear(m)
- #define mutex_lock(m)
- #define mutex_unlock(m)
-
- #define condition_alloc() (condition_t)0x00000004
- #define condition_free(c)
- #define condition_init(c)
- #define condition_clear(c)
- #define condition_wait(c, m)
- #define condition_wait_timeout(c, m, t) 0
- #define condition_signal(c)
- #define condition_broadcast(c)
-
- #define cthread_fork(f, a) (cthread_t)0
- #define cthread_detach(t)
- #define cthread_join(t) (cthread_t)0
- #define cthread_yield()
- #define cthread_exit(r)
- #define cthread_abort(t) KERN_FAILURE
- #define cthread_self() (cthread_t)0x00000004
- #define cthread_thread (void *)0
-
- extern any_t __cthread_data;
- #define cthread_set_data(t, d) (__cthread_data = (d))
- #define cthread_data(t) (__cthread_data)
-
- #endif CTHREADS_AVAILABLE
-
- #endif __MACHEMUL_CTHREADS_H
-