/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 :
* =====================================================================
* sc_thread.h
* Copyright (c) 2003 - 2011 sys0tem
* LICENSE :
* LGPL (GNU Lesser General Public License - Version 3,29 June 2007)
* http://www.gnu.org/copyleft/lesser.html
* or
* EPL (Eclipse Public License - v1.0)
* http://www.eclipse.org/legal/epl-v10.html
* =====================================================================
*/
#ifndef __SC_THREAD_H__
#define __SC_THREAD_H__
#include <sc_os.h>
#if (SC_isWindows)
#include <windows.h>
#include <process.h>
typedef HANDLE mutex_t;
#else
#include <pthread.h>
#include <time.h>
typedef pthread_mutex_t mutex_t;
#endif /* if (SC_isWindows) */
#include <sc_error.h>
typedef struct SC_Thread_ {
void* _data;
void (*start)(struct SC_Thread_*);
void (*join )(struct SC_Thread_*);
void (*_run )(void*);
#if (SC_isWindows)
HANDLE _hThread;
unsigned _threadID;
#else
pthread_t _tid;
#endif
} SC_Thread;
typedef struct SC_Mutex_ {
mutex_t mutex;
} SC_Mutex;
#ifdef __cplusplus
extern "C" {
#endif
SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize);
void SC_Thread_delete(SC_Thread* thread);
void SC_Mutex_init(mutex_t* mutex);
void SC_Mutex_lock(mutex_t* mutex);
void SC_Mutex_unlock(mutex_t* mutex);
void SC_Mutex_destroy(mutex_t* mutex);
void SC_sleep(long time);
#ifdef __cplusplus
}
#endif
#endif /* __SC_SOCKET_H__ */