Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

# SbMutex.h

    00001 #ifndef COIN_SBMUTEX_H
    00002 #define COIN_SBMUTEX_H
    00003
    00004 /**************************************************************************\
    00005  *
    00006  *  This file is part of the Coin 3D visualization library.
    00007  *  Copyright (C) 1998-2003 by Systems in Motion.  All rights reserved.
    00008  *
    00009  *  This library is free software; you can redistribute it and/or
    00010  *  modify it under the terms of the GNU General Public License
    00011  *  ("GPL") version 2 as published by the Free Software Foundation.
    00012  *  See the file LICENSE.GPL at the root directory of this source
    00013  *  distribution for additional information about the GNU GPL.
    00014  *
    00015  *  For using Coin with software that can not be combined with the GNU
    00016  *  GPL, and for taking advantage of the additional benefits of our
    00017  *  support services, please contact Systems in Motion about acquiring
    00018  *  a Coin Professional Edition License.
    00019  *
    00020  *  See <URL:http://www.coin3d.org> for  more information.
    00021  *
    00022  *  Systems in Motion, Teknobyen, Abels Gate 5, 7030 Trondheim, NORWAY.
    00023  *  <URL:http://www.sim.no>.
    00024  *
    00025 \**************************************************************************/
    00026
    00027 #include <Inventor/SbBasic.h>
    00028 #include <Inventor/C/threads/mutex.h>
    00029
    00030 class SbMutex {
    00031 public:
    00032   SbMutex(void) { this->mutex = cc_mutex_construct(); }
    00033   ~SbMutex(void) { cc_mutex_destruct(this->mutex); }
    00034
    00035   int lock(void) {
    00036     return cc_mutex_lock(this->mutex) == CC_OK ? 0 : 1;
    00037   }
    00038   SbBool tryLock(void) {
    00039     return cc_mutex_try_lock(this->mutex) == CC_OK;
    00040   }
    00041   int unlock(void) {
    00042     return cc_mutex_unlock(this->mutex) == CC_OK ? 0 : 1;
    00043   }
    00044
    00045 private:
    00046   // FIXME: we need access to C mutex structur. Should we use friend,
    00047   // or should we add a new public method to get to this structure?
    00048   // pederb, 2002-06-26
    00049   friend class SbCondVar;
    00050   cc_mutex * mutex;
    00051 };
    00052
    00053
    00054 #ifndef COIN_INTERNAL
    00055 // For TGS Inventor compile-time compatibility.
    00056 #include <Inventor/threads/SbThreadAutoLock.h>
    00057 #endif // COIN_INTERNAL
    00058
    00059 #endif // !COIN_SBMUTEX_H