1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Linus Nielsen Feltzing 2002-06-04 12:47:39 +00:00
parent 150c5a7cef
commit 80f8b22357
2 changed files with 11 additions and 11 deletions

View file

@ -25,7 +25,7 @@
long current_tick = 0; long current_tick = 0;
void (*tick_funcs[NUM_TICK_TASKS])(void); void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
static void tick_start(unsigned int interval_in_ms); static void tick_start(unsigned int interval_in_ms);
@ -37,7 +37,7 @@ void kernel_init(void)
int i; int i;
/* Clear the tick task array */ /* Clear the tick task array */
for(i = 0;i < NUM_TICK_TASKS;i++) for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
{ {
tick_funcs[i] = NULL; tick_funcs[i] = NULL;
} }
@ -151,7 +151,7 @@ void IMIA0(void)
int i; int i;
/* Run through the list of tick tasks */ /* Run through the list of tick tasks */
for(i = 0;i < NUM_TICK_TASKS;i++) for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
{ {
if(tick_funcs[i]) if(tick_funcs[i])
{ {
@ -170,7 +170,7 @@ int tick_add_task(void (*f)(void))
int oldlevel = set_irq_level(15); int oldlevel = set_irq_level(15);
/* Add a task if there is room */ /* Add a task if there is room */
for(i = 0;i < NUM_TICK_TASKS;i++) for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
{ {
if(tick_funcs[i] == NULL) if(tick_funcs[i] == NULL)
{ {
@ -189,7 +189,7 @@ int tick_remove_task(void (*f)(void))
int oldlevel = set_irq_level(15); int oldlevel = set_irq_level(15);
/* Remove a task if it is there */ /* Remove a task if it is there */
for(i = 0;i < NUM_TICK_TASKS;i++) for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
{ {
if(tick_funcs[i] == f) if(tick_funcs[i] == f)
{ {
@ -208,20 +208,20 @@ int tick_remove_task(void (*f)(void))
****************************************************************************/ ****************************************************************************/
void mutex_init(struct mutex *m) void mutex_init(struct mutex *m)
{ {
m->count = 0; m->locked = false;
} }
void mutex_lock(struct mutex *m) void mutex_lock(struct mutex *m)
{ {
/* Wait until the lock is open... */ /* Wait until the lock is open... */
while(m->count) while(m->locked)
yield(); yield();
/* ...and lock it */ /* ...and lock it */
m->count++; m->locked = true;
} }
void mutex_unlock(struct mutex *m) void mutex_unlock(struct mutex *m)
{ {
m->count--; m->locked = false;
} }

View file

@ -27,7 +27,7 @@
#define HZ 100 /* number of ticks per second */ #define HZ 100 /* number of ticks per second */
#define NUM_TICK_TASKS 4 #define MAX_NUM_TICK_TASKS 4
#define QUEUE_LENGTH 16 /* MUST be a power of 2 */ #define QUEUE_LENGTH 16 /* MUST be a power of 2 */
#define QUEUE_LENGTH_MASK (QUEUE_LENGTH - 1) #define QUEUE_LENGTH_MASK (QUEUE_LENGTH - 1)
@ -47,7 +47,7 @@ struct event_queue
struct mutex struct mutex
{ {
int count; bool locked;
}; };
/* global tick variable */ /* global tick variable */