Back to index

plt-scheme  4.2.1
mzrt.h
Go to the documentation of this file.
00001 #ifndef MZRT_H
00002 #define MZRT_H
00003 
00004 #ifdef MZ_USE_PLACES
00005 
00006 /****************** ATOMIC OPERATIONS ************************************/
00007 /* mzrt_atomic_ops.c */
00008 #ifdef _MSC_VER
00009 typedef unsigned int uint32_t;
00010 #else
00011 # include <stdint.h>
00012 #endif
00013 
00014 MZ_INLINE uint32_t mzrt_atomic_add_32(volatile unsigned int *counter, unsigned int value);
00015 MZ_INLINE uint32_t mzrt_atomic_incr_32(volatile unsigned int *counter);
00016 
00017 
00018 /****************** SIGNAL HANDLING ***************************************/
00019 /* mzrt.c */
00020 void mzrt_set_segfault_debug_handler();
00021 void mzrt_set_user_break_handler(void (*user_break_handler)(int));
00022 
00023 
00024 /****************** PROCESS WEIGHT THREADS ********************************/
00025 /* mzrt_threads.c */
00026 typedef struct mz_proc_thread {
00027 #ifdef WIN32
00028   HANDLE threadid;
00029 #else
00030   pthread_t threadid;
00031 #endif
00032   struct pt_mbox *mbox;
00033 } mz_proc_thread;
00034 
00035 
00036 #ifdef WIN32
00037 typedef DWORD (WINAPI *mz_proc_thread_start)(void*);
00038 #else
00039 typedef void *(mz_proc_thread_start)(void*);
00040 #endif
00041 
00042 mz_proc_thread* mzrt_proc_first_thread_init();
00043 mz_proc_thread* mz_proc_thread_create(mz_proc_thread_start*, void* data);
00044 void *mz_proc_thread_wait(mz_proc_thread *thread);
00045 
00046 void mzrt_sleep(int seconds);
00047 
00048 unsigned int mz_proc_thread_self();
00049 unsigned int mz_proc_thread_id(mz_proc_thread* thread);
00050 
00051 /****************** THREAD RWLOCK ******************************************/
00052 /* mzrt_rwlock_*.c */
00053 typedef struct mzrt_rwlock mzrt_rwlock; /* OPAQUE DEFINITION */
00054 int mzrt_rwlock_create(mzrt_rwlock **lock);
00055 int mzrt_rwlock_rdlock(mzrt_rwlock *lock);
00056 int mzrt_rwlock_wrlock(mzrt_rwlock *lock);
00057 int mzrt_rwlock_tryrdlock(mzrt_rwlock *lock);
00058 int mzrt_rwlock_trywrlock(mzrt_rwlock *lock);
00059 int mzrt_rwlock_unlock(mzrt_rwlock *lock);
00060 int mzrt_rwlock_destroy(mzrt_rwlock *lock);
00061 
00062 /****************** THREAD MUTEX ******************************************/
00063 typedef struct mzrt_mutex mzrt_mutex; /* OPAQUE DEFINITION */
00064 int mzrt_mutex_create(mzrt_mutex **mutex);
00065 int mzrt_mutex_lock(mzrt_mutex *mutex);
00066 int mzrt_mutex_trylock(mzrt_mutex *mutex);
00067 int mzrt_mutex_unlock(mzrt_mutex *mutex);
00068 int mzrt_mutex_destroy(mzrt_mutex *mutex);
00069 
00070 /****************** THREAD COND *******************************************/
00071 typedef struct mzrt_cond mzrt_cond; /* OPAQUE DEFINITION */
00072 int mzrt_cond_create(mzrt_cond **cond);
00073 int mzrt_cond_wait(mzrt_cond *cond, mzrt_mutex *mutex);
00074 int mzrt_cond_timedwait(mzrt_cond *cond, mzrt_mutex *mutex, long seconds, long nanoseconds);
00075 int mzrt_cond_signal(mzrt_cond *cond);
00076 int mzrt_cond_broadcast(mzrt_cond *cond);
00077 int mzrt_cond_destroy(mzrt_cond *cond);
00078 
00079 /****************** PROCESS THREAD MAIL BOX *******************************/
00080 typedef struct pt_mbox_msg {
00081   int     type;
00082   void    *payload;
00083   struct pt_mbox *origin;
00084 } pt_mbox_msg;
00085 
00086 typedef struct pt_mbox {
00087   struct pt_mbox_msg queue[5];
00088   int count;
00089   int in;
00090   int out;
00091   mzrt_mutex *mutex;
00092   mzrt_cond *nonempty;
00093   mzrt_cond *nonfull;
00094 } pt_mbox;
00095 
00096 pt_mbox *pt_mbox_create();
00097 void pt_mbox_send(pt_mbox *mbox, int type, void *payload, pt_mbox *origin);
00098 void pt_mbox_recv(pt_mbox *mbox, int *type, void **payload, pt_mbox **origin);
00099 void pt_mbox_send_recv(pt_mbox *mbox, int type, void *payload, pt_mbox *origin, int *return_type, void **return_payload);
00100 void pt_mbox_destroy(pt_mbox *mbox);
00101 
00102 #endif
00103 
00104 #endif