blob: a3b0d045cca559b09fb25a7b7b7f74e34621db42 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#ifndef TIBIA_THREAD_HH_
#define TIBIA_THREAD_HH_ 1
#include "main.hh"
#include <pthread.h>
typedef pthread_t ThreadHandle;
typedef int (ThreadFunction)(void *);
// TODO(fusion): Probably have another way to tell whether the thread was
// successfully spawned or not?
constexpr ThreadHandle INVALID_THREAD_HANDLE = 0;
ThreadHandle StartThread(ThreadFunction *Function, void *Argument, bool Detach);
int JoinThread(ThreadHandle Handle);
void DelayThread(int Seconds, int MicroSeconds);
struct Semaphore {
// REGULAR FUNCTIONS
// =========================================================================
Semaphore(void);
~Semaphore(void);
void up(void);
void down(void);
// DATA
// =========================================================================
int value;
pthread_mutex_t mutex;
pthread_cond_t condition;
};
#endif //TIBIA_THREAD_HH_
|