critsec.c
Go to the documentation of this file.
1 
2 #include "config.h"
3 #include <sys/critsec.h>
4 #include <critsec.h>
5 #include <unistd.h>
6 
7 #if defined(CONF_TM)
8 #include <sys/tm.h>
9 #include <tm.h>
10 
12 
18 
19 #if defined(CONF_CRITICAL_SECTIONS)
20 
32 int locked_check_and_increment(atomic_t* counter, tdata_t** tid);
33 __asm__("\n\
34 .text\n\
35 .global _locked_check_and_increment\n\
36  _locked_check_and_increment:\n\
37  push.w r4\n\
38  stc ccr, r4h\n\
39  orc #0x80, ccr\n\
40  mov.b @r0, r4l\n\
41  beq lci_get_lock\n\
42 \n\
43  push.w r2\n\
44  push.w r3\n\
45  mov.w @_ctid, r2\n\
46  mov.w @r1, r3\n\
47  sub.w r3, r2\n\
48  bne lci_cant_lock\n\
49 \n\
50  pop.w r3\n\
51  pop.w r2\n\
52  bra lci_get_lock\n\
53 \n\
54  lci_cant_lock:\n\
55  pop.w r3\n\
56  pop.w r2\n\
57  mov.w #0xffff, r0\n\
58  bra lci_done\n\
59 \n\
60  lci_get_lock:\n\
61  inc r4l\n\
62  mov.b r4l, @r0\n\
63  mov.w @_ctid, r0 \n\
64  mov.w r0, @r1 \n\
65  sub.w r0, r0\n\
66 \n\
67  lci_done:\n\
68  ldc r4h, ccr\n\
69  pop.w r4\n\
70  rts\n\
71  ");
72 
74 
79  critsec_t* cs = (critsec_t*)((unsigned)data);
80  if (locked_check_and_increment(&cs->count, &cs->task) == 0xffff)
81  return 0;
82  else
83  return 1;
84 }
85 
87 
97  if (locked_check_and_increment(&cs->count, &cs->task) == 0xffff)
98  return wait_event(&wait_critical_section, (wakeup_t)((unsigned)cs));
99  return 1;
100 }
101 #endif // CONF_CRITICAL_SECTIONS
102 #endif // CONF_TM
103 
critsec.h
Interface: kernel level critical sections.
_tdata_t
task data structure
Definition: tm.h:105
critsec::task
tdata_t * task
Definition: critsec.h:50
wait_event
wakeup_t wait_event(wakeup_t(*wakeup)(wakeup_t), wakeup_t data)
critsec
critical section data structure
Definition: critsec.h:48
wakeup_t
unsigned long wakeup_t
wakeup data area type
Definition: tm.h:57
critsec::count
atomic_t count
Definition: critsec.h:49
atomic_t
volatile unsigned char atomic_t
The data type that allows for atomic count operations.
Definition: atomic.h:43
locked_check_and_increment
int locked_check_and_increment(atomic_t *counter, tdata_t **tid)
check and increment counter, without interruptions
__asm__
__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\ ")
kernel_critsec_count
atomic_t kernel_critsec_count
critical section counter for kernel/task manager
Definition: critsec.c:17
wait_critical_section
wakeup_t wait_critical_section(wakeup_t data)
wakeup when critical section is available
Definition: critsec.c:78
unistd.h
Interface: reduced UNIX standard library.
enter_critical_section
int enter_critical_section(critsec_t *cs)
lock a critical section, or wait until it is available.
Definition: critsec.c:96
tm.h
Internal Interface: task management.
config.h
kernel configuration file

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.16