rllib  1
rlwthread.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                           wthread.h  -  description
00003                              -------------------
00004     begin                : Sun Jan 02 2000
00005     copyright            : (C) 2001 by Rainer Lehrig
00006     email                : lehrig@t-online.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
00013  *   published by the Free Software Foundation                             *
00014  *                                                                         *
00015  ***************************************************************************/
00016 /***********************************************************************************
00017 
00018 Wrapper for posix threads (UNIX,VMS,windows)
00019 
00020 (C) Rainer Lehrig 2001                                       lehrig@t-online.de
00021 
00022 ***********************************************************************************/
00023 
00024 #ifndef _RL_WTHREAD_H_
00025 #define _RL_WTHREAD_H_
00026 
00027 #ifndef SWIG
00028 
00029 #include "rldefine.h"
00030 
00031 #ifdef RLWIN32
00032 
00033 #include <windows.h>
00034 #include <winbase.h>
00035 #include <stddef.h>
00036 #include <string.h>
00037 
00038 #ifndef _WRAPTHREAD_
00039 #ifndef _WTHREAD_H_
00040 typedef unsigned long int pthread_t;
00041 
00042 /* Attributes for threads */
00043 typedef struct __sched_param
00044 {
00045   int sched_priority;
00046 }SCHED_PARAM;
00047 
00048 typedef struct
00049 {
00050   int     __detachstate;
00051   int     __schedpolicy;
00052   struct  __sched_param __schedparam;
00053   int     __inheritsched;
00054   int     __scope;
00055   size_t  __guardsize;
00056   int     __stackaddr_set;
00057   void   *__stackaddr;
00058   size_t  __stacksize;
00059 }pthread_attr_t;
00060 
00061 typedef HANDLE pthread_mutex_t;
00062 //old typedef CRITICAL_SECTION pthread_mutex_t;
00063 typedef long             pthread_mutexattr_t;
00064 #endif
00065 #endif
00066 
00067 #else  /* VMS or UNIX */
00068 #include <pthread.h>
00069 #endif /* end of MSWINDOWS */
00070 
00071 #ifndef _WRAPTHREAD_
00072 #ifndef _WTHREAD_H_
00073 typedef struct
00074 {
00075 #ifdef RLWIN32
00076   int    cmax;
00077   HANDLE hSemaphore;
00078 #else
00079   int              cmax;
00080   int              nready;
00081   pthread_mutex_t  mutex;
00082   pthread_cond_t   cond;
00083 #endif
00084 }WSEMAPHORE;
00085 #endif
00086 #endif
00087 
00088 /* function prototypes */
00089 //#ifdef __cplusplus
00090 //extern "C" {
00091 //#endif
00092 int  rlwthread_attr_init(pthread_attr_t *attr);
00093 int  rlwthread_create(pthread_t *tid, const pthread_attr_t *attr,
00094                       void *(*func)(void*), void *arg);
00095 void rlwthread_close_handle(pthread_t *tid);
00096 void rlwthread_exit(void *status);
00097 int  rlwthread_join(pthread_t tid, void **status);
00098 int  rlwthread_mutex_init(pthread_mutex_t *mptr, const pthread_mutexattr_t *attr);
00099 int  rlwthread_mutex_destroy(pthread_mutex_t *mptr);
00100 int  rlwthread_mutex_lock(pthread_mutex_t *mptr);
00101 int  rlwthread_mutex_trylock(pthread_mutex_t *mptr);
00102 int  rlwthread_mutex_unlock(pthread_mutex_t *mptr);
00103 int  rlwthread_cancel(pthread_t tid);
00104 int  rlwrapinit_semaphore(WSEMAPHORE *s, int cmax);
00105 int  rlwrapdestroy_semaphore(WSEMAPHORE *s);
00106 int  rlwrapincrement_semaphore(WSEMAPHORE *s);
00107 int  rlwrapwait_semaphore(WSEMAPHORE *s);
00108 int  rlwthread_sleep(long msec);
00109 void rlsleep(long msec);
00110 //#ifdef __cplusplus
00111 //};
00112 //#endif
00113 
00114 #else
00115 // SWIG
00116 void rlsleep(long msec);
00117 #endif
00118 
00119 #endif