thread_none.h 2 KB
/*
 * used for threadsafety within exception
 * actually only pthread is supported
 */
#ifndef  THREAD_H
#define  THREAD_H

#include <stdio.h>

#define  JOIN_OK             0x00
#define  JOIN_TIMEOUT        0x01
#define  JOIN_ERROR          0x02

/*
 * i guess it is possible to write mutex code that uses cond
 * elements to timeout on lock, but right now i have no clear
 * idea of how to do this. The following thoughts i had:
 * - create a struct that holds a pthread_mutex_t and a pthread_cond_t
 *   for every mutex. 
 * - lock mutexes only by calling pthread_cond_timedwait
 * And here starts the problem...to do a cond_timedwait i need to ensure
 * that the mutex is already locked...well and then a question i have not
 * clearyfied, if a thread ends, will all locks on mutexes be removed?
 * I guess so, but i did not test it. And an even more important question,
 * is it possible to write cleanup-code that guarantees that a
 * pthread_cond_signal is called for every mutex the thread holds...
 * well, we will end up with the requirement that the programmer has to
 * call a release mutex function before ending a thread and if the programmer
 * forgets that the behaviour of out code is unspecified
 * Right now i will not support timeouts on mutex-locks and to be consistent
 * it is not supported on win32 either, also it would be much easier to
 * implement there.
 */
#define  MUTEX_LOCK_OK       0x00
#define  MUTEX_LOCK_ERROR    0x02

#define   THREAD_T               int
#define   THREAD_ID_T            int
#define   THREAD_ID              0
#define   SELF_THREAD            0
#define   NEW_THREAD             perror ("No supported thread system used!\n")
#define   CANCEL_THREAD(t)       NEW_THREAD
#define   EXIT_THREAD(r)         NEW_THREAD
#define   JOIN_THREAD(t,i)       NEW_THREAD
#define   THREAD_CANCEL_ENABLE   NEW_THREAD
#define   THREAD_CANCEL_DISABLE  NEW_THREAD
#define   THREAD_CANCEL_ASYNC    NEW_THREAD
#define   THREAD_CANCEL_DEFER    NEW_THREAD
#define   T_PROC_RET             int

#endif   /* THREAD_H */