|
|
@@ -231,10 +231,9 @@ uint64_t microseconds()
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void thread_create(ThreadFunction f, void* params, OSThread& thread, const char* name)
|
|
|
+void thread_create(ThreadFunction f, void* params, OSThread* thread, const char* name)
|
|
|
{
|
|
|
- OSThread tid;
|
|
|
- tid.name = name;
|
|
|
+ thread->name = name;
|
|
|
|
|
|
// Make thread joinable
|
|
|
pthread_attr_t attr;
|
|
|
@@ -242,7 +241,7 @@ void thread_create(ThreadFunction f, void* params, OSThread& thread, const char*
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
|
|
|
|
|
// Create thread
|
|
|
- int rc = pthread_create(&tid.thread, &attr, f, (void*)params);
|
|
|
+ int rc = pthread_create(&(thread->thread), &attr, f, (void*)params);
|
|
|
|
|
|
if (rc != 0)
|
|
|
{
|
|
|
@@ -252,48 +251,66 @@ void thread_create(ThreadFunction f, void* params, OSThread& thread, const char*
|
|
|
|
|
|
// Free memory
|
|
|
pthread_attr_destroy(&attr);
|
|
|
+}
|
|
|
|
|
|
- thread = tid;
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void thread_join(OSThread* thread)
|
|
|
+{
|
|
|
+ pthread_join(thread->thread, NULL);
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void thread_join(OSThread thread)
|
|
|
+void thread_detach(OSThread* thread)
|
|
|
{
|
|
|
- pthread_join(thread.thread, NULL);
|
|
|
+ pthread_detach(thread->thread);
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void thread_detach(OSThread thread)
|
|
|
+void mutex_create(OSMutex* mutex)
|
|
|
{
|
|
|
- pthread_detach(thread.thread);
|
|
|
+ pthread_mutex_init(&mutex->mutex, NULL);
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void mutex_create(OSMutex& mutex)
|
|
|
+void mutex_destroy(OSMutex* mutex)
|
|
|
{
|
|
|
- OSMutex mut;
|
|
|
+ pthread_mutex_destroy(&mutex->mutex);
|
|
|
+}
|
|
|
|
|
|
- pthread_mutex_init(&mut.mutex, NULL);
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void mutex_lock(OSMutex* mutex)
|
|
|
+{
|
|
|
+ pthread_mutex_lock(&mutex->mutex);
|
|
|
+}
|
|
|
|
|
|
- mutex = mut;
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void mutex_unlock(OSMutex* mutex)
|
|
|
+{
|
|
|
+ pthread_mutex_unlock(&mutex->mutex);
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void cond_create(OSCond* cond)
|
|
|
+{
|
|
|
+ pthread_cond_init(&cond->cond, NULL);
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void mutex_destroy(OSMutex mutex)
|
|
|
+void cond_destroy(OSCond* cond)
|
|
|
{
|
|
|
- pthread_mutex_destroy(&mutex.mutex);
|
|
|
+ pthread_cond_destroy(&cond->cond);
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void mutex_lock(OSMutex mutex)
|
|
|
+void cond_signal(OSCond* cond)
|
|
|
{
|
|
|
- pthread_mutex_lock(&mutex.mutex);
|
|
|
+ pthread_cond_signal(&cond->cond);
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void mutex_unlock(OSMutex mutex)
|
|
|
+void cond_wait(OSCond* cond, OSMutex* mutex)
|
|
|
{
|
|
|
- pthread_mutex_unlock(&mutex.mutex);
|
|
|
+ pthread_cond_wait(&cond->cond, &mutex->mutex);
|
|
|
}
|
|
|
|
|
|
} // namespace os
|