| http://www.sim.no/ http://www.coin3d.org/

SbRWMutex.h
1 #ifndef COIN_SBRWMUTEX_H
2 #define COIN_SBRWMUTEX_H
3
4 /**************************************************************************\
5 *
6 * This file is part of the Coin 3D visualization library.
7 * Copyright (C) by Kongsberg Oil & Gas Technologies.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * ("GPL") version 2 as published by the Free Software Foundation.
12 * See the file LICENSE.GPL at the root directory of this source
13 * distribution for additional information about the GNU GPL.
14 *
15 * For using Coin with software that can not be combined with the GNU
16 * GPL, and for taking advantage of the additional benefits of our
17 * support services, please contact Kongsberg Oil & Gas Technologies
18 * about acquiring a Coin Professional Edition License.
19 *
20 * See http://www.coin3d.org/ for more information.
21 *
22 * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
23 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24 *
25 \**************************************************************************/
26
27 #include <Inventor/C/threads/rwmutex.h>
28
29 class SbRWMutex {
30 public:
31 enum Precedence {
32 READ_PRECEDENCE,
33 WRITE_PRECEDENCE
34 };
35
36 SbRWMutex(Precedence policy) {
37 this->rwmutex = cc_rwmutex_construct_etc(
38 (policy == WRITE_PRECEDENCE)? CC_WRITE_PRECEDENCE : CC_READ_PRECEDENCE);
39 }
40 ~SbRWMutex(void) { cc_rwmutex_destruct(this->rwmutex); }
41
42 int writeLock(void) {
43 return cc_rwmutex_write_lock(this->rwmutex) == CC_OK ? 0 : 1;
44 }
45 SbBool tryWriteLock(void) {
46 return cc_rwmutex_write_try_lock(this->rwmutex) == CC_OK;
47 }
48 int writeUnlock(void) {
49 return cc_rwmutex_write_unlock(this->rwmutex) == CC_OK ? 0 : 1;
50 }
51
52 int readLock(void) {
53 return cc_rwmutex_read_lock(this->rwmutex) == CC_OK ? 0 : 1;
54 }
55 int tryReadLock(void) {
56 return cc_rwmutex_read_try_lock(this->rwmutex) == CC_OK;
57 }
58 int readUnlock(void) {
59 return cc_rwmutex_read_unlock(this->rwmutex) == CC_OK ? 0 : 1;
60 }
61
62 private:
63 cc_rwmutex * rwmutex;
64 };
65
66 #endif // !COIN_SBRWMUTEX_H
SbRWMutex::tryReadLock
int tryReadLock(void)
Definition: SbRWMutex.h:55
SbRWMutex::readLock
int readLock(void)
Definition: SbRWMutex.h:52
SbRWMutex::~SbRWMutex
~SbRWMutex(void)
Definition: SbRWMutex.h:40
SbRWMutex::readUnlock
int readUnlock(void)
Definition: SbRWMutex.h:58
SbRWMutex::SbRWMutex
SbRWMutex(Precedence policy)
Definition: SbRWMutex.h:36
SbRWMutex::writeUnlock
int writeUnlock(void)
Definition: SbRWMutex.h:48
SbRWMutex::tryWriteLock
SbBool tryWriteLock(void)
Definition: SbRWMutex.h:45
SbRWMutex::writeLock
int writeLock(void)
Definition: SbRWMutex.h:42
SbRWMutex
Definition: SbRWMutex.h:29

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.