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

kernel/HOLD/critsec.c File Reference

#include "config.h"
#include <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 (volatile unsigned char *counter)
 increment counter without interruption

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

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

 __asm__ ("\n\.text\n\.global _locked_check_and_increment\n\_locked_check_and_increment:\n\push.w r4\n\stc ccr, r4h\n\orc#0x80, ccr\n\mov.b @r0, r4l\n\beq lci_get_lock\n\\n\push.w r2\n\push.w r3\n\mov.w @_ctid, r2\n\mov.w @r1, r3\n\sub.w r3, r2\n\bne lci_cant_lock\n\\n\pop.w r3\n\pop.w r2\n\bra lci_get_lock\n\\n\lci_cant_lock:\n\pop.w r3\n\pop.w r2\n\mov.w#0xffff, r0\n\bra lci_done\n\\n\lci_get_lock:\n\inc r4l\n\mov.b r4l,@r0\n\mov.w @_ctid, r0\n\mov.w r0,@r1\n\sub.w r0, r0\n\\n\lci_done:\n\ldc r4h, ccr\n\pop.w r4\n\rts\n\")
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__ "\n\.text\n\.global _locked_check_and_increment\n\_locked_check_and_increment:\n\push.w r4\n\stc  ccr,
r4h\n\orc#  0x80,
ccr\n\mov.b @  r0,
r4l\n\beq lci_get_lock\n\\n\push.w r2\n\push.w r3\n\mov.w @  _ctid,
r2\n\mov.w @  r1,
r3\n\sub.w  r3,
r2\n\bne lci_cant_lock\n\\n\pop.w r3\n\pop.w r2\n\bra lci_get_lock\n\\n\lci_cant_lock:\n\pop.w r3\n\pop.w r2\n\mov.w#  0xffff,
r0\n\bra lci_done\n\\n\lci_get_lock:\n\inc r4l\n\mov.b  r4l,
@r0\n\mov.w @  _ctid,
r0\n\mov.w  r0,
@r1\n\sub.w  r0,
r0\n\\n\lci_done:\n\ldc  r4h,
ccr\n\pop.w r4\n\rts\n\" 
 

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

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

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

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

Referenced by CriticalSectionBlock::CriticalSectionBlock().

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

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


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


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

Generated on Mon Feb 16 21:02:27 2004 for brickOS Kernel Developer by doxygen 1.3.5