summaryrefslogtreecommitdiff
path: root/src/linux/mutex.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-03-10 12:32:01 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-03-10 12:32:01 +0100
commit7cc519c9d2f5b68aae04d368077f17c605009b43 (patch)
tree3d02133184e0ff2b5277cca46c2b61ed3b648c81 /src/linux/mutex.cpp
parent22f40608ec8ba81577625bb65043cacbc51710eb (diff)
fix config loading on osx, merge /linux and /osx
Diffstat (limited to 'src/linux/mutex.cpp')
-rw-r--r--src/linux/mutex.cpp129
1 files changed, 0 insertions, 129 deletions
diff --git a/src/linux/mutex.cpp b/src/linux/mutex.cpp
deleted file mode 100644
index f59a1eb..0000000
--- a/src/linux/mutex.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-#include "mutex.h"
-
-extern long int syscall (long int __sysno, ...);
-extern int pthread_tryjoin_np(pthread_t ts_thread, void **retval);
-
-ts_thread ts_thread_start(void *(*start_routine) (void *), void *arg)
-{
- ts_thread result;
- result.valid = false;
-
- pthread_attr_t attr;
- int attr_init_result = pthread_attr_init(&attr);
- if (attr_init_result)
- return result;
-
- int start_thread_result = pthread_create(&result.thread, &attr, start_routine, arg);
- if (start_thread_result)
- {
- pthread_attr_destroy(&attr);
- return result;
- }
-
- result.valid = true;
- pthread_attr_destroy(&attr);
-
- return result;
-}
-
-void ts_thread_detach(ts_thread *ts_thread)
-{
- if (ts_thread->valid)
- {
- pthread_detach(ts_thread->thread);
- }
-}
-
-void ts_thread_join(ts_thread *ts_thread)
-{
- if (ts_thread->valid)
- {
- void *retval;
- pthread_join(ts_thread->thread, &retval);
- }
-}
-
-bool ts_thread_tryjoin(ts_thread *ts_thread)
-{
- if (ts_thread->valid)
- {
- void *retval;
- bool thread_joined = !pthread_tryjoin_np(ts_thread->thread, &retval);
- return thread_joined;
- }
- return false;
-}
-
-void ts_thread_exit()
-{
- pthread_exit(0);
-}
-
-void ts_thread_stop(ts_thread *ts_thread)
-{
- if (ts_thread->valid)
- {
- pthread_cancel(ts_thread->thread);
- }
-}
-
-ts_mutex ts_mutex_create()
-{
- ts_mutex result;
-
- pthread_mutexattr_t attr;
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT);
-
- pthread_mutex_init(&result.mutex, &attr);
-
- pthread_mutexattr_destroy(&attr);
-
- return result;
-}
-
-ts_mutex ts_mutex_create_recursive()
-{
- ts_mutex result;
-
- pthread_mutexattr_t attr;
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-
- pthread_mutex_init(&result.mutex, &attr);
-
- pthread_mutexattr_destroy(&attr);
-
- return result;
-}
-
-void ts_mutex_lock(ts_mutex *ts_mutex)
-{
- pthread_mutex_lock(&ts_mutex->mutex);
-}
-
-bool ts_mutex_trylock(ts_mutex *ts_mutex)
-{
- return !pthread_mutex_trylock(&ts_mutex->mutex);
-}
-
-void ts_mutex_unlock(ts_mutex *ts_mutex)
-{
- pthread_mutex_unlock(&ts_mutex->mutex);
-}
-
-void ts_mutex_destroy(ts_mutex *ts_mutex)
-{
- ts_mutex_unlock(ts_mutex);
- pthread_mutex_destroy(&ts_mutex->mutex);
-}
-
-int ts_thread_get_id()
-{
- return (int)syscall(__NR_gettid);
-}
-
-void ts_thread_sleep(int microseconds)
-{
- usleep(microseconds);
-} \ No newline at end of file