HelenOS sources
This source file includes following definitions.
- fibril_mutex_initialize
#ifndef _LIBC_FIBRIL_SYNCH_H_
#define _LIBC_FIBRIL_SYNCH_H_
#include <fibril.h>
#include <adt/list.h>
#include <time.h>
#include <stdbool.h>
#include <_bits/decls.h>
#ifndef __cplusplus
#define FIBRIL_MUTEX_INITIALIZER(name) \
{ \
.oi = { \
.owned_by = NULL \
}, \
.counter = 1, \
.waiters = LIST_INITIALIZER((name).waiters), \
}
#define FIBRIL_MUTEX_INITIALIZE(name) \
fibril_mutex_t name = FIBRIL_MUTEX_INITIALIZER(name)
#define FIBRIL_RWLOCK_INITIALIZER(name) \
{ \
.oi = { \
.owned_by = NULL \
}, \
.readers = 0, \
.writers = 0, \
.waiters = LIST_INITIALIZER((name).waiters), \
}
#define FIBRIL_RWLOCK_INITIALIZE(name) \
fibril_rwlock_t name = FIBRIL_RWLOCK_INITIALIZER(name)
#define FIBRIL_CONDVAR_INITIALIZER(name) \
{ \
.waiters = LIST_INITIALIZER((name).waiters), \
}
#define FIBRIL_CONDVAR_INITIALIZE(name) \
fibril_condvar_t name = FIBRIL_CONDVAR_INITIALIZER(name)
#define FIBRIL_SEMAPHORE_INITIALIZER(name, cnt) \
{ \
.count = (cnt), \
.waiters = LIST_INITIALIZER((name).waiters), \
}
#define FIBRIL_SEMAPHORE_INITIALIZE(name, cnt) \
fibril_semaphore_t name = FIBRIL_SEMAPHORE_INITIALIZER(name, cnt)
#endif
__HELENOS_DECLS_BEGIN;
typedef struct {
fibril_owner_info_t oi;
int counter;
list_t waiters;
} fibril_mutex_t;
typedef struct {
fibril_owner_info_t oi;
unsigned int writers;
unsigned int readers;
list_t waiters;
} fibril_rwlock_t;
typedef struct {
list_t waiters;
} fibril_condvar_t;
typedef void (*fibril_timer_fun_t)(void *);
typedef enum {
fts_not_set,
fts_active,
fts_fired,
fts_cleanup,
fts_clean
} fibril_timer_state_t;
typedef struct {
fibril_mutex_t lock;
fibril_mutex_t *lockp;
fibril_condvar_t cv;
fid_t fibril;
fibril_timer_state_t state;
fid_t handler_fid;
usec_t delay;
fibril_timer_fun_t fun;
void *arg;
} fibril_timer_t;
typedef struct {
long int count;
list_t waiters;
bool closed;
} fibril_semaphore_t;
extern void __fibril_synch_init(void);
extern void __fibril_synch_fini(void);
static inline __CONSTEXPR void fibril_mutex_initialize(fibril_mutex_t *fm)
{
fm->oi.owned_by = NULL;
fm->counter = 1;
list_initialize(&fm->waiters);
}
extern void fibril_mutex_lock(fibril_mutex_t *);
extern bool fibril_mutex_trylock(fibril_mutex_t *);
extern void fibril_mutex_unlock(fibril_mutex_t *);
extern bool fibril_mutex_is_locked(fibril_mutex_t *);
extern void fibril_rwlock_initialize(fibril_rwlock_t *);
extern void fibril_rwlock_read_lock(fibril_rwlock_t *);
extern void fibril_rwlock_write_lock(fibril_rwlock_t *);
extern void fibril_rwlock_read_unlock(fibril_rwlock_t *);
extern void fibril_rwlock_write_unlock(fibril_rwlock_t *);
extern bool fibril_rwlock_is_read_locked(fibril_rwlock_t *);
extern bool fibril_rwlock_is_write_locked(fibril_rwlock_t *);
extern bool fibril_rwlock_is_locked(fibril_rwlock_t *);
extern void fibril_condvar_initialize(fibril_condvar_t *);
extern errno_t fibril_condvar_wait_timeout(fibril_condvar_t *, fibril_mutex_t *,
usec_t);
extern void fibril_condvar_wait(fibril_condvar_t *, fibril_mutex_t *);
extern void fibril_condvar_signal(fibril_condvar_t *);
extern void fibril_condvar_broadcast(fibril_condvar_t *);
extern fibril_timer_t *fibril_timer_create(fibril_mutex_t *);
extern void fibril_timer_destroy(fibril_timer_t *);
extern void fibril_timer_set(fibril_timer_t *, usec_t, fibril_timer_fun_t,
void *);
extern void fibril_timer_set_locked(fibril_timer_t *, usec_t,
fibril_timer_fun_t, void *);
extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *);
extern fibril_timer_state_t fibril_timer_clear_locked(fibril_timer_t *);
extern void fibril_semaphore_initialize(fibril_semaphore_t *, long);
extern void fibril_semaphore_up(fibril_semaphore_t *);
extern void fibril_semaphore_down(fibril_semaphore_t *);
extern errno_t fibril_semaphore_down_timeout(fibril_semaphore_t *, usec_t);
extern void fibril_semaphore_close(fibril_semaphore_t *);
typedef struct mpsc mpsc_t;
extern mpsc_t *mpsc_create(size_t);
extern void mpsc_destroy(mpsc_t *);
extern errno_t mpsc_send(mpsc_t *, const void *);
extern errno_t mpsc_receive(mpsc_t *, void *, const struct timespec *);
extern void mpsc_close(mpsc_t *);
__HELENOS_DECLS_END;
#endif
HelenOS homepage, sources at GitHub