Subversion Repositories HomeAutomation

Rev

Rev 1398 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /***************************************************************************
  2.                            wthread.h  -  description
  3.                               -------------------
  4.      begin                : Sun Jan 02 2000
  5.      copyright            : (C) 2001 by Rainer Lehrig
  6.      email                : lehrig@t-online.de
  7.   ***************************************************************************/
  8.  
  9.  /***************************************************************************
  10.   *                                                                         *
  11.   *   This library is free software; you can redistribute it and/or modify  *
  12.   *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
  13.   *   published by the Free Software Foundation                             *
  14.   *                                                                         *
  15.   ***************************************************************************/
  16.  /***********************************************************************************
  17.  
  18.  Wrapper for posix threads (UNIX,VMS,windows)
  19.  
  20.  (C) Rainer Lehrig 2001                                       lehrig@t-online.de
  21.  
  22.  ***********************************************************************************/
  23.  
  24.  #ifndef _RL_WTHREAD_H_
  25.  #define _RL_WTHREAD_H_
  26.  
  27.  #include "rldefine.h"
  28.  
  29.  #ifdef _WIN32
  30.  
  31.  #include <windows.h>
  32.  #include <winbase.h>
  33.  #include <stddef.h>
  34.  #include <string.h>
  35.  
  36.  #ifndef _WRAPTHREAD_
  37.  #ifndef _WTHREAD_H_
  38.  typedef unsigned long int pthread_t;
  39.  
  40.  /* Attributes for threads */
  41.  struct __sched_param
  42.  {
  43.    int sched_priority;
  44.  };
  45.  
  46.  typedef struct
  47.  {
  48.    int     __detachstate;
  49.    int     __schedpolicy;
  50.    struct  __sched_param __schedparam;
  51.    int     __inheritsched;
  52.    int     __scope;
  53.    size_t  __guardsize;
  54.    int     __stackaddr_set;
  55.    void   *__stackaddr;
  56.    size_t  __stacksize;
  57.  }pthread_attr_t;
  58.  
  59.  typedef HANDLE pthread_mutex_t;
  60.  //old typedef CRITICAL_SECTION pthread_mutex_t;
  61.  typedef long             pthread_mutexattr_t;
  62.  #endif
  63.  #endif
  64.  
  65.  #else  /* VMS or UNIX */
  66.  #include <pthread.h>
  67.  #endif /* end of MSWINDOWS */
  68.  
  69.  #ifndef _WRAPTHREAD_
  70.  #ifndef _WTHREAD_H_
  71.  typedef struct
  72.  {
  73.  #ifdef _WIN32
  74.    int    cmax;
  75.    HANDLE hSemaphore;
  76.  #else
  77.    int              cmax;
  78.    int              nready;
  79.    pthread_mutex_t  mutex;
  80.    pthread_cond_t   cond;
  81.  #endif
  82.  }WSEMAPHORE;
  83.  #endif
  84.  #endif
  85.  
  86.  /* function prototypes */
  87.  //#ifdef __cplusplus
  88.  //extern "C" {
  89.  //#endif
  90.  int  rlwthread_attr_init(pthread_attr_t *attr);
  91.  int  rlwthread_create(pthread_t *tid, const pthread_attr_t *attr,
  92.                        void *(*func)(void*), void *arg);
  93.  void rlwthread_close_handle(pthread_t *tid);
  94.  void rlwthread_exit(void *status);
  95.  int  rlwthread_join(pthread_t tid, void **status);
  96.  int  rlwthread_mutex_init(pthread_mutex_t *mptr, const pthread_mutexattr_t *attr);
  97.  int  rlwthread_mutex_destroy(pthread_mutex_t *mptr);
  98.  int  rlwthread_mutex_lock(pthread_mutex_t *mptr);
  99.  int  rlwthread_mutex_trylock(pthread_mutex_t *mptr);
  100.  int  rlwthread_mutex_unlock(pthread_mutex_t *mptr);
  101.  int  rlwthread_cancel(pthread_t tid);
  102.  int  rlwrapinit_semaphore(WSEMAPHORE *s, int cmax);
  103.  int  rlwrapdestroy_semaphore(WSEMAPHORE *s);
  104.  int  rlwrapincrement_semaphore(WSEMAPHORE *s);
  105.  int  rlwrapwait_semaphore(WSEMAPHORE *s);
  106.  int  rlwthread_sleep(long msec);
  107.  void rlsleep(long msec);
  108.  //#ifdef __cplusplus
  109.  //};
  110.  //#endif
  111.  
  112.  #endif
  113.