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 
21 
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 

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

Generated on Sat Mar 15 2014 11:28:21 for brickOS Kernel Developer by doxygen 1.8.1.2