Main Page   Class Hierarchy   Compound List   File List   Header Files   Compound Members   File Members  

legOS/kernel/semaphore.c File Reference

POSIX 1003.1b semaphores for process synchronization. More...


Functions

wakeup_t sem_event_wait (wakeup_t data)
the semaphore event wakeup function for wait_event(). More...

int sem_wait (sem_t * sem)
wait on a semaphore. More...

int sem_trywait (sem_t * sem)
non-blocking check on a semaphore. More...

 __asm__ (" .text .align 1 .globl _sem_trywait _sem_trywait: stc ccr,r1h ; save flags orc #0x80,ccr ; block all but NMI mov.b @r0,r1l beq sem_fail ; !=0 -> decrease, return 0 dec r1l mov.b r1l,@r0 sub.w r0,r0 bra sem_ok sem_fail:mov #0xffff,r0 ; else return 0xffff sem_ok:ldc r1h,ccr ; restore flags rts ")
int sem_post (sem_t * sem)
increase semaphore count. More...

 __asm__ (" .text .align 1 .globl _sem_post _sem_post: stc ccr,r1h ; save flags orc #0x80,ccr ; disable all but NMI mov.b @r0,r1l inc r1l mov.b r1l,@r0 ldc r1h,ccr ; restore flags sub r0,r0 ; return 0 rts ")


Detailed Description

POSIX 1003.1b semaphores for process synchronization.

Author(s):
Markus L. Noga <markus@noga.de>

Function Documentation

wakeup_t sem_event_wait (wakeup_t data)

the semaphore event wakeup function for wait_event().

Parameters:
data   pointer to the semaphore passed as a wakeup_t

int sem_wait (sem_t * sem)

wait on a semaphore.

Parameters:
sem   a valid semaphore

suspends the calling thread until the semaphore has non-zero count. It then atomically decreases the semaphore count.

implemented with wait_event().

int sem_trywait (sem_t * sem)

non-blocking check on a semaphore.

Parameters:
sem   a valid semaphore

a non-blocking variant of sem_wait. If the semaphore has non-zero count, the count is atomically decreased and sem_trywait immediately returns 0. If the semaphore count is zero, sem_trywait immediately returns with error EAGAIN.

this is IRQ handler safe.

__asm__ (".text.align 1.globl _sem_trywait_sem_trywait:stc ccr, r1h;save flags orc# 0x80, ccr;block all but NMI mov.b@ r0, r1l beq sem_fail;! = 0 -, decrease, return 0 dec r1l mov. b r1l, @r0 sub. w r0, r0 bra sem_ok sem_fail:mov# 0xffff, r0;else return 0xffff sem_ok:ldc r1h, ccr;restore flags rts")

int sem_post (sem_t * sem)

increase semaphore count.

Parameters:
sem   a valid semaphore

atomically increases the count of the semaphore. This function never blocks and can safely be used in asynchronous signal handlers.

__asm__ (".text.align 1.globl _sem_post_sem_post:stc ccr, r1h;save flags orc# 0x80, ccr;disable all but NMI mov.b@ r0, r1l inc r1l mov. b r1l, @ r0 ldc r1h, ccr; restore flags sub r0, r0;return 0 rts")

legOS-0.2.4 is released under the Mozilla Public License. Original code copyright 1998-1999 by the authors.