critsec.c File Reference
#include "config.h"
#include <sys/critsec.h>
#include <critsec.h>
#include <unistd.h>
#include <sys/tm.h>
#include <tm.h>
Include dependency graph for critsec.c:

Go to the source code of this file.

Functions

int locked_check_and_increment (atomic_t *counter, tdata_t **tid)
 check and increment counter, without interruptions More...
 
 __asm__ ("\.text\.global _locked_check_and_increment\ _locked_check_and_increment:\ push.w r4\ stc ccr, r4h\ orc #0x80, ccr\ mov.b @r0, r4l\ beq lci_get_lock\\ push.w r2\ push.w r3\ mov.w @_ctid, r2\ mov.w @r1, r3\ sub.w r3, r2\ bne lci_cant_lock\\ pop.w r3\ pop.w r2\ bra lci_get_lock\\ lci_cant_lock:\ pop.w r3\ pop.w r2\ mov.w #0xffff, r0\ bra lci_done\\ lci_get_lock:\ inc r4l\ mov.b r4l, @r0\ mov.w @_ctid, r0 \ mov.w r0, @r1 \ sub.w r0, r0\\ lci_done:\ ldc r4h, ccr\ pop.w r4\ rts\ ")
 
wakeup_t wait_critical_section (wakeup_t data)
 wakeup when critical section is available More...
 
int enter_critical_section (critsec_t *cs)
 lock a critical section, or wait until it is available. More...
 

Variables

atomic_t kernel_critsec_count
 critical section counter for kernel/task manager More...
 

Function Documentation

§ __asm__()

__asm__ ( "\ext\lobal _locked_check_and_increment\locked_check_and_increment:\ush.w r4\tc  ccr,
r4h\ orc #  0x80,
ccr\ mov.b @  r0,
r4l\ beq lci_get_lock\\ push.w r2\ push.w r3\ mov.w @  _ctid,
r2\ mov.w @  r1,
r3\ sub.w  r3,
r2\ bne lci_cant_lock\\ pop.w r3\ pop.w r2\ bra lci_get_lock\\ lci_cant_lock:\ pop.w r3\ pop.w r2\ mov.w #  0xffff,
r0\ bra lci_done\\ lci_get_lock:\ inc r4l\ mov.b  r4l,
@r0\ mov.w @  _ctid,
r0 \ mov.w  r0,
@r1 \ sub.w  r0,
r0\\ lci_done:\ ldc  r4h,
ccr\ pop.w r4\ rts\ "   
)

§ enter_critical_section()

int enter_critical_section ( critsec_t cs)

lock a critical section, or wait until it is available.

enter critical section

check and lock critical section if it is available; otherwise, wait until it is available, then lock it.

Parameters
cspointer to critical section (critsec_t)
Returns
1 if successful, 0 upon failure
See also
initialize_critical_section
leave_critical_section
destroy_critical_section

Definition at line 96 of file critsec.c.

References critsec::count, locked_check_and_increment(), critsec::task, wait_critical_section(), and wait_event().

Referenced by CriticalSectionBlock::CriticalSectionBlock().

§ locked_check_and_increment()

int locked_check_and_increment ( atomic_t counter,
tdata_t **  tid 
)

check and increment counter, without interruptions

increments counter if count is already zero, or if this is the same task as the one that made it one.

used to enter a normal critical section.

Parameters
counterpointer to counter to be incremented
tidpointer to pointer to receive task pointer of the task that has locked the resource
Returns
0xffff if failure, 0 if successful
See also
locked_decrement

Referenced by enter_critical_section(), and wait_critical_section().

§ wait_critical_section()

wakeup_t wait_critical_section ( wakeup_t  data)

wakeup when critical section is available

wakeup function used to detect when a critical section is available. called while processing an interrupt, so interrupts are already disabled.

Definition at line 78 of file critsec.c.

References critsec::count, locked_check_and_increment(), and critsec::task.

Referenced by enter_critical_section().

Variable Documentation

§ kernel_critsec_count

atomic_t kernel_critsec_count

critical section counter for kernel/task manager

when the critical section counter is Zero, task swapping is allowed. when greater than zero, task swapping is not allowed. This is checked in the task_switch_handler() in systime.c

Definition at line 17 of file critsec.c.


brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated for brickOS Kernel Developer by doxygen 1.8.12