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

thread.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_THREAD_H
00025 #define INTI_G_THREAD_H
00026 
00027 #ifndef INTI_G_MUTEX_H
00028 #include <inti/glib/mutex.h>
00029 #endif
00030 
00031 #ifndef INTI_G_TIMEVAL_H
00032 #include <inti/glib/timeval.h>
00033 #endif
00034 
00035 namespace Inti {
00036 
00037 namespace G {
00038 
00039 class Error;
00040 
00043 
00044 enum ThreadError
00045 {
00046         THREAD_ERROR_AGAIN = G_THREAD_ERROR_AGAIN 
00047 };
00048 
00054 
00055 enum ThreadPriority
00056 {
00057         THREAD_PRIORITY_LOW = G_THREAD_PRIORITY_LOW, 
00058         THREAD_PRIORITY_NORMAL = G_THREAD_PRIORITY_NORMAL, 
00059         THREAD_PRIORITY_HIGH = G_THREAD_PRIORITY_HIGH, 
00060         THREAD_PRIORITY_URGENT = G_THREAD_PRIORITY_URGENT 
00061 };
00062 
00100 
00101 class Thread : private GThread
00102 {
00103         friend class none;
00104 
00105         Thread();
00106         Thread(const Thread&);
00107         Thread& operator=(const Thread&);
00108 
00109 public:
00110         typedef Slot0<void> ThreadSlot;
00117 
00120 
00121         static Thread* create(const ThreadSlot *slot, bool joinable, G::Error *error = 0);
00139 
00140         static Thread* create(const ThreadSlot *slot, unsigned long stack_size, bool joinable, bool bound, G::Error *error = 0);
00167 
00171 
00172         GThread* g_thread() const { return (GThread*)this; }
00174 
00175         bool is_joinable() const;
00178 
00179         ThreadPriority get_priority() const;
00181 
00183 
00184         static void init(GThreadFunctions *vtable = 0);
00212 
00213         static bool supported();
00216 
00217         static Thread* self();
00220 
00221         static void yield();
00225 
00226         static void exit();
00232 
00235 
00236         void join();
00241 
00242         void set_priority(ThreadPriority priority);
00251 
00253 };
00254 
00296 
00297 class Condition : public ReferencedObject
00298 
00299 {
00300         Condition(const Condition&);
00301         Condition& operator=(const Condition&);
00302 
00303         GCond *cond_;
00304 
00305 public:
00308 
00309         Condition();
00311 
00312         ~Condition();
00314 
00318 
00319         void signal();
00324 
00325         void broadcast();
00330 
00331         bool wait(Mutex& mutex, const TimeVal *abs_time = 0);
00343 
00345 };
00346 
00351 
00352 #define INTI_STATIC_PRIVATE_INIT { G_STATIC_PRIVATE_INIT }
00353 
00379 
00380 template<typename T>
00381 struct StaticPrivate
00382 {
00383         GStaticPrivate private_key_;
00384 
00385         static void delete_data(void *data)
00386         {
00387                 delete static_cast<T*>(data);
00388         }
00393 
00394 
00397 
00398         GStaticPrivate* g_static_private() const
00399         {
00400                 return const_cast<GStaticPrivate*>(&private_key_);
00401         }
00403 
00404         operator GStaticPrivate* () const
00405         {
00406                 return this ? g_static_private() : 0;
00407         }
00409 
00413 
00414         T* get() const
00415         {
00416                 return static_cast<T*>(g_static_private_get(g_static_private()));
00417         }
00424 
00425         void set(T *data, GDestroyNotify notify = &delete_data)
00426         {
00427                 g_static_private_set(private_key_, data, notify);
00428         }
00441 
00443 };
00444 
00475 
00476 template<typename T>
00477 class Private : public StaticPrivate<T>
00478 {
00479         Private(const Private<T>&);
00480         Private<T>& operator=(const Private<T>&);
00481 
00482 public:
00485 
00486         Private()
00487         {
00488                 g_static_private_init(g_static_private());
00489         }
00491 
00492         ~Private()
00493         {
00494                 g_static_private_free(g_static_private());
00495         }
00497 
00499 };
00500 
00501 } // namespace G
00502 
00503 } // namespace Inti
00504 
00505 #endif // INTI_G_THREAD_H
Main Page - Footer


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