cu
sync.h File Reference

Structure for wrapping a generic object with a mutex. More...

#include <pthread.h>

Go to the source code of this file.

Data Structures

struct  mutex_t
 
struct  thread_t
 

Functions

mutex_t cu_mutex_new (void *inner)
 Initialize a CU mutex. More...
 
void cu_mutex_del (mutex_t *mutex, void(*del)(void *))
 Destroy a cu mutex_t object and the data. More...
 
void * cu_lock (mutex_t *mutex)
 lock the mutex and get access to the data More...
 
void cu_unlock (mutex_t *mutex)
 Unlock a mutex_t object. More...
 
thread_t cu_thread_new (void *(*handle)(), void *args)
 Create a thread_t structur. More...
 
void cu_spawn (thread_t *thread)
 Spawn a new thread. More...
 
void * cu_join (thread_t *thread)
 Join a thread. More...
 
void mutex_init (pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr)
 Wrapper around pthread_mutex_init() with error handling. More...
 
void mutex_lock (pthread_mutex_t *mutex)
 Wrapper around pthread_mutex_lock() with error handling. More...
 
void mutex_unlock (pthread_mutex_t *mutex)
 Wrapper around pthread_mutex_unlock() with error handling. More...
 
void mutex_destroy (pthread_mutex_t *mutex)
 Wrapper around pthread_mutex_destroy() with error handling. More...
 
void thread_new (pthread_t *thread, const pthread_attr_t *attr, void *(*handle)(void *), void *arg)
 Wrapper around pthread_thread_create() with error handling. More...
 
void thread_exit (void *retval)
 Wrapper around pthread_exit() More...
 
void thread_join (pthread_t thread, void **retval)
 Wrapper around pthread_join() with error handling. More...
 
void thread_cancel (pthread_t thread)
 Wrapper around pthread_cancel() with error handling. More...
 
void attr_init (pthread_attr_t *attr)
 
void attr_destory (pthread_attr_t *attr)
 

Detailed Description

Structure for wrapping a generic object with a mutex.

The module contains functions with dealing with thread and syncronization.

Pthread wrapper function do not have the prefix cu, they can directly be transferred to pthread calls with error checking.

Function Documentation

void* cu_join ( thread_t thread)

Join a thread.

Parameters
threadto join
Returns
returns the result of joined thread
void* cu_lock ( mutex_t mutex)

lock the mutex and get access to the data

Parameters
mutexmutex to lock
Returns
locked data
void cu_mutex_del ( mutex_t mutex,
void(*)(void *)  del 
)

Destroy a cu mutex_t object and the data.

Parameters
mutexto destroy
mutex_t cu_mutex_new ( void *  inner)

Initialize a CU mutex.

struct complex_object {...};
Parameters
mutexpthread mutex
innerdata to surround with a mutex
Returns
a mutex_t obj
void cu_spawn ( thread_t thread)

Spawn a new thread.

Parameters
threadthread to spawn
thread_t cu_thread_new ( void *(*)()  handle,
void *  args 
)

Create a thread_t structur.

Parameters
handlehandle function
argumentsof the handle function
Returns
new thread_t
void cu_unlock ( mutex_t mutex)

Unlock a mutex_t object.

Parameters
mutexto lock
void mutex_destroy ( pthread_mutex_t *  mutex)

Wrapper around pthread_mutex_destroy() with error handling.

Parameters
mutexMutex
void mutex_init ( pthread_mutex_t *restrict  mutex,
const pthread_mutexattr_t *restrict  attr 
)

Wrapper around pthread_mutex_init() with error handling.

Parameters
mutexMutex
attrAttribute
void mutex_lock ( pthread_mutex_t *  mutex)

Wrapper around pthread_mutex_lock() with error handling.

Parameters
mutexMutex
void mutex_unlock ( pthread_mutex_t *  mutex)

Wrapper around pthread_mutex_unlock() with error handling.

Parameters
mutexMutex
void thread_cancel ( pthread_t  thread)

Wrapper around pthread_cancel() with error handling.

Parameters
threadThread
void thread_exit ( void *  retval)

Wrapper around pthread_exit()

Parameters
retvalReturn value
void thread_join ( pthread_t  thread,
void **  retval 
)

Wrapper around pthread_join() with error handling.

Parameters
threadThread
retvalReturn Value
void thread_new ( pthread_t *  thread,
const pthread_attr_t *  attr,
void *(*)(void *)  handle,
void *  arg 
)

Wrapper around pthread_thread_create() with error handling.

Parameters
threadThread
attrAttribute
handleHandle Function
argArgument