Subversion Repositories HomeAutomation

Rev

Rev 270 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /***************************************************************************
  2.                            rlthread.h  -  description
  3.                               -------------------
  4.      begin                : Tue Jan 02 2001
  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.  #ifndef _RL_THREAD_H_
  17.  #define _RL_THREAD_H_
  18.  
  19.  #include "rldefine.h"
  20.  #include "rlwthread.h"
  21.  
  22.  class rlThread;
  23.  
  24.  typedef struct
  25.  {
  26.    rlThread *thread;
  27.    void     *user;
  28.    int      running;
  29.  }
  30.  THREAD_PARAM;
  31.  
  32.  class rlThread
  33.  {
  34.  public:
  35.    rlThread(int max_semphore=1000);
  36.    ~rlThread();
  37.    int create(void *(*func)(void*), void *argument);
  38.  
  39.    int trylock();
  40.  
  41.    int lock();
  42.  
  43.    int unlock();
  44.  
  45.    int waitSemaphore();
  46.  
  47.    int incrementSemaphore();
  48.  
  49.    int join(void **status);
  50.  
  51.    int cancel();
  52.  
  53.    void threadExit(void *status);
  54.  
  55.    pthread_t       tid;
  56.    pthread_attr_t  attr;
  57.    pthread_mutex_t mutex;
  58.    WSEMAPHORE      semaphore;
  59.  private:
  60.    THREAD_PARAM    arg;
  61.  };
  62.  
  63.  class rlMutex
  64.  {
  65.  public:
  66.    rlMutex(const pthread_mutexattr_t *attr = NULL);
  67.    ~rlMutex();
  68.  
  69.    int trylock();
  70.  
  71.    int lock();
  72.  
  73.    int unlock();
  74.  
  75.    pthread_mutex_t mutex;
  76.  };
  77.  
  78.  class rlSemaphore
  79.  {
  80.  public:
  81.    rlSemaphore(int max_semaphore = 1000);
  82.    ~rlSemaphore();
  83.  
  84.    int waitSemaphore();
  85.  
  86.    int incrementSemaphore();
  87.  
  88.    WSEMAPHORE      semaphore;
  89.  };
  90.  
  91.  #endif
  92.