Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

kernel/critsec.c File Reference

#include "config.h"
#include <sys/critsec.h>
#include <unistd.h>
#include <sys/tm.h>
#include <tm.h>

Include dependency graph for critsec.c:

Include dependency graph

Go to the source code of this file.

Functions

int locked_increment (unsigned char *counter)
 increment counter without interruption

 __asm__ (".text.globl _locked_increment _locked_increment:stc ccr, r1h orc#0x80, ccr mov.b @r0, r1l inc r1l mov.b r1l,@r0 ldc r1h, ccr sub r0, r0 rts")
int locked_decrement (unsigned char *counter)
 decrement counter without interruption

 __asm__ (".text.globl _locked_decrement _locked_decrement:stc ccr, r1h orc#0x80, ccr mov.b @r0, r1l dec r1l mov.b r1l,@r0 ldc r1h, ccr sub r0, r0 rts")
int locked_check_and_increment (unsigned char *counter, tdata_t **tid)
 check and increment counter, without interruptions

 __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

int enter_critical_section (critsec_t *cs)
 enter critical section


Variables

volatile unsigned char kernel_critsec_count
 critical section counter for kernel/task manager


Function Documentation

__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" 
 

__asm__ ".text.globl _locked_decrement _locked_decrement:stc  ccr,
r1h orc#  0x80,
ccr mov.b @  r0,
r1l dec r1l mov.b  r1l,
@r0 ldc  r1h,
ccr sub  r0,
r0 rts" 
 

__asm__ ".text.globl _locked_increment _locked_increment:stc  ccr,
r1h orc#  0x80,
ccr mov.b @  r0,
r1l inc r1l mov.b  r1l,
@r0 ldc  r1h,
ccr sub  r0,
r0 rts" 
 

Referenced by dbutton(), disable_irqs(), enable_irqs(), lcd_clear(), lcd_hide(), lcd_show(), power_init(), power_off(), sound_playing(), and sound_system().

int enter_critical_section critsec_t cs  ) 
 

enter critical section

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

Parameters:
cs pointer 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 144 of file critsec.c.

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

int locked_check_and_increment unsigned char *  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:
counter pointer to counter to be incremented
tid pointer 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().

int locked_decrement unsigned char *  counter  ) 
 

decrement counter without interruption

locks interrupts except NMI, decrements count then restores interrupts.

used to leave both normal and kernel critical sections.

Parameters:
counter pointer to counter to be decremented
Returns:
always 0 (currently)
See also:
locked_increment

int locked_increment unsigned char *  counter  ) 
 

increment counter without interruption

locks interrupts except NMI, then increments the count and restores intrrupts.

primarily used to enter kernel critical section.

Parameters:
counter pointer to counter to be incremented
Returns:
always 0 (currently)
See also:
locked_decrement

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 126 of file critsec.c.

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

Referenced by enter_critical_section().


Variable Documentation

volatile unsigned char 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.

Definition at line 15 of file critsec.c.


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

Generated on Sun Jul 27 00:10:09 2003 for brickOS Kernel Developer by doxygen 1.3.2