summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-06-04 12:47:39 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-06-04 12:47:39 +0000
commit80f8b22357d4997c2025bee4660f726f3049fe74 (patch)
tree4246890690b8fe36ad26cced79190c3b45db07ec
parent150c5a7ceff528cbd5bdd153d3e29f0f6d4f794a (diff)
downloadrockbox-80f8b22357d4997c2025bee4660f726f3049fe74.tar.gz
rockbox-80f8b22357d4997c2025bee4660f726f3049fe74.zip
Clarified the mutex code, renamed the NUM_TICK_TASKS macro
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@885 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/kernel.c18
-rw-r--r--firmware/kernel.h4
2 files changed, 11 insertions, 11 deletions
diff --git a/firmware/kernel.c b/firmware/kernel.c
index 12b6eea781..be30d8e56b 100644
--- a/firmware/kernel.c
+++ b/firmware/kernel.c
@@ -25,7 +25,7 @@
25 25
26long current_tick = 0; 26long current_tick = 0;
27 27
28void (*tick_funcs[NUM_TICK_TASKS])(void); 28void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
29 29
30static void tick_start(unsigned int interval_in_ms); 30static void tick_start(unsigned int interval_in_ms);
31 31
@@ -37,7 +37,7 @@ void kernel_init(void)
37 int i; 37 int i;
38 38
39 /* Clear the tick task array */ 39 /* Clear the tick task array */
40 for(i = 0;i < NUM_TICK_TASKS;i++) 40 for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
41 { 41 {
42 tick_funcs[i] = NULL; 42 tick_funcs[i] = NULL;
43 } 43 }
@@ -151,7 +151,7 @@ void IMIA0(void)
151 int i; 151 int i;
152 152
153 /* Run through the list of tick tasks */ 153 /* Run through the list of tick tasks */
154 for(i = 0;i < NUM_TICK_TASKS;i++) 154 for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
155 { 155 {
156 if(tick_funcs[i]) 156 if(tick_funcs[i])
157 { 157 {
@@ -170,7 +170,7 @@ int tick_add_task(void (*f)(void))
170 int oldlevel = set_irq_level(15); 170 int oldlevel = set_irq_level(15);
171 171
172 /* Add a task if there is room */ 172 /* Add a task if there is room */
173 for(i = 0;i < NUM_TICK_TASKS;i++) 173 for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
174 { 174 {
175 if(tick_funcs[i] == NULL) 175 if(tick_funcs[i] == NULL)
176 { 176 {
@@ -189,7 +189,7 @@ int tick_remove_task(void (*f)(void))
189 int oldlevel = set_irq_level(15); 189 int oldlevel = set_irq_level(15);
190 190
191 /* Remove a task if it is there */ 191 /* Remove a task if it is there */
192 for(i = 0;i < NUM_TICK_TASKS;i++) 192 for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
193 { 193 {
194 if(tick_funcs[i] == f) 194 if(tick_funcs[i] == f)
195 { 195 {
@@ -208,20 +208,20 @@ int tick_remove_task(void (*f)(void))
208 ****************************************************************************/ 208 ****************************************************************************/
209void mutex_init(struct mutex *m) 209void mutex_init(struct mutex *m)
210{ 210{
211 m->count = 0; 211 m->locked = false;
212} 212}
213 213
214void mutex_lock(struct mutex *m) 214void mutex_lock(struct mutex *m)
215{ 215{
216 /* Wait until the lock is open... */ 216 /* Wait until the lock is open... */
217 while(m->count) 217 while(m->locked)
218 yield(); 218 yield();
219 219
220 /* ...and lock it */ 220 /* ...and lock it */
221 m->count++; 221 m->locked = true;
222} 222}
223 223
224void mutex_unlock(struct mutex *m) 224void mutex_unlock(struct mutex *m)
225{ 225{
226 m->count--; 226 m->locked = false;
227} 227}
diff --git a/firmware/kernel.h b/firmware/kernel.h
index f79bc42b80..ee9ded7ab0 100644
--- a/firmware/kernel.h
+++ b/firmware/kernel.h
@@ -27,7 +27,7 @@
27 27
28#define HZ 100 /* number of ticks per second */ 28#define HZ 100 /* number of ticks per second */
29 29
30#define NUM_TICK_TASKS 4 30#define MAX_NUM_TICK_TASKS 4
31 31
32#define QUEUE_LENGTH 16 /* MUST be a power of 2 */ 32#define QUEUE_LENGTH 16 /* MUST be a power of 2 */
33#define QUEUE_LENGTH_MASK (QUEUE_LENGTH - 1) 33#define QUEUE_LENGTH_MASK (QUEUE_LENGTH - 1)
@@ -47,7 +47,7 @@ struct event_queue
47 47
48struct mutex 48struct mutex
49{ 49{
50 int count; 50 bool locked;
51}; 51};
52 52
53/* global tick variable */ 53/* global tick variable */