matos/core/wait.h
2020-08-20 23:41:36 +02:00

41 lines
1.3 KiB
C

#pragma once
#include "kthread.h"
struct wait_queue {
struct kthread *thread;
struct wait_queue *next;
struct wait_queue *prev;
};
#define __WAITQUEUE_INITIALIZER(name) \
{ \
.thread = NULL, .next = NULL, .prev = NULL \
}
#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 wakeUp(struct wait_queue *);
#define wait_event(wq, condition) \
do { \
if (condition) \
break; \
wait(wq); \
} while (1)
struct semaphore {
int count;
struct wait_queue *wait;
};
struct mutex {
struct kthread *owner;
struct wait_queue *wait;
};