add wq[Init|Free]

This commit is contained in:
Mathieu Maret 2020-08-19 14:31:16 +02:00
parent e8959f3693
commit c71b0135cf
4 changed files with 30 additions and 9 deletions

View File

@ -6,21 +6,18 @@
#include "list.h"
#include "time.h"
struct wait_queue *waitQueues = NULL;
int mutexInit(struct mutex *m)
{
uint32_t flags;
m->owner = NULL;
m->wait = (struct wait_queue *)malloc(sizeof(struct wait_queue));
if (!m->wait)
return ENOMEM;
waitQueueInit(m->wait);
list_init(m->wait->thread);
disable_IRQs(flags);
list_add_tail(waitQueues, m->wait);
restore_IRQs(flags);
return 0;
}
@ -40,7 +37,7 @@ int mutexFree(struct mutex *m)
getCurrentThread());
}
#endif
list_delete(waitQueues, m->wait);
waitQueueFree(m->wait);
free(m->wait);
} else {
ret = EBUSY;
@ -76,7 +73,7 @@ int mutexUnlock(struct mutex *m)
m->owner = NULL;
wake_up(m->wait);
wakeUp(m->wait);
restore_IRQs(flags);

View File

@ -3,7 +3,27 @@
#include "list.h"
#include "wait.h"
int wake_up(struct wait_queue *wq)
static struct wait_queue *waitQueues = NULL;
int waitQueueInit(struct wait_queue *wq)
{
uint32_t flags;
disable_IRQs(flags);
list_add_tail(waitQueues, wq);
restore_IRQs(flags);
return 0;
}
int waitQueueFree(struct wait_queue *wq)
{
uint32_t flags;
disable_IRQs(flags);
list_delete(waitQueues, wq);
restore_IRQs(flags);
return 0;
}
int wakeUp(struct wait_queue *wq)
{
struct kthread *th;
uint32_t flags;

View File

@ -16,9 +16,11 @@ struct wait_queue {
#define DECLARE_WAITQUEUE(name) \
struct wait_queue name = __WAITQUEUE_INITIALIZER(name)
int waitQueueInit(struct wait_queue *);
int waitQueueFree(struct wait_queue *);
int wait(struct wait_queue *);
int waitTimeout(struct wait_queue *wq, unsigned long msec);
int wake_up(struct wait_queue *);
int wakeUp(struct wait_queue *);
#define wait_event(wq, condition) \
do { \

View File

@ -274,7 +274,9 @@ void wqThread(void *arg)
{
(void)arg;
DECLARE_WAITQUEUE(test);
waitQueueInit(&test);
assert(waitTimeout(&test, 1000) == 1);
waitQueueFree(&test);
haveTimeout = 1;
}