/*
 * threadwrap.h
 *
 *  Created on: 10.01.2011
 *      Author: uwe
 */

#ifndef THREADWRAP_H_
#define THREADWRAP_H_

#include <pthread.h>

//#define MAXTHREADS 16
//#define USETHREADS 1

#ifdef __cplusplus
extern "C"
{
#endif

unsigned int  get_MAXTHREADS();
unsigned int  get_USETHREADS();
void set_MAXTHREADS(unsigned int );
void set_USETHREADS(unsigned int );

#ifdef __cplusplus
}
#endif

#define MPT_THREAD_T pthread_t
#define MPT_THREAD_CREATE(tid, attr, func, arg) pthread_create(tid, attr, func, arg)
#define MPT_THREAD_JOIN(tid, retval)	pthread_join(tid, retval)
#define MPT_THREAD_DESTROY(thread)	pthread_destroy(thread)

#define MPT_THREAD_MUTEX_T					pthread_mutex_t
#define MPT_THREAD_MUTEX_INIT(mutex, attr)	pthread_mutex_init(mutex, attr)
#define MPT_THREAD_MUTEX_DESTROY(mutex) 	pthread_mutex_destroy(mutex)

#define MPT_THREAD_MUTEX_LOCK(mutex) 		pthread_mutex_lock(mutex)
#define MPT_THREAD_MUTEX_UNLOCK(mutex)		pthread_mutex_unlock(mutex)
#define MPT_THREAD_MUTEX_TRYLOCK(mutex) 	pthread_mutex_trylock(mutex)

#define MPT_THREAD_COND_T	pthread_cond_t
#define MPT_THREAD_COND_INIT(cond, attr) pthread_cond_init(cond, attr)
#define MPT_THREAD_COND_DESTROY(cond) pthread_cond_destroy(cond)

#define MPT_THREAD_COND_WAIT(cond, mutex) pthread_cond_wait(cond, mutex);
#define	 MPT_THREAD_COND_SIGNAL(cond) pthread_cond_signal(cond);
#define MPT_THREAD_COND_BROADCAST(cond) pthread_cond_broadcast(cond)

#endif /* THREADWRAP_H_ */
