00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #ifndef LIBC_FIBRIL_SYNCH_H_
00036 #define LIBC_FIBRIL_SYNCH_H_
00037
00038 #include <fibril.h>
00039 #include <adt/list.h>
00040 #include <libarch/tls.h>
00041 #include <sys/time.h>
00042 #include <bool.h>
00043
00044 typedef struct {
00045 fibril_owner_info_t oi;
00046 int counter;
00047 link_t waiters;
00048 } fibril_mutex_t;
00049
00050 #define FIBRIL_MUTEX_INITIALIZER(name) \
00051 { \
00052 .oi = { \
00053 .owned_by = NULL \
00054 }, \
00055 .counter = 1, \
00056 .waiters = { \
00057 .prev = &name.waiters, \
00058 .next = &name.waiters, \
00059 } \
00060 }
00061
00062 #define FIBRIL_MUTEX_INITIALIZE(name) \
00063 fibril_mutex_t name = FIBRIL_MUTEX_INITIALIZER(name)
00064
00065 typedef struct {
00066 fibril_owner_info_t oi;
00067 unsigned writers;
00068 unsigned readers;
00069 link_t waiters;
00070 } fibril_rwlock_t;
00071
00072 #define FIBRIL_RWLOCK_INITIALIZER(name) \
00073 { \
00074 .oi = { \
00075 .owned_by = NULL \
00076 }, \
00077 .readers = 0, \
00078 .writers = 0, \
00079 .waiters = { \
00080 .prev = &name.waiters, \
00081 .next = &name.waiters, \
00082 } \
00083 }
00084
00085 #define FIBRIL_RWLOCK_INITIALIZE(name) \
00086 fibril_rwlock_t name = FIBRIL_RWLOCK_INITIALIZER(name)
00087
00088 typedef struct {
00089 link_t waiters;
00090 } fibril_condvar_t;
00091
00092 #define FIBRIL_CONDVAR_INITIALIZER(name) \
00093 { \
00094 .waiters = { \
00095 .next = &name.waiters, \
00096 .prev = &name.waiters, \
00097 } \
00098 }
00099
00100 #define FIBRIL_CONDVAR_INITIALIZE(name) \
00101 fibril_condvar_t name = FIBRIL_CONDVAR_INITIALIZER(name)
00102
00103 extern void fibril_mutex_initialize(fibril_mutex_t *);
00104 extern void fibril_mutex_lock(fibril_mutex_t *);
00105 extern bool fibril_mutex_trylock(fibril_mutex_t *);
00106 extern void fibril_mutex_unlock(fibril_mutex_t *);
00107 extern bool fibril_mutex_is_locked(fibril_mutex_t *);
00108
00109 extern void fibril_rwlock_initialize(fibril_rwlock_t *);
00110 extern void fibril_rwlock_read_lock(fibril_rwlock_t *);
00111 extern void fibril_rwlock_write_lock(fibril_rwlock_t *);
00112 extern void fibril_rwlock_read_unlock(fibril_rwlock_t *);
00113 extern void fibril_rwlock_write_unlock(fibril_rwlock_t *);
00114 extern bool fibril_rwlock_is_read_locked(fibril_rwlock_t *);
00115 extern bool fibril_rwlock_is_write_locked(fibril_rwlock_t *);
00116 extern bool fibril_rwlock_is_locked(fibril_rwlock_t *);
00117
00118 extern void fibril_condvar_initialize(fibril_condvar_t *);
00119 extern int fibril_condvar_wait_timeout(fibril_condvar_t *, fibril_mutex_t *,
00120 suseconds_t);
00121 extern void fibril_condvar_wait(fibril_condvar_t *, fibril_mutex_t *);
00122 extern void fibril_condvar_signal(fibril_condvar_t *);
00123 extern void fibril_condvar_broadcast(fibril_condvar_t *);
00124
00125 #endif
00126