1.1 --- a/epoc32/include/stdapis/glib-2.0/glib/gthread.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/stdapis/glib-2.0/glib/gthread.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,404 @@
1.4 -gthread.h
1.5 +/* GLIB - Library of useful routines for C programming
1.6 + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
1.7 + * Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
1.8 + *
1.9 + * This library is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU Lesser General Public
1.11 + * License as published by the Free Software Foundation; either
1.12 + * version 2 of the License, or (at your option) any later version.
1.13 + *
1.14 + * This library is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.17 + * Lesser General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU Lesser General Public
1.20 + * License along with this library; if not, write to the
1.21 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.22 + * Boston, MA 02111-1307, USA.
1.23 + */
1.24 +
1.25 +/*
1.26 + * Modified by the GLib Team and others 1997-2000. See the AUTHORS
1.27 + * file for a list of people on the GLib Team. See the ChangeLog
1.28 + * files for a list of changes. These files are distributed with
1.29 + * GLib at ftp://ftp.gtk.org/pub/gtk/.
1.30 + */
1.31 +
1.32 +#ifndef __G_THREAD_H__
1.33 +#define __G_THREAD_H__
1.34 +
1.35 +#include <_ansi.h>
1.36 +#include <glib/gerror.h>
1.37 +#include <glib/gtypes.h>
1.38 +#include <glib/gatomic.h> /* for g_atomic_pointer_get */
1.39 +
1.40 +G_BEGIN_DECLS
1.41 +
1.42 +/* GLib Thread support
1.43 + */
1.44 +#ifdef __SYMBIAN32__
1.45 +IMPORT_C GQuark g_thread_error_quark (void);
1.46 +#else
1.47 +extern GQuark g_thread_error_quark (void);
1.48 +#endif /* __SYMBIAN32__ */
1.49 +#define G_THREAD_ERROR g_thread_error_quark ()
1.50 +
1.51 +typedef enum
1.52 +{
1.53 + G_THREAD_ERROR_AGAIN /* Resource temporarily unavailable */
1.54 +} GThreadError;
1.55 +
1.56 +typedef gpointer (*GThreadFunc) (gpointer data);
1.57 +
1.58 +typedef enum
1.59 +{
1.60 + G_THREAD_PRIORITY_LOW,
1.61 + G_THREAD_PRIORITY_NORMAL,
1.62 + G_THREAD_PRIORITY_HIGH,
1.63 + G_THREAD_PRIORITY_URGENT
1.64 +} GThreadPriority;
1.65 +
1.66 +typedef struct _GThread GThread;
1.67 +struct _GThread
1.68 +{
1.69 + /*< private >*/
1.70 + GThreadFunc func;
1.71 + gpointer data;
1.72 + gboolean joinable;
1.73 + GThreadPriority priority;
1.74 +};
1.75 +
1.76 +typedef struct _GMutex GMutex;
1.77 +typedef struct _GCond GCond;
1.78 +typedef struct _GPrivate GPrivate;
1.79 +typedef struct _GStaticPrivate GStaticPrivate;
1.80 +
1.81 +typedef struct _GThreadFunctions GThreadFunctions;
1.82 +struct _GThreadFunctions
1.83 +{
1.84 + GMutex* (*mutex_new) (void);
1.85 + void (*mutex_lock) (GMutex *mutex);
1.86 + gboolean (*mutex_trylock) (GMutex *mutex);
1.87 + void (*mutex_unlock) (GMutex *mutex);
1.88 + void (*mutex_free) (GMutex *mutex);
1.89 + GCond* (*cond_new) (void);
1.90 + void (*cond_signal) (GCond *cond);
1.91 + void (*cond_broadcast) (GCond *cond);
1.92 + void (*cond_wait) (GCond *cond,
1.93 + GMutex *mutex);
1.94 + gboolean (*cond_timed_wait) (GCond *cond,
1.95 + GMutex *mutex,
1.96 + GTimeVal *end_time);
1.97 + void (*cond_free) (GCond *cond);
1.98 + GPrivate* (*private_new) (GDestroyNotify destructor);
1.99 + gpointer (*private_get) (GPrivate *private_key);
1.100 + void (*private_set) (GPrivate *private_key,
1.101 + gpointer data);
1.102 + void (*thread_create) (GThreadFunc func,
1.103 + gpointer data,
1.104 + gulong stack_size,
1.105 + gboolean joinable,
1.106 + gboolean bound,
1.107 + GThreadPriority priority,
1.108 + gpointer thread,
1.109 + GError **error);
1.110 + void (*thread_yield) (void);
1.111 + void (*thread_join) (gpointer thread);
1.112 + void (*thread_exit) (void);
1.113 + void (*thread_set_priority)(gpointer thread,
1.114 + GThreadPriority priority);
1.115 + void (*thread_self) (gpointer thread);
1.116 + gboolean (*thread_equal) (gpointer thread1,
1.117 + gpointer thread2);
1.118 +};
1.119 +
1.120 +#ifdef __SYMBIAN32__
1.121 +IMPORT_C GThreadFunctions *_g_thread_functions_for_glib_use();
1.122 +#endif /* __SYMBIAN32__ */
1.123 +GLIB_VAR GThreadFunctions g_thread_functions_for_glib_use;
1.124 +
1.125 +#ifdef __SYMBIAN32__
1.126 +IMPORT_C gboolean *_g_thread_use_default_impl();
1.127 +#endif /* __SYMBIAN32__ */
1.128 +GLIB_VAR gboolean g_thread_use_default_impl;
1.129 +
1.130 +#ifdef __SYMBIAN32__
1.131 +IMPORT_C gboolean *_g_threads_got_initialized();
1.132 +#endif /* __SYMBIAN32__ */
1.133 +GLIB_VAR gboolean g_threads_got_initialized;
1.134 +
1.135 +/* initializes the mutex/cond/private implementation for glib, might
1.136 + * only be called once, and must not be called directly or indirectly
1.137 + * from another glib-function, e.g. as a callback.
1.138 + */
1.139 +IMPORT_C void g_thread_init (GThreadFunctions *vtable);
1.140 +
1.141 +#ifdef __SYMBIAN32__
1.142 +IMPORT_C gboolean g_thread_supported();
1.143 +#else
1.144 +#define g_thread_supported() (g_threads_got_initialized)
1.145 +#endif
1.146 +
1.147 +/* Errorcheck mutexes. If you define G_ERRORCHECK_MUTEXES, then all
1.148 + * mutexes will check for re-locking and re-unlocking */
1.149 +
1.150 +/* Initialize thread system with errorcheck mutexes. vtable must be
1.151 + * NULL. Do not call directly. Use #define G_ERRORCHECK_MUTEXES
1.152 + * instead.
1.153 + */
1.154 +IMPORT_C void g_thread_init_with_errorcheck_mutexes (GThreadFunctions* vtable);
1.155 +
1.156 +/* A random number to recognize debug calls to g_mutex_... */
1.157 +#define G_MUTEX_DEBUG_MAGIC 0xf8e18ad7
1.158 +
1.159 +#ifdef G_ERRORCHECK_MUTEXES
1.160 +#define g_thread_init(vtable) g_thread_init_with_errorcheck_mutexes (vtable)
1.161 +#endif
1.162 +
1.163 +/* internal function for fallback static mutex implementation */
1.164 +IMPORT_C GMutex* g_static_mutex_get_mutex_impl (GMutex **mutex);
1.165 +
1.166 +#define g_static_mutex_get_mutex_impl_shortcut(mutex) \
1.167 + (g_atomic_pointer_get ((gpointer*)(void*)mutex) ? *(mutex) : \
1.168 + g_static_mutex_get_mutex_impl (mutex))
1.169 +
1.170 +/* shorthands for conditional and unconditional function calls */
1.171 +
1.172 +#define G_THREAD_UF(op, arglist) \
1.173 + (*g_thread_functions_for_glib_use . op) arglist
1.174 +#define G_THREAD_CF(op, fail, arg) \
1.175 + (g_thread_supported () ? G_THREAD_UF (op, arg) : (fail))
1.176 +#define G_THREAD_ECF(op, fail, mutex, type) \
1.177 + (g_thread_supported () ? ((type(*)(GMutex*, gulong, gchar*)) \
1.178 + (*g_thread_functions_for_glib_use . op)) \
1.179 + (mutex, G_MUTEX_DEBUG_MAGIC, G_STRLOC) : (fail))
1.180 +
1.181 +#ifndef G_ERRORCHECK_MUTEXES
1.182 +# define g_mutex_lock(mutex) \
1.183 + G_THREAD_CF (mutex_lock, (void)0, (mutex))
1.184 +# define g_mutex_trylock(mutex) \
1.185 + G_THREAD_CF (mutex_trylock, TRUE, (mutex))
1.186 +# define g_mutex_unlock(mutex) \
1.187 + G_THREAD_CF (mutex_unlock, (void)0, (mutex))
1.188 +# define g_mutex_free(mutex) \
1.189 + G_THREAD_CF (mutex_free, (void)0, (mutex))
1.190 +# define g_cond_wait(cond, mutex) \
1.191 + G_THREAD_CF (cond_wait, (void)0, (cond, mutex))
1.192 +# define g_cond_timed_wait(cond, mutex, abs_time) \
1.193 + G_THREAD_CF (cond_timed_wait, TRUE, (cond, mutex, abs_time))
1.194 +#else /* G_ERRORCHECK_MUTEXES */
1.195 +# define g_mutex_lock(mutex) \
1.196 + G_THREAD_ECF (mutex_lock, (void)0, (mutex), void)
1.197 +# define g_mutex_trylock(mutex) \
1.198 + G_THREAD_ECF (mutex_trylock, TRUE, (mutex), gboolean)
1.199 +# define g_mutex_unlock(mutex) \
1.200 + G_THREAD_ECF (mutex_unlock, (void)0, (mutex), void)
1.201 +# define g_mutex_free(mutex) \
1.202 + G_THREAD_ECF (mutex_free, (void)0, (mutex), void)
1.203 +# define g_cond_wait(cond, mutex) \
1.204 + (g_thread_supported () ? ((void(*)(GCond*, GMutex*, gulong, gchar*))\
1.205 + g_thread_functions_for_glib_use.cond_wait) \
1.206 + (cond, mutex, G_MUTEX_DEBUG_MAGIC, G_STRLOC) : (void) 0)
1.207 +# define g_cond_timed_wait(cond, mutex, abs_time) \
1.208 + (g_thread_supported () ? \
1.209 + ((gboolean(*)(GCond*, GMutex*, GTimeVal*, gulong, gchar*)) \
1.210 + g_thread_functions_for_glib_use.cond_timed_wait) \
1.211 + (cond, mutex, abs_time, G_MUTEX_DEBUG_MAGIC, G_STRLOC) : TRUE)
1.212 +#endif /* G_ERRORCHECK_MUTEXES */
1.213 +
1.214 +#define g_mutex_new() G_THREAD_UF (mutex_new, ())
1.215 +#define g_cond_new() G_THREAD_UF (cond_new, ())
1.216 +#define g_cond_signal(cond) G_THREAD_CF (cond_signal, (void)0, (cond))
1.217 +#define g_cond_broadcast(cond) G_THREAD_CF (cond_broadcast, (void)0, (cond))
1.218 +#define g_cond_free(cond) G_THREAD_CF (cond_free, (void)0, (cond))
1.219 +#define g_private_new(destructor) G_THREAD_UF (private_new, (destructor))
1.220 +#define g_private_get(private_key) G_THREAD_CF (private_get, \
1.221 + ((gpointer)private_key), \
1.222 + (private_key))
1.223 +#define g_private_set(private_key, value) G_THREAD_CF (private_set, \
1.224 + (void) (private_key = \
1.225 + (GPrivate*) (value)), \
1.226 + (private_key, value))
1.227 +#define g_thread_yield() G_THREAD_CF (thread_yield, (void)0, ())
1.228 +
1.229 +#define g_thread_create(func, data, joinable, error) \
1.230 + (g_thread_create_full (func, data, 0, joinable, FALSE, \
1.231 + G_THREAD_PRIORITY_NORMAL, error))
1.232 +
1.233 +IMPORT_C GThread* g_thread_create_full (GThreadFunc func,
1.234 + gpointer data,
1.235 + gulong stack_size,
1.236 + gboolean joinable,
1.237 + gboolean bound,
1.238 + GThreadPriority priority,
1.239 + GError **error);
1.240 +IMPORT_C GThread* g_thread_self (void);
1.241 +IMPORT_C void g_thread_exit (gpointer retval);
1.242 +IMPORT_C gpointer g_thread_join (GThread *thread);
1.243 +
1.244 +IMPORT_C void g_thread_set_priority (GThread *thread,
1.245 + GThreadPriority priority);
1.246 +
1.247 +/* GStaticMutexes can be statically initialized with the value
1.248 + * G_STATIC_MUTEX_INIT, and then they can directly be used, that is
1.249 + * much easier, than having to explicitly allocate the mutex before
1.250 + * use
1.251 + */
1.252 +#define g_static_mutex_lock(mutex) \
1.253 + g_mutex_lock (g_static_mutex_get_mutex (mutex))
1.254 +#define g_static_mutex_trylock(mutex) \
1.255 + g_mutex_trylock (g_static_mutex_get_mutex (mutex))
1.256 +#define g_static_mutex_unlock(mutex) \
1.257 + g_mutex_unlock (g_static_mutex_get_mutex (mutex))
1.258 +IMPORT_C void g_static_mutex_init (GStaticMutex *mutex);
1.259 +IMPORT_C void g_static_mutex_free (GStaticMutex *mutex);
1.260 +
1.261 +struct _GStaticPrivate
1.262 +{
1.263 + /*< private >*/
1.264 + guint index;
1.265 +};
1.266 +#define G_STATIC_PRIVATE_INIT { 0 }
1.267 +IMPORT_C void g_static_private_init (GStaticPrivate *private_key);
1.268 +IMPORT_C gpointer g_static_private_get (GStaticPrivate *private_key);
1.269 +IMPORT_C void g_static_private_set (GStaticPrivate *private_key,
1.270 + gpointer data,
1.271 + GDestroyNotify notify);
1.272 +IMPORT_C void g_static_private_free (GStaticPrivate *private_key);
1.273 +
1.274 +typedef struct _GStaticRecMutex GStaticRecMutex;
1.275 +struct _GStaticRecMutex
1.276 +{
1.277 + /*< private >*/
1.278 + GStaticMutex mutex;
1.279 + guint depth;
1.280 + GSystemThread owner;
1.281 +};
1.282 +
1.283 +#define G_STATIC_REC_MUTEX_INIT { G_STATIC_MUTEX_INIT }
1.284 +IMPORT_C void g_static_rec_mutex_init (GStaticRecMutex *mutex);
1.285 +IMPORT_C void g_static_rec_mutex_lock (GStaticRecMutex *mutex);
1.286 +IMPORT_C gboolean g_static_rec_mutex_trylock (GStaticRecMutex *mutex);
1.287 +IMPORT_C void g_static_rec_mutex_unlock (GStaticRecMutex *mutex);
1.288 +IMPORT_C void g_static_rec_mutex_lock_full (GStaticRecMutex *mutex,
1.289 + guint depth);
1.290 +IMPORT_C guint g_static_rec_mutex_unlock_full (GStaticRecMutex *mutex);
1.291 +IMPORT_C void g_static_rec_mutex_free (GStaticRecMutex *mutex);
1.292 +
1.293 +typedef struct _GStaticRWLock GStaticRWLock;
1.294 +struct _GStaticRWLock
1.295 +{
1.296 + /*< private >*/
1.297 + GStaticMutex mutex;
1.298 + GCond *read_cond;
1.299 + GCond *write_cond;
1.300 + guint read_counter;
1.301 + gboolean have_writer;
1.302 + guint want_to_read;
1.303 + guint want_to_write;
1.304 +};
1.305 +
1.306 +#define G_STATIC_RW_LOCK_INIT { G_STATIC_MUTEX_INIT, NULL, NULL, 0, FALSE, 0, 0 }
1.307 +
1.308 +IMPORT_C void g_static_rw_lock_init (GStaticRWLock* lock);
1.309 +IMPORT_C void g_static_rw_lock_reader_lock (GStaticRWLock* lock);
1.310 +IMPORT_C gboolean g_static_rw_lock_reader_trylock (GStaticRWLock* lock);
1.311 +IMPORT_C void g_static_rw_lock_reader_unlock (GStaticRWLock* lock);
1.312 +IMPORT_C void g_static_rw_lock_writer_lock (GStaticRWLock* lock);
1.313 +IMPORT_C gboolean g_static_rw_lock_writer_trylock (GStaticRWLock* lock);
1.314 +IMPORT_C void g_static_rw_lock_writer_unlock (GStaticRWLock* lock);
1.315 +IMPORT_C void g_static_rw_lock_free (GStaticRWLock* lock);
1.316 +
1.317 +IMPORT_C void g_thread_foreach (GFunc thread_func,
1.318 + gpointer user_data);
1.319 +
1.320 +typedef enum
1.321 +{
1.322 + G_ONCE_STATUS_NOTCALLED,
1.323 + G_ONCE_STATUS_PROGRESS,
1.324 + G_ONCE_STATUS_READY
1.325 +} GOnceStatus;
1.326 +
1.327 +typedef struct _GOnce GOnce;
1.328 +struct _GOnce
1.329 +{
1.330 + volatile GOnceStatus status;
1.331 + volatile gpointer retval;
1.332 +};
1.333 +
1.334 +#define G_ONCE_INIT { G_ONCE_STATUS_NOTCALLED, NULL }
1.335 +
1.336 +IMPORT_C gpointer g_once_impl (GOnce *once, GThreadFunc func, gpointer arg);
1.337 +
1.338 +#ifdef G_ATOMIC_OP_MEMORY_BARRIER_NEEDED
1.339 +# define g_once(once, func, arg) g_once_impl ((once), (func), (arg))
1.340 +#else /* !G_ATOMIC_OP_MEMORY_BARRIER_NEEDED*/
1.341 +# define g_once(once, func, arg) \
1.342 + (((once)->status == G_ONCE_STATUS_READY) ? \
1.343 + (once)->retval : \
1.344 + g_once_impl ((once), (func), (arg)))
1.345 +#endif /* G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */
1.346 +
1.347 +/* these are some convenience macros that expand to nothing if GLib
1.348 + * was configured with --disable-threads. for using StaticMutexes,
1.349 + * you define them with G_LOCK_DEFINE_STATIC (name) or G_LOCK_DEFINE (name)
1.350 + * if you need to export the mutex. With G_LOCK_EXTERN (name) you can
1.351 + * declare such an globally defined lock. name is a unique identifier
1.352 + * for the protected varibale or code portion. locking, testing and
1.353 + * unlocking of such mutexes can be done with G_LOCK(), G_UNLOCK() and
1.354 + * G_TRYLOCK() respectively.
1.355 + */
1.356 + #ifdef __SYMBIAN32__
1.357 + #ifdef G_DEBUG_LOCKS
1.358 + #undef G_DEBUG_LOCKS
1.359 + #endif //G_DEBUG_LOCKS
1.360 + #endif //__SYMBIAN32__
1.361 +
1.362 +extern void glib_dummy_decl (void);
1.363 +#define G_LOCK_NAME(name) g__ ## name ## _lock
1.364 +#ifdef G_THREADS_ENABLED
1.365 +# define G_LOCK_DEFINE_STATIC(name) static G_LOCK_DEFINE (name)
1.366 +# define G_LOCK_DEFINE(name) \
1.367 + GStaticMutex G_LOCK_NAME (name) = G_STATIC_MUTEX_INIT
1.368 +# define G_LOCK_EXTERN(name) extern GStaticMutex G_LOCK_NAME (name)
1.369 +
1.370 +# ifdef G_DEBUG_LOCKS
1.371 +# define G_LOCK(name) G_STMT_START{ \
1.372 + g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
1.373 + "file %s: line %d (%s): locking: %s ", \
1.374 + __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
1.375 + #name); \
1.376 + g_static_mutex_lock (&G_LOCK_NAME (name)); \
1.377 + }G_STMT_END
1.378 +# define G_UNLOCK(name) G_STMT_START{ \
1.379 + g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
1.380 + "file %s: line %d (%s): unlocking: %s ", \
1.381 + __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
1.382 + #name); \
1.383 + g_static_mutex_unlock (&G_LOCK_NAME (name)); \
1.384 + }G_STMT_END
1.385 +# define G_TRYLOCK(name) \
1.386 + (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
1.387 + "file %s: line %d (%s): try locking: %s ", \
1.388 + __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
1.389 + #name), g_static_mutex_trylock (&G_LOCK_NAME (name)))
1.390 +# else /* !G_DEBUG_LOCKS */
1.391 +# define G_LOCK(name) g_static_mutex_lock (&G_LOCK_NAME (name))
1.392 +# define G_UNLOCK(name) g_static_mutex_unlock (&G_LOCK_NAME (name))
1.393 +# define G_TRYLOCK(name) g_static_mutex_trylock (&G_LOCK_NAME (name))
1.394 +# endif /* !G_DEBUG_LOCKS */
1.395 +#else /* !G_THREADS_ENABLED */
1.396 +# define G_LOCK_DEFINE_STATIC(name) extern void glib_dummy_decl (void)
1.397 +# define G_LOCK_DEFINE(name) extern void glib_dummy_decl (void)
1.398 +# define G_LOCK_EXTERN(name) extern void glib_dummy_decl (void)
1.399 +# define G_LOCK(name)
1.400 +# define G_UNLOCK(name)
1.401 +# define G_TRYLOCK(name) (TRUE)
1.402 +#endif /* !G_THREADS_ENABLED */
1.403 +
1.404 +
1.405 +G_END_DECLS
1.406 +
1.407 +#endif /* __G_THREAD_H__ */
1.408 +