Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2105 → Rev 2106

/trunk/kernel/generic/include/synch/futex.h
42,14 → 42,19
 
/** Kernel-side futex structure. */
typedef struct {
uintptr_t paddr; /**< Physical address of the status variable. */
waitq_t wq; /**< Wait queue for threads waiting for futex availability. */
link_t ht_link; /**< Futex hash table link. */
count_t refcount; /**< Number of tasks that reference this futex. */
/** Physical address of the status variable. */
uintptr_t paddr;
/** Wait queue for threads waiting for futex availability. */
waitq_t wq;
/** Futex hash table link. */
link_t ht_link;
/** Number of tasks that reference this futex. */
count_t refcount;
} futex_t;
 
extern void futex_init(void);
extern unative_t sys_futex_sleep_timeout(uintptr_t uaddr, uint32_t usec, int flags);
extern unative_t sys_futex_sleep_timeout(uintptr_t uaddr, uint32_t usec,
int flags);
extern unative_t sys_futex_wakeup(uintptr_t uaddr);
 
extern void futex_cleanup(void);
/trunk/kernel/generic/include/synch/condvar.h
44,15 → 44,16
waitq_t wq;
} condvar_t;
 
#define condvar_wait(cv,mtx) \
_condvar_wait_timeout((cv),(mtx),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
#define condvar_wait_timeout(cv,mtx,usec) \
_condvar_wait_timeout((cv),(mtx),(usec),SYNCH_FLAGS_NONE)
#define condvar_wait(cv, mtx) \
_condvar_wait_timeout((cv), (mtx), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
#define condvar_wait_timeout(cv, mtx, usec) \
_condvar_wait_timeout((cv), (mtx), (usec), SYNCH_FLAGS_NONE)
 
extern void condvar_initialize(condvar_t *cv);
extern void condvar_signal(condvar_t *cv);
extern void condvar_broadcast(condvar_t *cv);
extern int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec, int flags);
extern int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec,
int flags);
 
#endif
 
/trunk/kernel/generic/include/synch/rwlock.h
48,22 → 48,28
 
typedef struct {
SPINLOCK_DECLARE(lock);
mutex_t exclusive; /**< Mutex for writers, readers can bypass it if readers_in is positive. */
count_t readers_in; /**< Number of readers in critical section. */
/**
* Mutex for writers, readers can bypass it if readers_in is positive.
*/
mutex_t exclusive;
/** Number of readers in critical section. */
count_t readers_in;
} rwlock_t;
 
#define rwlock_write_lock(rwl) \
_rwlock_write_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
_rwlock_write_lock_timeout((rwl), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
#define rwlock_read_lock(rwl) \
_rwlock_read_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
_rwlock_read_lock_timeout((rwl), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
#define rwlock_write_trylock(rwl) \
_rwlock_write_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
_rwlock_write_lock_timeout((rwl), SYNCH_NO_TIMEOUT, \
SYNCH_FLAGS_NON_BLOCKING)
#define rwlock_read_trylock(rwl) \
_rwlock_read_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
#define rwlock_write_lock_timeout(rwl,usec) \
_rwlock_write_lock_timeout((rwl),(usec),SYNCH_FLAGS_NONE)
#define rwlock_read_lock_timeout(rwl,usec) \
_rwlock_read_lock_timeout((rwl),(usec),SYNCH_FLAGS_NONE)
_rwlock_read_lock_timeout((rwl), SYNCH_NO_TIMEOUT, \
SYNCH_FLAGS_NON_BLOCKING)
#define rwlock_write_lock_timeout(rwl, usec) \
_rwlock_write_lock_timeout((rwl), (usec), SYNCH_FLAGS_NONE)
#define rwlock_read_lock_timeout(rwl, usec) \
_rwlock_read_lock_timeout((rwl), (usec), SYNCH_FLAGS_NONE)
 
extern void rwlock_initialize(rwlock_t *rwl);
extern void rwlock_read_unlock(rwlock_t *rwl);
/trunk/kernel/generic/include/synch/semaphore.h
46,7 → 46,7
#define semaphore_down(s) \
_semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
#define semaphore_trydown(s) \
_semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING)
_semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING)
#define semaphore_down_timeout(s, usec) \
_semaphore_down_timeout((s), (usec), SYNCH_FLAGS_NONE)
 
/trunk/kernel/generic/include/synch/synch.h
35,20 → 35,31
#ifndef KERN_SYNCH_H_
#define KERN_SYNCH_H_
 
#define SYNCH_NO_TIMEOUT 0 /**< Request with no timeout. */
/** Request with no timeout. */
#define SYNCH_NO_TIMEOUT 0
 
#define SYNCH_FLAGS_NONE 0 /**< No flags specified. */
#define SYNCH_FLAGS_NON_BLOCKING (1<<0) /**< Non-blocking operation request. */
#define SYNCH_FLAGS_INTERRUPTIBLE (1<<1) /**< Interruptible operation. */
/** No flags specified. */
#define SYNCH_FLAGS_NONE 0
/** Non-blocking operation request. */
#define SYNCH_FLAGS_NON_BLOCKING (1 << 0)
/** Interruptible operation. */
#define SYNCH_FLAGS_INTERRUPTIBLE (1 << 1)
 
#define ESYNCH_WOULD_BLOCK 1 /**< Could not satisfy the request without going to sleep. */
#define ESYNCH_TIMEOUT 2 /**< Timeout occurred. */
#define ESYNCH_INTERRUPTED 4 /**< Sleep was interrupted. */
#define ESYNCH_OK_ATOMIC 8 /**< Operation succeeded without sleeping. */
#define ESYNCH_OK_BLOCKED 16 /**< Operation succeeded and did sleep. */
/** Could not satisfy the request without going to sleep. */
#define ESYNCH_WOULD_BLOCK 1
/** Timeout occurred. */
#define ESYNCH_TIMEOUT 2
/** Sleep was interrupted. */
#define ESYNCH_INTERRUPTED 4
/** Operation succeeded without sleeping. */
#define ESYNCH_OK_ATOMIC 8
/** Operation succeeded and did sleep. */
#define ESYNCH_OK_BLOCKED 16
 
#define SYNCH_FAILED(rc) ((rc) & (ESYNCH_WOULD_BLOCK | ESYNCH_TIMEOUT | ESYNCH_INTERRUPTED))
#define SYNCH_OK(rc) ((rc) & (ESYNCH_OK_ATOMIC | ESYNCH_OK_BLOCKED))
#define SYNCH_FAILED(rc) \
((rc) & (ESYNCH_WOULD_BLOCK | ESYNCH_TIMEOUT | ESYNCH_INTERRUPTED))
#define SYNCH_OK(rc) \
((rc) & (ESYNCH_OK_ATOMIC | ESYNCH_OK_BLOCKED))
 
#endif
 
/trunk/kernel/generic/include/synch/waitq.h
52,8 → 52,12
*/
SPINLOCK_DECLARE(lock);
 
int missed_wakeups; /**< Number of waitq_wakeup() calls that didn't find a thread to wake up. */
link_t head; /**< List of sleeping threads for wich there was no missed_wakeup. */
/**
* Number of waitq_wakeup() calls that didn't find a thread to wake up.
*/
int missed_wakeups;
/** List of sleeping threads for wich there was no missed_wakeup. */
link_t head;
} waitq_t;
 
#define waitq_sleep(wq) \