matos/core/wait.h

42 lines
1.4 KiB
C
Raw Normal View History

2020-07-08 23:08:50 +02:00
#pragma once
2021-10-30 14:18:21 +02:00
#include "thread.h"
2020-07-08 23:08:50 +02:00
struct wait_queue {
2021-10-30 14:08:12 +02:00
struct thread *thread;
2020-07-08 23:08:50 +02:00
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);
2021-11-09 20:13:40 +01:00
int waitUp(struct wait_queue *);
int waitUpNb(struct wait_queue *wq, unsigned int nbThread);
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;
2021-11-09 20:13:40 +01:00
struct wait_queue wait;
2020-07-08 23:08:50 +02:00
};
struct mutex {
2021-10-30 14:08:12 +02:00
struct thread *owner;
2020-08-15 23:31:35 +02:00
struct wait_queue *wait;
2020-07-08 23:08:50 +02:00
};