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

thread.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_THREAD_HH 00025 #define GFC_G_THREAD_HH 00026 00027 #ifndef GFC_G_MUTEX_HH 00028 #include <gfc/glib/mutex.hh> 00029 #endif 00030 00031 #ifndef GFC_G_TIMEVAL_HH 00032 #include <gfc/glib/timeval.hh> 00033 #endif 00034 00035 #ifndef SIGCXX_SIGCXX_H 00036 #include <sigc++/sigc++.h> 00037 #endif 00038 00039 namespace GFC { 00040 00041 namespace G { 00042 00043 class Error; 00044 00047 00048 enum ThreadError 00049 { 00050 THREAD_ERROR_AGAIN = G_THREAD_ERROR_AGAIN 00051 }; 00052 00058 00059 enum ThreadPriority 00060 { 00061 THREAD_PRIORITY_LOW = G_THREAD_PRIORITY_LOW, 00062 THREAD_PRIORITY_NORMAL = G_THREAD_PRIORITY_NORMAL, 00063 THREAD_PRIORITY_HIGH = G_THREAD_PRIORITY_HIGH, 00064 THREAD_PRIORITY_URGENT = G_THREAD_PRIORITY_URGENT 00065 }; 00066 00104 00105 class Thread : private GThread, protected sigc::trackable 00106 { 00107 friend class none; 00108 00109 Thread(); 00110 Thread(const Thread&); 00111 Thread& operator=(const Thread&); 00112 00113 public: 00114 typedef sigc::slot<void> ThreadSlot; 00121 00124 00125 static Thread* create(const ThreadSlot& slot, bool joinable, G::Error *error = 0); 00143 00144 static Thread* create(const ThreadSlot& slot, unsigned long stack_size, bool joinable, bool bound, G::Error *error = 0); 00171 00175 00176 GThread* g_thread() const; 00178 00179 bool is_joinable() const; 00182 00183 ThreadPriority get_priority() const; 00185 00187 00188 static void init(GThreadFunctions *vtable = 0); 00216 00217 static bool supported(); 00220 00221 static Thread* self(); 00224 00225 static void yield(); 00229 00230 static void exit(); 00236 00239 00240 void join(); 00245 00246 void set_priority(ThreadPriority priority); 00255 00257 }; 00258 00300 00301 class Condition : public GFC::Object 00302 00303 { 00304 Condition(const Condition&); 00305 Condition& operator=(const Condition&); 00306 00307 GCond *cond_; 00308 00309 public: 00312 00313 Condition(); 00315 00316 ~Condition(); 00318 00322 00323 GCond* g_cond() const; 00325 00329 00330 void signal(); 00335 00336 void broadcast(); 00341 00342 bool wait(Mutex& mutex, const TimeVal *abs_time = 0); 00354 00356 }; 00357 00362 00363 #define GFC_STATIC_PRIVATE_INIT { G_STATIC_PRIVATE_INIT } 00364 00390 00391 template<typename T> 00392 struct StaticPrivate 00393 { 00394 GStaticPrivate private_key_; 00395 00396 static void delete_data(void *data) 00397 { 00398 delete static_cast<T*>(data); 00399 } 00404 00405 00408 00409 GStaticPrivate* g_static_private() const 00410 { 00411 return const_cast<GStaticPrivate*>(&private_key_); 00412 } 00414 00415 operator GStaticPrivate* () const 00416 { 00417 return this ? g_static_private() : 0; 00418 } 00420 00424 00425 T* get() const 00426 { 00427 return static_cast<T*>(g_static_private_get(g_static_private())); 00428 } 00435 00436 void set(T *data, GDestroyNotify notify = &delete_data) 00437 { 00438 g_static_private_set(private_key_, data, notify); 00439 } 00452 00454 }; 00455 00486 00487 template<typename T> 00488 class Private : public StaticPrivate<T> 00489 { 00490 Private(const Private<T>&); 00491 Private<T>& operator=(const Private<T>&); 00492 00493 public: 00496 00497 Private() 00498 { 00499 g_static_private_init(this->g_static_private()); 00500 } 00502 00503 ~Private() 00504 { 00505 g_static_private_free(this->g_static_private()); 00506 } 00508 00510 }; 00511 00512 } // namespace G 00513 00514 } // namespace GFC 00515 00516 #include <gfc/glib/inline/thread.inl> 00517 00518 #endif // GFC_G_THREAD_HH

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