gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
Macros
gwion_thread.h File Reference

cross-platform thread functions More...

#include <pthread.h>
#include <dlfcn.h>

Go to the source code of this file.

Macros

#define THREAD_RETTYPE   void *
 
#define THREAD_FUNC(a)   THREAD_RETTYPE(a)(void *data)
 
#define THREAD_TYPE   pthread_t
 
#define THREAD_CREATE(thread, func, arg)    pthread_create(&thread, NULL, func, arg)
 
#define THREAD_JOIN(thread)   pthread_join(thread, NULL)
 
#define THREAD_RETURN(arg)
 
#define THREAD_DETACH(arg)   pthread_detach(arg)
 
#define MUTEX_TYPE   pthread_mutex_t *
 
#define MUTEX_INITIALIZER   PTHREAD_MUTEX_INITIALIZER
 
#define MUTEX_SETUP(x)
 
#define MUTEX_CLEANUP(x)
 
#define MUTEX_LOCK(x)   pthread_mutex_lock((x))
 
#define MUTEX_COND_LOCK(x)   pthread_mutex_lock((x))
 
#define MUTEX_UNLOCK(x)   pthread_mutex_unlock((x))
 
#define MUTEX_COND_UNLOCK(x)   pthread_mutex_unlock((x))
 
#define THREAD_COND_TYPE   pthread_cond_t*
 
#define THREAD_COND_SETUP(x)
 
#define THREAD_COND_WAIT(x, mutex)   pthread_cond_wait(x, mutex)
 
#define THREAD_COND_SIGNAL(x)   pthread_cond_signal(x)
 
#define THREAD_COND_BROADCAST(x)   pthread_cond_broadcast(x)
 
#define THREAD_COND_CLEANUP(x)
 
#define STR_EXPAND(tok)   #tok
 
#define STR(tok)   STR_EXPAND(tok)
 
#define DLOPEN(dl, b)   dlopen(dl, b)
 
#define DLSYM(dl, t, a)   (t)(intptr_t) dlsym(dl, a)
 
#define DLCLOSE(dl)   dlclose(dl)
 
#define DLERROR()   dlerror()
 

Detailed Description

cross-platform thread functions

Definition in file gwion_thread.h.

Macro Definition Documentation

◆ DLCLOSE

#define DLCLOSE ( dl)    dlclose(dl)

Definition at line 93 of file gwion_thread.h.

◆ DLERROR

#define DLERROR ( )    dlerror()

Definition at line 94 of file gwion_thread.h.

◆ DLOPEN

#define DLOPEN ( dl,
b )   dlopen(dl, b)

Definition at line 91 of file gwion_thread.h.

◆ DLSYM

#define DLSYM ( dl,
t,
a )   (t)(intptr_t) dlsym(dl, a)

Definition at line 92 of file gwion_thread.h.

◆ MUTEX_CLEANUP

#define MUTEX_CLEANUP ( x)
Value:
{ \
pthread_mutex_destroy((x)); \
xfree(x); \
}

Definition at line 60 of file gwion_thread.h.

60#define MUTEX_CLEANUP(x) \
61 { \
62 pthread_mutex_destroy((x)); \
63 xfree(x); \
64 }

◆ MUTEX_COND_LOCK

#define MUTEX_COND_LOCK ( x)    pthread_mutex_lock((x))

Definition at line 66 of file gwion_thread.h.

◆ MUTEX_COND_UNLOCK

#define MUTEX_COND_UNLOCK ( x)    pthread_mutex_unlock((x))

Definition at line 68 of file gwion_thread.h.

◆ MUTEX_INITIALIZER

#define MUTEX_INITIALIZER   PTHREAD_MUTEX_INITIALIZER

Definition at line 51 of file gwion_thread.h.

◆ MUTEX_LOCK

#define MUTEX_LOCK ( x)    pthread_mutex_lock((x))

Definition at line 65 of file gwion_thread.h.

◆ MUTEX_SETUP

#define MUTEX_SETUP ( x)
Value:
{ \
pthread_mutexattr_t attr; \
pthread_mutexattr_init(&attr); \
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \
x = (pthread_mutex_t *)xmalloc(sizeof(pthread_mutex_t)); \
pthread_mutex_init(x, &attr); \
}
static ANEW void * xmalloc(const m_uint sz)
Definition xalloc.h:13

Definition at line 52 of file gwion_thread.h.

52#define MUTEX_SETUP(x) \
53 { \
54 pthread_mutexattr_t attr; \
55 pthread_mutexattr_init(&attr); \
56 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \
57 x = (pthread_mutex_t *)xmalloc(sizeof(pthread_mutex_t)); \
58 pthread_mutex_init(x, &attr); \
59 }

◆ MUTEX_TYPE

#define MUTEX_TYPE   pthread_mutex_t *

Definition at line 50 of file gwion_thread.h.

◆ MUTEX_UNLOCK

#define MUTEX_UNLOCK ( x)    pthread_mutex_unlock((x))

Definition at line 67 of file gwion_thread.h.

◆ STR

#define STR ( tok)    STR_EXPAND(tok)

Definition at line 88 of file gwion_thread.h.

◆ STR_EXPAND

#define STR_EXPAND ( tok)    #tok

Definition at line 87 of file gwion_thread.h.

◆ THREAD_COND_BROADCAST

#define THREAD_COND_BROADCAST ( x)    pthread_cond_broadcast(x)

Definition at line 78 of file gwion_thread.h.

◆ THREAD_COND_CLEANUP

#define THREAD_COND_CLEANUP ( x)
Value:
{ \
pthread_cond_destroy(x); \
xfree(x); \
}

Definition at line 79 of file gwion_thread.h.

79#define THREAD_COND_CLEANUP(x) \
80 { \
81 pthread_cond_destroy(x); \
82 xfree(x); \
83 }

◆ THREAD_COND_SETUP

#define THREAD_COND_SETUP ( x)
Value:
{ \
x = (pthread_cond_t *)xcalloc(1, sizeof(pthread_cond_t)); \
pthread_cond_init(x, NULL); \
}
static ANEW void * xcalloc(const m_uint n, const m_uint sz)
Definition xalloc.h:18

Definition at line 71 of file gwion_thread.h.

71#define THREAD_COND_SETUP(x) \
72 { \
73 x = (pthread_cond_t *)xcalloc(1, sizeof(pthread_cond_t)); \
74 pthread_cond_init(x, NULL); \
75 }

◆ THREAD_COND_SIGNAL

#define THREAD_COND_SIGNAL ( x)    pthread_cond_signal(x)

Definition at line 77 of file gwion_thread.h.

◆ THREAD_COND_TYPE

#define THREAD_COND_TYPE   pthread_cond_t*

Definition at line 70 of file gwion_thread.h.

◆ THREAD_COND_WAIT

#define THREAD_COND_WAIT ( x,
mutex )   pthread_cond_wait(x, mutex)

Definition at line 76 of file gwion_thread.h.

◆ THREAD_CREATE

#define THREAD_CREATE ( thread,
func,
arg )    pthread_create(&thread, NULL, func, arg)

Definition at line 40 of file gwion_thread.h.

40#define THREAD_CREATE(thread, func, arg) \
41 pthread_create(&thread, NULL, func, arg)

◆ THREAD_DETACH

#define THREAD_DETACH ( arg)    pthread_detach(arg)

Definition at line 48 of file gwion_thread.h.

◆ THREAD_FUNC

#define THREAD_FUNC ( a)    THREAD_RETTYPE(a)(void *data)

Definition at line 38 of file gwion_thread.h.

◆ THREAD_JOIN

#define THREAD_JOIN ( thread)    pthread_join(thread, NULL)

Definition at line 42 of file gwion_thread.h.

◆ THREAD_RETTYPE

#define THREAD_RETTYPE   void *

Definition at line 37 of file gwion_thread.h.

◆ THREAD_RETURN

#define THREAD_RETURN ( arg)
Value:
{ \
pthread_exit(NULL); \
return NULL; \
}

Definition at line 43 of file gwion_thread.h.

43#define THREAD_RETURN(arg) \
44 { \
45 pthread_exit(NULL); \
46 return NULL; \
47 }

◆ THREAD_TYPE

#define THREAD_TYPE   pthread_t

Definition at line 39 of file gwion_thread.h.