ooRexx  4.2.0-source
About: ooRexx (Open Object Rexx) is a free implementation of Object Rexx. Object Rexx is an enhancement of the classic Rexx interpreter; a full-featured programming language with a human-oriented syntax.
  Fossies Dox: ooRexx-4.2.0-source.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

SysSemaphore.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.ibm.com/developerworks/oss/CPLv1.0.htm */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /*****************************************************************************/
39 /* REXX Unix Support */
40 /* */
41 /* Semaphore support for Unix systems */
42 /* */
43 /*****************************************************************************/
44 
45 #ifndef SysSemaphore_DEFINED
46 #define SysSemaphore_DEFINED
47 
48 #include <pthread.h>
49 #include <stdlib.h>
50 #include "rexx.h"
51 
52 class SysSemaphore {
53 public:
54  SysSemaphore() : postedCount(0), created(false) { }
55  SysSemaphore(bool);
56  ~SysSemaphore() { ; }
57  void create();
58  inline void open() { ; }
59  void close();
60  void post();
61  void wait();
62  bool wait(uint32_t);
63  void reset();
64  inline bool posted() { return postedCount != 0; }
65 
66 protected:
67  pthread_cond_t semCond;
68  pthread_mutex_t semMutex;
70  bool created;
71 };
72 
73 class SysMutex {
74 public:
75  SysMutex() : created(false) { ; }
76  SysMutex(bool);
77  ~SysMutex() { ; }
78  void create();
79  inline void open() { ; }
80  void close();
81  inline void request() { pthread_mutex_lock(&mutexMutex); }
82  inline void release() { pthread_mutex_unlock(&mutexMutex); }
83  inline bool requestImmediate() { return pthread_mutex_trylock(&mutexMutex) == 0;}
84 
85 protected:
86  pthread_mutex_t mutexMutex;
87  bool created;
88 };
89 #endif
SysMutex::create
void create()
Definition: SysSemaphore.cpp:238
SysSemaphore
Definition: SysSemaphore.hpp:52
SysSemaphore::reset
void reset()
Definition: SysSemaphore.cpp:213
rexx.h
SysSemaphore::SysSemaphore
SysSemaphore()
Definition: SysSemaphore.hpp:54
SysMutex::open
void open()
Definition: SysSemaphore.hpp:79
SysMutex::mutexMutex
pthread_mutex_t mutexMutex
Definition: SysSemaphore.hpp:86
SysSemaphore::created
bool created
Definition: SysSemaphore.hpp:70
SysSemaphore::~SysSemaphore
~SysSemaphore()
Definition: SysSemaphore.hpp:56
SysMutex::close
void close()
Definition: SysSemaphore.cpp:287
SysSemaphore::semMutex
pthread_mutex_t semMutex
Definition: SysSemaphore.hpp:68
SysSemaphore::close
void close()
Definition: SysSemaphore.cpp:153
SysSemaphore::create
void create()
Definition: SysSemaphore.cpp:89
SysMutex::SysMutex
SysMutex()
Definition: SysSemaphore.hpp:75
SysMutex::created
bool created
Definition: SysSemaphore.hpp:87
SysMutex
Definition: SysSemaphore.hpp:73
SysMutex::request
void request()
Definition: SysSemaphore.hpp:81
SysSemaphore::posted
bool posted()
Definition: SysSemaphore.hpp:64
SysSemaphore::postedCount
int postedCount
Definition: SysSemaphore.hpp:69
SysMutex::requestImmediate
bool requestImmediate()
Definition: SysSemaphore.hpp:83
SysSemaphore::semCond
pthread_cond_t semCond
Definition: SysSemaphore.hpp:67
SysSemaphore::post
void post()
Definition: SysSemaphore.cpp:164
SysSemaphore::wait
void wait()
Definition: SysSemaphore.cpp:174
SysMutex::~SysMutex
~SysMutex()
Definition: SysSemaphore.hpp:77
SysSemaphore::open
void open()
Definition: SysSemaphore.hpp:58
SysMutex::release
void release()
Definition: SysSemaphore.hpp:82