Coin Logo 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
29class SbRWMutex {
30public:
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
62private:
63 cc_rwmutex * rwmutex;
64};
65
66#endif // !COIN_SBRWMUTEX_H
Definition SbRWMutex.h:29
SbRWMutex(Precedence policy)
Definition SbRWMutex.h:36
int writeLock(void)
Definition SbRWMutex.h:42
int writeUnlock(void)
Definition SbRWMutex.h:48
int tryReadLock(void)
Definition SbRWMutex.h:55
SbBool tryWriteLock(void)
Definition SbRWMutex.h:45
int readLock(void)
Definition SbRWMutex.h:52
~SbRWMutex(void)
Definition SbRWMutex.h:40
int readUnlock(void)
Definition SbRWMutex.h:58

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

Generated on Wed Jul 17 2024 for Coin by Doxygen 1.12.0.