GFC Logo GFC Title Logo
Reference Manual
Main Page  |  Namespace List  |  Alphabetical List  |  Class List  |  File List

mutex.hh

Go to the documentation of this file.
00001 /* GFC-Core: GTK+ Foundation Classes (Core Library) 00002 * Copyright (C) 2003-2004 The GFC 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 GFC_G_MUTEX_HH 00025 #define GFC_G_MUTEX_HH 00026 00027 #ifndef GFC_OBJECT_HH 00028 #include <gfc/object.hh> 00029 #endif 00030 00031 #ifndef __G_THREAD_H__ 00032 #include <glib/gthread.h> 00033 #endif 00034 00035 #define GFC_STATIC_RW_LOCK_INIT { G_STATIC_RW_LOCK_INIT } 00036 00037 namespace GFC { 00038 00039 namespace G { 00040 00106 00107 class Mutex : public GFC::Object 00108 { 00109 Mutex(const Mutex&); 00110 Mutex& operator=(const Mutex&); 00111 00112 GMutex *mutex_; 00113 bool locked_; 00114 00115 public: 00118 00119 Mutex(bool lock_mutex = false); 00126 00127 ~Mutex(); 00129 00133 00134 GMutex* g_mutex() const; 00136 00137 operator GMutex* () const; 00139 00140 bool is_locked() const; 00143 00147 00148 void lock(); 00156 00157 bool trylock(); 00170 00171 void unlock(); 00175 }; 00176 00181 00182 #define GFC_STATIC_MUTEX_INIT { G_STATIC_MUTEX_INIT } 00183 00215 00216 struct StaticMutex 00217 { 00218 GStaticMutex mutex_; 00219 00222 00223 void init(); 00225 00229 00230 GStaticMutex* g_static_mutex() const; 00232 00233 operator GStaticMutex* () const; 00235 00239 00240 void lock(); 00248 00249 bool trylock(); 00262 00263 void unlock(); 00268 }; 00269 00274 00275 #define GFC_STATIC_REC_MUTEX_INIT { G_STATIC_REC_MUTEX_INIT } 00276 00289 00290 struct StaticRecMutex 00291 { 00292 GStaticRecMutex mutex_; 00293 00296 00297 void init(); 00299 00303 00304 GStaticRecMutex* g_static_rec_mutex() const; 00306 00307 operator GStaticRecMutex* () const; 00309 00310 bool is_locked() const; 00312 00316 00317 void lock(unsigned int depth = 1); 00325 00326 bool trylock(); 00334 00335 void unlock(); 00340 00341 unsigned int unlock_full(); 00347 }; 00348 00354 00355 class RecMutex : public StaticRecMutex 00356 { 00357 RecMutex(const RecMutex&); 00358 RecMutex& operator=(const RecMutex&); 00359 00360 public: 00363 00364 RecMutex(bool lock_mutex = false, unsigned int depth = 1); 00368 00369 ~RecMutex(); 00371 00372 }; 00373 00378 00379 #define GFC_STATIC_RW_LOCK_INIT { G_STATIC_RW_LOCK_INIT } 00380 00446 00447 struct StaticRWLock 00448 { 00449 GStaticRWLock lock_; 00450 00453 00454 void init(); 00456 00460 00461 GStaticRWLock* g_static_rw_lock() const; 00463 00464 operator GStaticRWLock* () const; 00466 00470 00471 void reader_lock(); 00481 00482 bool reader_trylock(); 00490 00491 void reader_unlock(); 00495 00496 void writer_lock(); 00503 00504 bool writer_trylock(); 00511 00512 void writer_unlock(); 00519 }; 00520 00526 00527 class RWLock : public StaticRWLock 00528 { 00529 RWLock(const RWLock&); 00530 RWLock& operator=(const RWLock&); 00531 00532 public: 00535 00536 RWLock(); 00538 00539 ~RWLock(); 00542 }; 00543 00544 } // namespace G 00545 00546 } // namespace GFC 00547 00548 #include <gfc/glib/inline/mutex.inl> 00549 00550 #endif // GFC_G_MUTEX_HH 00551

Generated on Tue Aug 24 00:04:56 2004 for GFC-Core by doxygen 1.3.8