Synchronization


Files

file  condvar.h
file  futex.h
file  mutex.h
file  rwlock.h
file  semaphore.h
file  spinlock.h
file  synch.h
file  waitq.h
file  condvar.c
 Condition variables.
file  futex.c
 Kernel backend for futexes.
file  mutex.c
 Mutexes.
file  rwlock.c
 Reader/Writer locks.
file  semaphore.c
 Semaphores.
file  spinlock.c
 Spinlocks.
file  waitq.c
 Wait queue.

Data Structures

struct  condvar
struct  futex
struct  mutex
struct  rwlock
struct  semaphore
struct  spinlock
struct  waitq

Defines

#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 mutex_lock(mtx)   _mutex_lock_timeout((mtx),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
#define mutex_trylock(mtx)   _mutex_lock_timeout((mtx),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
#define mutex_lock_timeout(mtx, usec)   _mutex_lock_timeout((mtx),(usec),SYNCH_FLAGS_NON_BLOCKING)
#define mutex_lock_active(mtx)   while (mutex_trylock((mtx)) != ESYNCH_OK_ATOMIC)
#define rwlock_write_lock(rwl)   _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)
#define rwlock_write_trylock(rwl)   _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)
#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)
#define semaphore_down_timeout(s, usec)   _semaphore_down_timeout((s),(usec),SYNCH_FLAGS_NONE)
#define SPINLOCK_DECLARE(slname)   spinlock_t slname
#define SPINLOCK_INITIALIZE(slname)
#define spinlock_lock(x)   atomic_lock_arch(&(x)->val)
#define SYNCH_NO_TIMEOUT   0
#define SYNCH_FLAGS_NONE   0
#define SYNCH_FLAGS_NON_BLOCKING   (1<<0)
#define SYNCH_FLAGS_INTERRUPTIBLE   (1<<1)
#define ESYNCH_WOULD_BLOCK   1
#define ESYNCH_TIMEOUT   2
#define ESYNCH_INTERRUPTED   4
#define ESYNCH_OK_ATOMIC   8
#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 WAKEUP_FIRST   0
#define WAKEUP_ALL   1
#define waitq_sleep(wq)   waitq_sleep_timeout((wq),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
#define FUTEX_HT_SIZE   1024
#define ALLOW_ALL   0
#define ALLOW_READERS_ONLY   1

Enumerations

enum  rwlock_type { RWLOCK_NONE, RWLOCK_READER, RWLOCK_WRITER }

Functions

void condvar_initialize (condvar_t *cv)
void condvar_signal (condvar_t *cv)
void condvar_broadcast (condvar_t *cv)
int _condvar_wait_timeout (condvar_t *cv, mutex_t *mtx, __u32 usec, int flags)
void futex_init (void)
__native sys_futex_sleep_timeout (__address uaddr, __u32 usec, int flags)
__native sys_futex_wakeup (__address uaddr)
void futex_cleanup (void)
void mutex_initialize (mutex_t *mtx)
int _mutex_lock_timeout (mutex_t *mtx, __u32 usec, int flags)
void mutex_unlock (mutex_t *mtx)
void rwlock_initialize (rwlock_t *rwl)
void rwlock_read_unlock (rwlock_t *rwl)
void rwlock_write_unlock (rwlock_t *rwl)
int _rwlock_read_lock_timeout (rwlock_t *rwl, __u32 usec, int flags)
int _rwlock_write_lock_timeout (rwlock_t *rwl, __u32 usec, int flags)
void semaphore_initialize (semaphore_t *s, int val)
int _semaphore_down_timeout (semaphore_t *s, __u32 usec, int flags)
void semaphore_up (semaphore_t *s)
void spinlock_initialize (spinlock_t *sl, char *name)
int spinlock_trylock (spinlock_t *sl)
void spinlock_lock_debug (spinlock_t *sl)
static void spinlock_unlock (spinlock_t *sl)
void waitq_initialize (waitq_t *wq)
int waitq_sleep_timeout (waitq_t *wq, __u32 usec, int flags)
ipl_t waitq_sleep_prepare (waitq_t *wq)
int waitq_sleep_timeout_unsafe (waitq_t *wq, __u32 usec, int flags)
void waitq_sleep_finish (waitq_t *wq, int rc, ipl_t ipl)
void waitq_wakeup (waitq_t *wq, bool all)
void _waitq_wakeup_unsafe (waitq_t *wq, bool all)
void waitq_interrupt_sleep (thread_t *t)
static void futex_initialize (futex_t *futex)
static futex_tfutex_find (__address paddr)
static index_t futex_ht_hash (__native *key)
static bool futex_ht_compare (__native *key, count_t keys, link_t *item)
static void futex_ht_remove_callback (link_t *item)
static void let_others_in (rwlock_t *rwl, int readers_only)
static void release_spinlock (void *arg)
static void waitq_timeouted_sleep (void *data)

Variables

static rwlock_t futex_ht_lock
static hash_table_t futex_ht
static hash_table_operations_t futex_ht_ops

Define Documentation

#define ALLOW_ALL   0
 

Definition at line 71 of file rwlock.c.

Referenced by rwlock_read_unlock(), and rwlock_write_unlock().

#define ALLOW_READERS_ONLY   1
 

Definition at line 72 of file rwlock.c.

Referenced by _rwlock_write_lock_timeout().

#define condvar_wait cv,
mtx   )     _condvar_wait_timeout((cv),(mtx),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
 

Definition at line 47 of file condvar.h.

#define condvar_wait_timeout cv,
mtx,
usec   )     _condvar_wait_timeout((cv),(mtx),(usec),SYNCH_FLAGS_NONE)
 

Definition at line 49 of file condvar.h.

#define ESYNCH_INTERRUPTED   4
 

Sleep was interrupted.

Definition at line 46 of file synch.h.

Referenced by _rwlock_read_lock_timeout(), and waitq_sleep_timeout_unsafe().

#define ESYNCH_OK_ATOMIC   8
 

Operation succeeded without sleeping.

Definition at line 47 of file synch.h.

Referenced by _rwlock_read_lock_timeout(), waitq_sleep_finish(), and waitq_sleep_timeout_unsafe().

#define ESYNCH_OK_BLOCKED   16
 

Operation succeeded and did sleep.

Definition at line 48 of file synch.h.

Referenced by _rwlock_read_lock_timeout(), and waitq_sleep_timeout_unsafe().

#define ESYNCH_TIMEOUT   2
 

Timeout occurred.

Definition at line 45 of file synch.h.

Referenced by _rwlock_read_lock_timeout(), ktaskgc(), and waitq_sleep_timeout_unsafe().

#define ESYNCH_WOULD_BLOCK   1
 

Could not satisfy the request without going to sleep.

Definition at line 44 of file synch.h.

Referenced by _rwlock_read_lock_timeout(), waitq_sleep_finish(), and waitq_sleep_timeout_unsafe().

#define FUTEX_HT_SIZE   1024
 

Definition at line 57 of file futex.c.

Referenced by futex_ht_hash(), and futex_init().

#define mutex_lock mtx   )     _mutex_lock_timeout((mtx),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
 

Definition at line 47 of file mutex.h.

Referenced by _condvar_wait_timeout(), anon_page_fault(), anon_share(), as_area_create(), as_area_destroy(), as_area_resize(), as_area_share(), as_page_fault(), check_area_conflicts(), elf_page_fault(), elf_share(), find_area_and_lock(), futex_cleanup(), futex_find(), pt_lock(), ptl0_create(), sh_info_remove_reference(), and task_create().

#define mutex_lock_active mtx   )     while (mutex_trylock((mtx)) != ESYNCH_OK_ATOMIC)
 

Definition at line 53 of file mutex.h.

Referenced by as_switch(), asid_get(), and task_destroy().

#define mutex_lock_timeout mtx,
usec   )     _mutex_lock_timeout((mtx),(usec),SYNCH_FLAGS_NON_BLOCKING)
 

Definition at line 51 of file mutex.h.

#define mutex_trylock mtx   )     _mutex_lock_timeout((mtx),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
 

Definition at line 49 of file mutex.h.

Referenced by _rwlock_read_lock_timeout().

#define rwlock_read_lock rwl   )     _rwlock_read_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
 

Definition at line 58 of file rwlock.h.

Referenced by futex_find().

#define rwlock_read_lock_timeout rwl,
usec   )     _rwlock_read_lock_timeout((rwl),(usec),SYNCH_FLAGS_NONE)
 

Definition at line 66 of file rwlock.h.

#define rwlock_read_trylock rwl   )     _rwlock_read_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
 

Definition at line 62 of file rwlock.h.

#define rwlock_write_lock rwl   )     _rwlock_write_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
 

Definition at line 56 of file rwlock.h.

Referenced by futex_cleanup(), and futex_find().

#define rwlock_write_lock_timeout rwl,
usec   )     _rwlock_write_lock_timeout((rwl),(usec),SYNCH_FLAGS_NONE)
 

Definition at line 64 of file rwlock.h.

#define rwlock_write_trylock rwl   )     _rwlock_write_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
 

Definition at line 60 of file rwlock.h.

#define semaphore_down  )     _semaphore_down_timeout((s),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
 

Definition at line 48 of file semaphore.h.

#define semaphore_down_timeout s,
usec   )     _semaphore_down_timeout((s),(usec),SYNCH_FLAGS_NONE)
 

Definition at line 52 of file semaphore.h.

#define semaphore_trydown  )     _semaphore_down_timeout((s),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
 

Definition at line 50 of file semaphore.h.

#define SPINLOCK_DECLARE slname   )     spinlock_t slname
 

Definition at line 56 of file spinlock.h.

#define SPINLOCK_INITIALIZE slname   ) 
 

Value:

spinlock_t slname = {           \
                .val = { 0 }            \
        }

Definition at line 69 of file spinlock.h.

#define spinlock_lock  )     atomic_lock_arch(&(x)->val)
 

Definition at line 82 of file spinlock.h.

Referenced by _getc(), _ipc_answer_free_call(), _ipc_call(), _rwlock_read_lock_timeout(), _rwlock_write_lock_timeout(), _slab_cache_create(), _slab_reclaim(), _waitq_wakeup_unsafe(), answer_preprocess(), as_destroy(), as_install_arch(), as_switch(), asid_get(), asid_put(), cap_get(), cap_set(), chardev_push_character(), clock(), cmd_desc(), cmd_help(), cmd_register(), cmdtab_search_one(), ddi_iospace_enable(), ddi_physmem_map(), exc_print_cmd(), exc_register(), fb_putchar(), find_best_thread(), find_free_zone_lock(), find_zone_and_lock(), get_call(), get_mag_from_cache(), ipc_answer(), ipc_call(), ipc_cleanup(), ipc_forward(), ipc_irq_cleanup(), ipc_irq_register(), ipc_irq_send_msg(), ipc_irq_send_notif(), ipc_irq_unregister(), ipc_phone_connect(), ipc_phone_hangup(), ipc_print_task(), ipc_wait_for_call(), kcpulb(), kinit(), klog_vprintf(), ktaskclnp(), ktaskgc(), let_others_in(), magazine_obj_get(), magazine_obj_put(), parse_cmdline(), phone_alloc(), printf_core(), put_mag_to_cache(), relink_rq(), rwlock_read_unlock(), rwlock_write_unlock(), sched_print_list(), scheduler(), scheduler_separated_stack(), semaphore_initialize(), send_call(), slab_cache_destroy(), slab_enable_cpucache(), slab_obj_create(), slab_obj_destroy(), slab_print_list(), slab_reclaim(), sys_cap_grant(), sys_cap_revoke(), task_create(), task_kill(), task_print_list(), thread_create(), thread_destroy(), thread_detach(), thread_exit(), thread_join_timeout(), thread_print_list(), thread_ready(), thread_register_call_me(), timeout_register(), timeout_unregister(), tlb_shootdown_ipi_recv(), tlb_shootdown_start(), waitq_interrupt_sleep(), waitq_sleep_prepare(), waitq_sleep_timeout_unsafe(), waitq_timeouted_sleep(), waitq_wakeup(), zone_merge(), zone_print_list(), zone_print_one(), and zones_add_zone().

#define SYNCH_FAILED rc   )     ((rc) & (ESYNCH_WOULD_BLOCK | ESYNCH_TIMEOUT | ESYNCH_INTERRUPTED))
 

Definition at line 50 of file synch.h.

Referenced by _rwlock_read_lock_timeout(), _rwlock_write_lock_timeout(), and ipc_wait_for_call().

#define SYNCH_FLAGS_INTERRUPTIBLE   (1<<1)
 

Interruptible operation.

Definition at line 42 of file synch.h.

Referenced by sys_futex_sleep_timeout(), sys_ipc_wait_for_call(), and waitq_sleep_timeout_unsafe().

#define SYNCH_FLAGS_NON_BLOCKING   (1<<0)
 

Non-blocking operation request.

Definition at line 41 of file synch.h.

Referenced by thread_usleep(), and waitq_sleep_timeout_unsafe().

#define SYNCH_FLAGS_NONE   0
 

No flags specified.

Definition at line 40 of file synch.h.

Referenced by ipc_call_sync(), and ktaskgc().

#define SYNCH_NO_TIMEOUT   0
 

Request with no timeout.

Definition at line 38 of file synch.h.

Referenced by ipc_call_sync().

#define SYNCH_OK rc   )     ((rc) & (ESYNCH_OK_ATOMIC | ESYNCH_OK_BLOCKED))
 

Definition at line 51 of file synch.h.

#define waitq_sleep wq   )     waitq_sleep_timeout((wq),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
 

Definition at line 60 of file waitq.h.

Referenced by _getc().

#define WAKEUP_ALL   1
 

Definition at line 45 of file waitq.h.

Referenced by condvar_broadcast().

#define WAKEUP_FIRST   0
 

Definition at line 44 of file waitq.h.

Referenced by chardev_push_character(), condvar_signal(), let_others_in(), main_ap_separated_stack(), semaphore_up(), and sys_futex_wakeup().


Enumeration Type Documentation

enum rwlock_type
 

Enumerator:
RWLOCK_NONE 
RWLOCK_READER 
RWLOCK_WRITER 

Definition at line 44 of file rwlock.h.


Function Documentation

int _condvar_wait_timeout condvar_t cv,
mutex_t mtx,
__u32  usec,
int  flags
 

Wait for the condition becoming true.

Parameters:
cv Condition variable.
mtx Mutex.
usec Timeout value in microseconds.
flags Select mode of operation.
For exact description of meaning of possible combinations of usec and flags, see comment for waitq_sleep_timeout(). Note that when SYNCH_FLAGS_NON_BLOCKING is specified here, ESYNCH_WOULD_BLOCK is always returned.

Returns:
See comment for waitq_sleep_timeout().

Definition at line 90 of file condvar.c.

References waitq::missed_wakeups, mutex_lock, mutex_unlock(), waitq_sleep_finish(), waitq_sleep_prepare(), waitq_sleep_timeout_unsafe(), and condvar::wq.

Here is the call graph for this function:

int _mutex_lock_timeout mutex_t mtx,
__u32  usec,
int  flags
 

Acquire mutex

Acquire mutex. Timeout mode and non-blocking mode can be requested.

Parameters:
mtx Mutex.
usec Timeout in microseconds.
flags Specify mode of operation.
For exact description of possible combinations of usec and flags, see comment for waitq_sleep_timeout().

Returns:
See comment for waitq_sleep_timeout().

Definition at line 67 of file mutex.c.

References _semaphore_down_timeout(), and mutex::sem.

Referenced by _rwlock_read_lock_timeout(), and _rwlock_write_lock_timeout().

Here is the call graph for this function:

int _rwlock_read_lock_timeout rwlock_t rwl,
__u32  usec,
int  flags
 

Acquire reader/writer lock for writing

Acquire reader/writer lock for writing. Timeout and willingness to block may be specified.

Parameters:
rwl Reader/Writer lock.
usec Timeout in microseconds.
flags Select mode of operation.
For exact description of possible combinations of usec and flags, see comment for waitq_sleep_timeout().

Returns:
See comment for waitq_sleep_timeout().

Definition at line 157 of file rwlock.c.

References _mutex_lock_timeout(), ESYNCH_INTERRUPTED, ESYNCH_OK_ATOMIC, ESYNCH_OK_BLOCKED, ESYNCH_TIMEOUT, ESYNCH_WOULD_BLOCK, rwlock::exclusive, waitq::head, interrupts_disable(), interrupts_restore(), list_empty(), mutex_trylock, NULL, panic, rwlock::readers_in, release_spinlock(), RWLOCK_READER, mutex::sem, spinlock_lock, spinlock_unlock(), SYNCH_FAILED, THREAD, thread_register_call_me(), and semaphore::wq.

Here is the call graph for this function:

int _rwlock_write_lock_timeout rwlock_t rwl,
__u32  usec,
int  flags
 

Acquire reader/writer lock for reading

Acquire reader/writer lock for reading. Timeout and willingness to block may be specified.

Parameters:
rwl Reader/Writer lock.
usec Timeout in microseconds.
flags Specify mode of operation.
For exact description of possible combinations of usec and flags, see comment for waitq_sleep_timeout().

Returns:
See comment for waitq_sleep_timeout().

Definition at line 103 of file rwlock.c.

References _mutex_lock_timeout(), ALLOW_READERS_ONLY, rwlock::exclusive, interrupts_disable(), interrupts_restore(), let_others_in(), rwlock::readers_in, RWLOCK_WRITER, spinlock_lock, spinlock_unlock(), SYNCH_FAILED, and THREAD.

Here is the call graph for this function:

int _semaphore_down_timeout semaphore_t s,
__u32  usec,
int  flags
 

Semaphore down

Semaphore down. Conditional mode and mode with timeout can be requested.

Parameters:
s Semaphore.
usec Timeout in microseconds.
flags Select mode of operation.
For exact description of possible combinations of usec and flags, see comment for waitq_sleep_timeout().

Returns:
See comment for waitq_sleep_timeout().

Definition at line 81 of file semaphore.c.

References waitq_sleep_timeout(), and semaphore::wq.

Referenced by _mutex_lock_timeout().

Here is the call graph for this function:

void _waitq_wakeup_unsafe waitq_t wq,
bool  all
 

Internal SMP- and IRQ-unsafe version of waitq_wakeup()

This is the internal SMP- and IRQ-unsafe version of waitq_wakeup(). It assumes wq->lock is already locked and interrupts are already disabled.

Parameters:
wq Pointer to wait queue.
all If this is non-zero, all sleeping threads will be woken up and missed count will be zeroed.

Definition at line 409 of file waitq.c.

References waitq::head, list_empty(), list_get_instance, list_remove(), waitq::missed_wakeups, link::next, NULL, thread::sleep_queue, thread::sleep_timeout, spinlock_lock, spinlock_unlock(), thread_ready(), thread::timeout_pending, timeout_unregister(), and thread::wq_link.

Referenced by let_others_in(), scheduler_separated_stack(), and waitq_wakeup().

Here is the call graph for this function:

void condvar_broadcast condvar_t cv  ) 
 

Signal the condition has become true to all waiting threads by waking them up.

Parameters:
cv Condition variable.

Definition at line 71 of file condvar.c.

References waitq_wakeup(), WAKEUP_ALL, and condvar::wq.

Here is the call graph for this function:

void condvar_initialize condvar_t cv  ) 
 

Initialize condition variable.

Parameters:
cv Condition variable.

Definition at line 49 of file condvar.c.

References waitq_initialize(), and condvar::wq.

Here is the call graph for this function:

void condvar_signal condvar_t cv  ) 
 

Signal the condition has become true to the first waiting thread by waking it up.

Parameters:
cv Condition variable.

Definition at line 60 of file condvar.c.

References waitq_wakeup(), WAKEUP_FIRST, and condvar::wq.

Here is the call graph for this function:

void futex_cleanup void   ) 
 

Remove references from futexes known to the current task.

Definition at line 312 of file futex.c.

References futex_ht, futex_ht_lock, hash_table_remove(), btree_node::key, btree_node::keys, list_get_instance, mutex_lock, link::next, rwlock_write_lock, TASK, and btree_node::value.

Referenced by ktaskclnp().

Here is the call graph for this function:

futex_t * futex_find __address  paddr  )  [static]
 

Find kernel address of the futex structure corresponding to paddr.

If the structure does not exist already, a new one is created.

Parameters:
paddr Physical address of the userspace futex counter.
Returns:
Address of the kernel futex structure.

Definition at line 185 of file futex.c.

References btree_insert(), btree_search(), futex_ht, futex_ht_lock, futex_initialize(), hash_table_find(), hash_table_get_instance, hash_table_insert(), futex::ht_link, malloc(), mutex_lock, mutex_unlock(), NULL, futex::paddr, futex::refcount, rwlock_read_lock, rwlock_read_unlock(), rwlock_write_lock, rwlock_write_unlock(), and TASK.

Referenced by sys_futex_sleep_timeout(), and sys_futex_wakeup().

Here is the call graph for this function:

bool futex_ht_compare __native key,
count_t  keys,
link_t item
[static]
 

Compare futex hash table item with a key.

Parameters:
key Address where the key (i.e. physical address of futex counter) is stored.
Returns:
True if the item matches the key. False otherwise.

Definition at line 289 of file futex.c.

References ASSERT, hash_table_get_instance, and futex::paddr.

index_t futex_ht_hash __native key  )  [static]
 

Compute hash index into futex hash table.

Parameters:
key Address where the key (i.e. physical address of futex counter) is stored.
Returns:
Index into futex hash table.

Definition at line 278 of file futex.c.

References FUTEX_HT_SIZE.

void futex_ht_remove_callback link_t item  )  [static]
 

Callback for removal items from futex hash table.

Parameters:
item Item removed from the hash table.

Definition at line 303 of file futex.c.

References free(), and hash_table_get_instance.

Here is the call graph for this function:

void futex_init void   ) 
 

Initialize futex subsystem.

Definition at line 84 of file futex.c.

References futex_ht, futex_ht_lock, futex_ht_ops, FUTEX_HT_SIZE, hash_table_create(), and rwlock_initialize().

Referenced by main_bsp_separated_stack().

Here is the call graph for this function:

void futex_initialize futex_t futex  )  [static]
 

Initialize kernel futex structure.

Parameters:
futex Kernel futex structure.

Definition at line 94 of file futex.c.

References futex::ht_link, link_initialize(), futex::paddr, futex::refcount, waitq_initialize(), and futex::wq.

Referenced by futex_find().

Here is the call graph for this function:

void let_others_in rwlock_t rwl,
int  readers_only
[static]
 

Direct handoff of reader/writer lock ownership.

Direct handoff of reader/writer lock ownership to waiting readers or a writer.

Must be called with rwl->lock locked. Must be called with interrupts_disable()'d.

Parameters:
rwl Reader/Writer lock.
readers_only See the description below.
If readers_only is false: (unlock scenario) Let the first sleeper on 'exclusive' mutex in, no matter whether it is a reader or a writer. If there are more leading readers in line, let each of them in.

Otherwise: (timeout scenario) Let all leading readers in.

Definition at line 316 of file rwlock.c.

References _waitq_wakeup_unsafe(), rwlock::exclusive, waitq::head, list_empty(), list_get_instance, link::next, NULL, rwlock::readers_in, thread::rwlock_holder_type, RWLOCK_NONE, RWLOCK_READER, mutex::sem, spinlock_lock, spinlock_unlock(), WAKEUP_FIRST, and semaphore::wq.

Referenced by _rwlock_write_lock_timeout(), rwlock_read_unlock(), and rwlock_write_unlock().

Here is the call graph for this function:

void mutex_initialize mutex_t mtx  ) 
 

Initialize mutex

Initialize mutex.

Parameters:
mtx Mutex.

Definition at line 48 of file mutex.c.

References mutex::sem, and semaphore_initialize().

Referenced by as_area_create(), as_area_share(), as_create(), rwlock_initialize(), and task_create().

Here is the call graph for this function:

void mutex_unlock mutex_t mtx  ) 
 

Release mutex

Release mutex.

Parameters:
mtx Mutex.

Definition at line 78 of file mutex.c.

References mutex::sem, and semaphore_up().

Referenced by _condvar_wait_timeout(), as_area_create(), as_area_destroy(), as_area_resize(), as_area_share(), as_get_size(), as_page_fault(), as_switch(), asid_get(), check_area_conflicts(), futex_find(), pt_unlock(), ptl0_create(), sh_info_remove_reference(), task_create(), and task_destroy().

Here is the call graph for this function:

void release_spinlock void *  arg  )  [static]
 

Release spinlock callback

This is a callback function invoked from the scheduler. The callback is registered in _rwlock_read_lock_timeout().

Parameters:
arg Spinlock.

Definition at line 382 of file rwlock.c.

References spinlock_unlock().

Referenced by _rwlock_read_lock_timeout().

Here is the call graph for this function:

void rwlock_initialize rwlock_t rwl  ) 
 

Initialize reader/writer lock

Initialize reader/writer lock.

Parameters:
rwl Reader/Writer lock.

Definition at line 83 of file rwlock.c.

References rwlock::exclusive, mutex_initialize(), rwlock::readers_in, and spinlock_initialize().

Referenced by futex_init().

Here is the call graph for this function:

void rwlock_read_unlock rwlock_t rwl  ) 
 

Release reader/writer lock held by reader

Release reader/writer lock held by reader. Handoff reader/writer lock ownership directly to a waiting writer or don't do anything if more readers poses the lock.

Parameters:
rwl Reader/Writer lock.

Definition at line 284 of file rwlock.c.

References ALLOW_ALL, interrupts_disable(), interrupts_restore(), let_others_in(), rwlock::readers_in, spinlock_lock, and spinlock_unlock().

Referenced by futex_find().

Here is the call graph for this function:

void rwlock_write_unlock rwlock_t rwl  ) 
 

Release reader/writer lock held by writer

Release reader/writer lock held by writer. Handoff reader/writer lock ownership directly to waiting readers or a writer.

Parameters:
rwl Reader/Writer lock.

Definition at line 263 of file rwlock.c.

References ALLOW_ALL, interrupts_disable(), interrupts_restore(), let_others_in(), spinlock_lock, and spinlock_unlock().

Referenced by futex_find().

Here is the call graph for this function:

void semaphore_initialize semaphore_t s,
int  val
 

Initialize semaphore

Initialize semaphore.

Parameters:
s Semaphore.
val Maximal number of threads allowed to enter critical section.

Definition at line 52 of file semaphore.c.

References interrupts_disable(), interrupts_restore(), waitq::missed_wakeups, spinlock_lock, spinlock_unlock(), waitq_initialize(), and semaphore::wq.

Referenced by mutex_initialize().

Here is the call graph for this function:

void semaphore_up semaphore_t s  ) 
 

Semaphore up

Semaphore up.

Parameters:
s Semaphore.

Definition at line 92 of file semaphore.c.

References waitq_wakeup(), WAKEUP_FIRST, and semaphore::wq.

Referenced by mutex_unlock().

Here is the call graph for this function:

void spinlock_initialize spinlock_t sl,
char *  name
 

Initialize spinlock

Initialize spinlock.

Parameters:
sl Pointer to spinlock_t structure.

Definition at line 59 of file spinlock.c.

References atomic_set(), and spinlock::val.

Referenced by _slab_cache_create(), _zone_merge(), chardev_initialize(), cmd_initialize(), cpu_init(), frame_init(), ipc_answerbox_init(), ipc_irq_make_table(), ipc_phone_init(), make_magcache(), rwlock_initialize(), task_create(), thr_constructor(), timeout_init(), timeout_initialize(), waitq_initialize(), and zone_construct().

Here is the call graph for this function:

void spinlock_lock_debug spinlock_t sl  ) 
 

int spinlock_trylock spinlock_t sl  ) 
 

Lock spinlock conditionally

Lock spinlock conditionally. If the spinlock is not available at the moment, signal failure.

Parameters:
sl Pointer to spinlock_t structure.
Returns:
Zero on failure, non-zero otherwise.

Definition at line 141 of file spinlock.c.

References CS_ENTER_BARRIER, preemption_disable(), preemption_enable(), and spinlock::val.

Referenced by ipc_cleanup(), scheduler_separated_stack(), timeout_unregister(), waitq_interrupt_sleep(), and waitq_timeouted_sleep().

Here is the call graph for this function:

static void spinlock_unlock spinlock_t sl  )  [static]
 

Unlock spinlock

Unlock spinlock.

Parameters:
sl Pointer to spinlock_t structure.

Definition at line 91 of file spinlock.h.

References ASSERT, atomic_get(), atomic_set(), CS_LEAVE_BARRIER, preemption_enable(), and spinlock::val.

Referenced by _getc(), _ipc_answer_free_call(), _ipc_call(), _rwlock_read_lock_timeout(), _rwlock_write_lock_timeout(), _slab_cache_create(), _slab_reclaim(), _waitq_wakeup_unsafe(), answer_preprocess(), as_destroy(), as_switch(), asid_get(), asid_put(), cap_get(), cap_set(), chardev_push_character(), clock(), cmd_desc(), cmd_help(), cmd_register(), cmdtab_search_one(), cushion(), ddi_iospace_enable(), ddi_physmem_map(), exc_print_cmd(), exc_register(), fb_putchar(), find_best_thread(), find_free_zone_lock(), find_zone_and_lock(), frame_alloc_generic(), frame_free(), frame_get_parent(), frame_mark_unavailable(), frame_reference_add(), frame_set_parent(), get_call(), get_mag_from_cache(), ipc_answer(), ipc_call(), ipc_cleanup(), ipc_forward(), ipc_irq_cleanup(), ipc_irq_register(), ipc_irq_send_msg(), ipc_irq_send_notif(), ipc_irq_unregister(), ipc_phone_connect(), ipc_phone_hangup(), ipc_print_task(), ipc_wait_for_call(), kcpulb(), kinit(), klog_vprintf(), ktaskclnp(), ktaskgc(), let_others_in(), magazine_obj_get(), magazine_obj_put(), parse_cmdline(), put_mag_to_cache(), release_spinlock(), relink_rq(), rwlock_read_unlock(), rwlock_write_unlock(), sched_print_list(), scheduler(), scheduler_separated_stack(), semaphore_initialize(), send_call(), slab_cache_destroy(), slab_enable_cpucache(), slab_obj_create(), slab_obj_destroy(), slab_print_list(), slab_reclaim(), sys_cap_grant(), sys_cap_revoke(), task_create(), task_kill(), task_print_list(), thread_create(), thread_destroy(), thread_detach(), thread_exit(), thread_join_timeout(), thread_ready(), thread_register_call_me(), timeout_register(), timeout_unregister(), tlb_shootdown_finalize(), tlb_shootdown_ipi_recv(), waitq_interrupt_sleep(), waitq_sleep_finish(), waitq_sleep_prepare(), waitq_sleep_timeout_unsafe(), waitq_timeouted_sleep(), waitq_wakeup(), zone_merge(), and zone_print_list().

Here is the call graph for this function:

__native sys_futex_sleep_timeout __address  uaddr,
__u32  usec,
int  flags
 

Sleep in futex wait queue.

Parameters:
uaddr Userspace address of the futex counter.
usec If non-zero, number of microseconds this thread is willing to sleep.
flags Select mode of operation.
Returns:
One of ESYNCH_TIMEOUT, ESYNCH_OK_ATOMIC and ESYNCH_OK_BLOCKED. See synch.h. If there is no physical mapping for uaddr ENOENT is returned.

Definition at line 111 of file futex.c.

References ALIGN_DOWN, AS, ENOENT, futex_find(), interrupts_disable(), interrupts_restore(), page_mapping_find(), PAGE_SIZE, page_table_lock(), page_table_unlock(), SYNCH_FLAGS_INTERRUPTIBLE, waitq_sleep_timeout(), and futex::wq.

Here is the call graph for this function:

__native sys_futex_wakeup __address  uaddr  ) 
 

Wakeup one thread waiting in futex wait queue.

Parameters:
uaddr Userspace address of the futex counter.
Returns:
ENOENT if there is no physical mapping for uaddr.

Definition at line 146 of file futex.c.

References ALIGN_DOWN, AS, ENOENT, futex_find(), interrupts_disable(), interrupts_restore(), page_mapping_find(), PAGE_SIZE, page_table_lock(), page_table_unlock(), waitq_wakeup(), WAKEUP_FIRST, and futex::wq.

Here is the call graph for this function:

void waitq_initialize waitq_t wq  ) 
 

Initialize wait queue

Initialize wait queue.

Parameters:
wq Pointer to wait queue to be initialized.

Definition at line 66 of file waitq.c.

References waitq::head, list_initialize(), waitq::missed_wakeups, and spinlock_initialize().

Referenced by chardev_initialize(), condvar_initialize(), futex_initialize(), ipc_answerbox_init(), semaphore_initialize(), thread_create(), and thread_usleep().

Here is the call graph for this function:

void waitq_interrupt_sleep thread_t t  ) 
 

Interrupt sleeping thread.

This routine attempts to interrupt a thread from its sleep in a waitqueue. If the thread is not found sleeping, no action is taken.

Parameters:
t Thread to be interrupted.

Definition at line 127 of file waitq.c.

References interrupts_disable(), interrupts_restore(), list_remove(), NULL, thread::saved_context, thread::sleep_interruptible, thread::sleep_interruption_context, thread::sleep_queue, thread::sleep_timeout, spinlock_lock, spinlock_trylock(), spinlock_unlock(), thread_exists(), thread_ready(), threads_lock, thread::timeout_pending, timeout_unregister(), and thread::wq_link.

Referenced by task_kill().

Here is the call graph for this function:

void waitq_sleep_finish waitq_t wq,
int  rc,
ipl_t  ipl
 

Finish waiting in a wait queue.

This function restores interrupts to the state that existed prior to the call to waitq_sleep_prepare(). If necessary, the wait queue lock is released.

Parameters:
wq Wait queue.
rc Return code of waitq_sleep_timeout_unsafe().
ipl Interrupt level returned by waitq_sleep_prepare().

Definition at line 275 of file waitq.c.

References ESYNCH_OK_ATOMIC, ESYNCH_WOULD_BLOCK, interrupts_restore(), and spinlock_unlock().

Referenced by _condvar_wait_timeout(), and waitq_sleep_timeout().

Here is the call graph for this function:

ipl_t waitq_sleep_prepare waitq_t wq  ) 
 

Prepare to sleep in a waitq.

This function will return holding the lock of the wait queue and interrupts disabled.

Parameters:
wq Wait queue.
Returns:
Interrupt level as it existed on entry to this function.

Definition at line 237 of file waitq.c.

References interrupts_disable(), interrupts_restore(), spinlock_lock, spinlock_unlock(), and THREAD.

Referenced by _condvar_wait_timeout(), and waitq_sleep_timeout().

Here is the call graph for this function:

int waitq_sleep_timeout waitq_t wq,
__u32  usec,
int  flags
 

Sleep until either wakeup, timeout or interruption occurs

This is a sleep implementation which allows itself to time out or to be interrupted from the sleep, restoring a failover context.

Sleepers are organised in a FIFO fashion in a structure called wait queue.

This function is really basic in that other functions as waitq_sleep() and all the *_timeout() functions use it.

Parameters:
wq Pointer to wait queue.
usec Timeout in microseconds.
flags Specify mode of the sleep.
The sleep can be interrupted only if the SYNCH_FLAGS_INTERRUPTIBLE bit is specified in flags.

If usec is greater than zero, regardless of the value of the SYNCH_FLAGS_NON_BLOCKING bit in flags, the call will not return until either timeout, interruption or wakeup comes.

If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is not set in flags, the call will not return until wakeup or interruption comes.

If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is set in flags, the call will immediately return, reporting either success or failure.

Returns:
Returns one of: ESYNCH_WOULD_BLOCK, ESYNCH_TIMEOUT, ESYNCH_INTERRUPTED, ESYNCH_OK_ATOMIC, ESYNCH_OK_BLOCKED.
  • ESYNCH_WOULD_BLOCK means that the sleep failed because at the time of the call there was no pending wakeup.
  • ESYNCH_TIMEOUT means that the sleep timed out.
  • ESYNCH_INTERRUPTED means that somebody interrupted the sleeping thread.
  • ESYNCH_OK_ATOMIC means that the sleep succeeded and that there was a pending wakeup at the time of the call. The caller was not put asleep at all.
  • ESYNCH_OK_BLOCKED means that the sleep succeeded; the full sleep was attempted.

Definition at line 217 of file waitq.c.

References waitq_sleep_finish(), waitq_sleep_prepare(), and waitq_sleep_timeout_unsafe().

Referenced by _semaphore_down_timeout(), ipc_wait_for_call(), sys_futex_sleep_timeout(), thread_join_timeout(), and thread_usleep().

Here is the call graph for this function:

int waitq_sleep_timeout_unsafe waitq_t wq,
__u32  usec,
int  flags
 

Internal implementation of waitq_sleep_timeout().

This function implements logic of sleeping in a wait queue. This call must be preceeded by a call to waitq_sleep_prepare() and followed by a call to waitq_slee_finish().

Parameters:
wq See waitq_sleep_timeout().
usec See waitq_sleep_timeout().
flags See waitq_sleep_timeout().
Returns:
See waitq_sleep_timeout().

Definition at line 300 of file waitq.c.

References context_save, ESYNCH_INTERRUPTED, ESYNCH_OK_ATOMIC, ESYNCH_OK_BLOCKED, ESYNCH_TIMEOUT, ESYNCH_WOULD_BLOCK, waitq::head, list_append(), waitq::missed_wakeups, scheduler(), Sleeping, spinlock_lock, spinlock_unlock(), SYNCH_FLAGS_INTERRUPTIBLE, SYNCH_FLAGS_NON_BLOCKING, THREAD, timeout_register(), and waitq_timeouted_sleep().

Referenced by _condvar_wait_timeout(), and waitq_sleep_timeout().

Here is the call graph for this function:

void waitq_timeouted_sleep void *  data  )  [static]
 

Handle timeout during waitq_sleep_timeout() call

This routine is called when waitq_sleep_timeout() timeouts. Interrupts are disabled.

It is supposed to try to remove 'its' thread from the wait queue; it can eventually fail to achieve this goal when these two events overlap. In that case it behaves just as though there was no timeout at all.

Parameters:
data Pointer to the thread that called waitq_sleep_timeout().

Definition at line 85 of file waitq.c.

References list_remove(), NULL, thread::saved_context, thread::sleep_queue, thread::sleep_timeout_context, spinlock_lock, spinlock_trylock(), spinlock_unlock(), thread_exists(), thread_ready(), threads_lock, thread::timeout_pending, and thread::wq_link.

Referenced by waitq_sleep_timeout_unsafe().

Here is the call graph for this function:

void waitq_wakeup waitq_t wq,
bool  all
 

Wake up first thread sleeping in a wait queue

Wake up first thread sleeping in a wait queue. This is the SMP- and IRQ-safe wrapper meant for general use.

Besides its 'normal' wakeup operation, it attempts to unregister possible timeout.

Parameters:
wq Pointer to wait queue.
all If this is non-zero, all sleeping threads will be woken up and missed count will be zeroed.

Definition at line 386 of file waitq.c.

References _waitq_wakeup_unsafe(), interrupts_disable(), interrupts_restore(), spinlock_lock, and spinlock_unlock().

Referenced by _ipc_answer_free_call(), _ipc_call(), chardev_push_character(), condvar_broadcast(), condvar_signal(), main_ap_separated_stack(), semaphore_up(), send_call(), and sys_futex_wakeup().

Here is the call graph for this function:


Variable Documentation

hash_table_t futex_ht [static]
 

Futex hash table.

Definition at line 74 of file futex.c.

Referenced by futex_cleanup(), futex_find(), and futex_init().

rwlock_t futex_ht_lock [static]
 

Read-write lock protecting global futex hash table. It is also used to serialize access to all futex_t structures. Must be acquired before the task futex B+tree lock.

Definition at line 71 of file futex.c.

Referenced by futex_cleanup(), futex_find(), and futex_init().

hash_table_operations_t futex_ht_ops [static]
 

Initial value:

 {
        .hash = futex_ht_hash,
        .compare = futex_ht_compare,
        .remove_callback = futex_ht_remove_callback
}
Futex hash table operations.

Definition at line 77 of file futex.c.

Referenced by futex_init().


Generated on Sun Jun 18 17:23:35 2006 for HelenOS Kernel (ppc32) by  doxygen 1.4.6