diff options
| author | fusion32 <marcopuzziello@gmail.com> | 2025-05-22 14:43:54 -0300 |
|---|---|---|
| committer | fusion32 <marcopuzziello@gmail.com> | 2025-05-22 14:44:31 -0300 |
| commit | 3edeaf1f5280b88da6cf60ad65f9c5c5c8d508c2 (patch) | |
| tree | 1cb1505304bdfe6b6115296340e92765e2421f63 /src/thread.hh | |
| parent | 297e8450d80411d81f0aaeee642053354125bd6d (diff) | |
| download | game-3edeaf1f5280b88da6cf60ad65f9c5c5c8d508c2.tar.gz game-3edeaf1f5280b88da6cf60ad65f9c5c5c8d508c2.zip | |
implement threading API
Diffstat (limited to 'src/thread.hh')
| -rw-r--r-- | src/thread.hh | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/thread.hh b/src/thread.hh new file mode 100644 index 0000000..a3b0d04 --- /dev/null +++ b/src/thread.hh @@ -0,0 +1,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_ |
