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 
Interface: kernel level critical sections.
kernel configuration file
volatile unsigned char atomic_t
The data type that allows for atomic count operations.
Definition: atomic.h:43
int locked_check_and_increment(atomic_t *counter, tdata_t **tid)
check and increment counter, without interruptions
Internal Interface: task management.
atomic_t count
Definition: critsec.h:49
Interface: reduced UNIX standard library.
tdata_t * task
Definition: critsec.h:50
int enter_critical_section(critsec_t *cs)
lock a critical section, or wait until it is available.
Definition: critsec.c:96
unsigned long wakeup_t
wakeup data area type
Definition: tm.h:57
atomic_t kernel_critsec_count
critical section counter for kernel/task manager
Definition: critsec.c:17
critical section data structure
Definition: critsec.h:48
__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
Definition: critsec.c:78
task data structure
Definition: tm.h:105
wakeup_t wait_event(wakeup_t(*wakeup)(wakeup_t), wakeup_t data)

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