matos/core/wait.h

41 lines
1.3 KiB
C
Raw Permalink Normal View History

2020-07-08 23:08:50 +02:00
#pragma once
#include "kthread.h"
struct wait_queue {
struct kthread *thread;
struct wait_queue *next;
struct wait_queue *prev;
};
2020-08-18 14:12:45 +02:00
#define __WAITQUEUE_INITIALIZER(name) \
{ \
.thread = NULL, .next = NULL, .prev = NULL \
}
#define DECLARE_WAITQUEUE(name) \
struct wait_queue name = __WAITQUEUE_INITIALIZER(name)
2020-08-19 14:31:16 +02:00
int waitQueueInit(struct wait_queue *);
int waitQueueFree(struct wait_queue *);
2020-08-15 23:31:35 +02:00
int wait(struct wait_queue *);
2020-08-18 14:12:45 +02:00
int waitTimeout(struct wait_queue *wq, unsigned long msec);
2020-08-19 14:31:16 +02:00
int wakeUp(struct wait_queue *);
2020-08-15 23:31:35 +02:00
#define wait_event(wq, condition) \
do { \
if (condition) \
break; \
wait(wq); \
} while (1)
2020-07-08 23:08:50 +02:00
struct semaphore {
2020-08-15 23:31:35 +02:00
int count;
struct wait_queue *wait;
2020-07-08 23:08:50 +02:00
};
struct mutex {
2020-08-15 23:31:35 +02:00
struct kthread *owner;
struct wait_queue *wait;
2020-07-08 23:08:50 +02:00
};