aboutsummaryrefslogtreecommitdiff
path: root/src/threads.hh
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2025-06-19 03:13:48 -0300
committerfusion32 <marcopuzziello@gmail.com>2025-06-19 03:13:48 -0300
commitbd3a6a04601749cbde007eaabf803fb602ee2783 (patch)
tree476b89932627aa73ad88de22d37e4617bbdb1795 /src/threads.hh
parente5b8aadd493b8b5df4ed661f2491de33d634b001 (diff)
downloadgame-bd3a6a04601749cbde007eaabf803fb602ee2783.tar.gz
game-bd3a6a04601749cbde007eaabf803fb602ee2783.zip
beginning of `communication.cc`
Diffstat (limited to 'src/threads.hh')
-rw-r--r--src/threads.hh33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/threads.hh b/src/threads.hh
new file mode 100644
index 0000000..9eafe11
--- /dev/null
+++ b/src/threads.hh
@@ -0,0 +1,33 @@
+#ifndef TIBIA_THREADS_HH_
+#define TIBIA_THREADS_HH_ 1
+
+#include "common.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);
+ThreadHandle StartThread(ThreadFunction *Function, void *Argument, size_t StackSize, bool Detach);
+ThreadHandle StartThread(ThreadFunction *Function, void *Argument, void *Stack, size_t StackSize, bool Detach);
+int JoinThread(ThreadHandle Handle);
+void DelayThread(int Seconds, int MicroSeconds);
+
+struct Semaphore {
+ Semaphore(int Value);
+ ~Semaphore(void);
+ void up(void);
+ void down(void);
+
+ // DATA
+ // =================
+ int value;
+ pthread_mutex_t mutex;
+ pthread_cond_t condition;
+};
+
+#endif //TIBIA_THREADS_HH_