Reference Manual
Inti Logo
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

mutex.h

Go to the documentation of this file.
00001 /*  Inti: Integrated Foundation Classes
00002  *  Copyright (C) 2003 The Inti Development Team.
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00023 
00024 #ifndef INTI_G_MUTEX_H
00025 #define INTI_G_MUTEX_H
00026 
00027 #ifndef INTI_SLOT_H
00028 #include <inti/slot.h>
00029 #endif
00030 
00031 #ifndef __G_THREAD_H__
00032 #include <glib/gthread.h>
00033 #endif
00034 
00035 #define INTI_STATIC_RW_LOCK_INIT { G_STATIC_RW_LOCK_INIT }
00036 
00037 namespace Inti {
00038 
00039 namespace G {
00040 
00041 class Error;
00042 
00108 
00109 class Mutex : public ReferencedObject
00110 {
00111         Mutex(const Mutex&);
00112         Mutex& operator=(const Mutex&);
00113 
00114         GMutex *mutex_;
00115         bool locked_;
00116 
00117 public:
00120 
00121         Mutex(bool lock_mutex = false);
00128 
00129         ~Mutex();
00131 
00135 
00136         GMutex* g_mutex() const { return mutex_; }
00138 
00139         operator GMutex* () const;
00141 
00142         bool is_locked() const;
00145 
00149 
00150         void lock();
00158 
00159         bool trylock();
00172 
00173         void unlock();
00177 };
00178 
00183 
00184 #define INTI_STATIC_MUTEX_INIT { G_STATIC_MUTEX_INIT }
00185 
00217 
00218 struct StaticMutex
00219 {
00220         GStaticMutex mutex_;
00221 
00224 
00225         void init();
00227 
00231 
00232         GStaticMutex* g_static_mutex() const { return const_cast<GStaticMutex*>(&mutex_); }
00234 
00235         operator GStaticMutex* () const;
00237 
00241 
00242         void lock();
00250 
00251         bool trylock();
00264 
00265         void unlock();
00270 };
00271 
00276 
00277 #define INTI_STATIC_REC_MUTEX_INIT { G_STATIC_REC_MUTEX_INIT }
00278 
00291 
00292 struct StaticRecMutex
00293 {
00294         GStaticRecMutex mutex_;
00295 
00298 
00299         void init();
00301 
00305 
00306         GStaticRecMutex* g_static_rec_mutex() const { return const_cast<GStaticRecMutex*>(&mutex_); }
00308 
00309         operator GStaticRecMutex* () const;
00311 
00312         bool is_locked() const;
00314 
00318 
00319         void lock(unsigned int depth = 1);
00327 
00328         bool trylock();
00336 
00337         void unlock();
00342 
00343         unsigned int unlock_full();
00349 };
00350 
00356 
00357 class RecMutex : public StaticRecMutex
00358 {
00359         RecMutex(const RecMutex&);
00360         RecMutex& operator=(const RecMutex&);
00361 
00362 public:
00365 
00366         RecMutex(bool lock_mutex = false, unsigned int depth = 1);
00370 
00371         ~RecMutex();
00373 
00374 };
00375 
00380 
00381 #define INTI_STATIC_RW_LOCK_INIT { G_STATIC_RW_LOCK_INIT }
00382 
00448 
00449 struct StaticRWLock
00450 {
00451         GStaticRWLock lock_;
00452 
00455 
00456         void init();
00458 
00462 
00463         GStaticRWLock* g_static_rw_lock() const { return const_cast<GStaticRWLock*>(&lock_); }
00465 
00466         operator GStaticRWLock* () const;
00468 
00472 
00473         void reader_lock();
00483 
00484         bool reader_trylock();
00492 
00493         void reader_unlock();
00497 
00498         void writer_lock();
00505 
00506         bool writer_trylock();
00513 
00514         void writer_unlock();
00521 };
00522 
00528 
00529 class RWLock : public StaticRWLock
00530 {
00531         RWLock(const RWLock&);
00532         RWLock& operator=(const RWLock&);
00533 
00534 public:
00537 
00538         RWLock();
00540 
00541         ~RWLock();
00544 };
00545 
00546 } // namespace G
00547 
00548 } // namespace Inti
00549 
00550 #endif // INTI_G_MUTEX_H
00551 
Main Page - Footer


Generated on Sun Sep 14 20:08:03 2003 for Inti by doxygen 1.3.2 written by Dimitri van Heesch, © 1997-2002