* To register hooks which are executed on exit().
* Usually a wrapper for STDC atexit.
*
- * void *g_memmove(void *dest, const void *src, guint count);
+ * void g_memmove(gpointer dest, gconstpointer void *src, gulong count);
* A wrapper for STDC memmove, or an implementation, if memmove doesn't
* exist. The prototype looks like the above, give or take a const,
* or size_t.
/* Timer
*/
+
+#define G_MICROSEC 1000000
+
GTimer* g_timer_new (void);
void g_timer_destroy (GTimer *timer);
void g_timer_start (GTimer *timer);
void g_timer_reset (GTimer *timer);
gdouble g_timer_elapsed (GTimer *timer,
gulong *microseconds);
-
+void g_usleep (gulong microseconds);
/* String utility functions that modify a string argument or
* return a constant string that must not be freed.
...); /* NULL terminated */
gchar* g_strjoin (const gchar *separator,
...); /* NULL terminated */
+/* Return a duplicate of the string with \ and " characters escaped by
+ * a \. The returned string should be freed with g_free().
+ */
gchar* g_strescape (gchar *string);
+
gpointer g_memdup (gconstpointer mem,
guint byte_size);
const gchar *format,
GDate *date);
-
/* GRelation
*
* Indexed Relations. Imagine a really simple table in a
gdouble g_rand_double_range (GRand *rand,
gdouble min,
gdouble max);
-/* This might go in, if -lm is no problem for you guys
-gdouble g_rand_normal (GRand *rand,
- gdouble mean,
- gdouble standard_deviation);
-*/
void g_random_set_seed (guint32 seed);
guint32 g_random_int (void);
gdouble g_random_double (void);
gdouble g_random_double_range (gdouble min,
gdouble max);
-/* dito
-gdouble g_random_normal (gdouble mean,
- gdouble standard_deviation);
-*/
/* Prime numbers.
* <windows.h> every now and then...).
*
* You still need to include the appropriate headers to get the
- * prototypes, <io.h> or <direct.h>.
+ * prototypes, like <stdio.h>, <io.h>, <direct.h> or <process.h>.
*
* For some functions, we provide emulators in glib, which are prefixed
* with gwin_.
# define access _access
#ifdef __GNUC__
# define stat _stat
+# define fileno _fileno
#endif
+# define fstat _fstat
# define unlink _unlink
# define open _open
# define read _read
# define write _write
# define lseek _lseek
# define close _close
+# define rmdir _rmdir
# define pipe(phandles) _pipe (phandles, 4096, _O_BINARY)
# define popen _popen
# define pclose _pclose
# define fdopen _fdopen
+# define hypot _hypot
# define ftruncate(fd, size) gwin_ftruncate (fd, size)
# define opendir gwin_opendir
# define readdir gwin_readdir
/* GLib Thread support
*/
+
+typedef void (*GThreadFunc) (gpointer value);
+
+typedef enum
+{
+ G_THREAD_PRIORITY_LOW,
+ G_THREAD_PRIORITY_NORMAL,
+ G_THREAD_PRIORITY_HIGH,
+ G_THREAD_PRIORITY_URGENT,
+} GThreadPriority;
+
+typedef struct _GThread GThread;
+struct _GThread
+{
+ GThreadPriority priority;
+ gboolean bound;
+ gboolean joinable;
+};
+
typedef struct _GMutex GMutex;
typedef struct _GCond GCond;
typedef struct _GPrivate GPrivate;
typedef struct _GStaticPrivate GStaticPrivate;
+
typedef struct _GThreadFunctions GThreadFunctions;
struct _GThreadFunctions
{
- GMutex* (*mutex_new) (void);
- void (*mutex_lock) (GMutex *mutex);
- gboolean (*mutex_trylock) (GMutex *mutex);
- void (*mutex_unlock) (GMutex *mutex);
- void (*mutex_free) (GMutex *mutex);
- GCond* (*cond_new) (void);
- void (*cond_signal) (GCond *cond);
- void (*cond_broadcast) (GCond *cond);
- void (*cond_wait) (GCond *cond,
- GMutex *mutex);
- gboolean (*cond_timed_wait) (GCond *cond,
- GMutex *mutex,
- GTimeVal *end_time);
- void (*cond_free) (GCond *cond);
- GPrivate* (*private_new) (GDestroyNotify destructor);
- gpointer (*private_get) (GPrivate *private_key);
- void (*private_set) (GPrivate *private_key,
- gpointer data);
+ GMutex* (*mutex_new) (void);
+ void (*mutex_lock) (GMutex *mutex);
+ gboolean (*mutex_trylock) (GMutex *mutex);
+ void (*mutex_unlock) (GMutex *mutex);
+ void (*mutex_free) (GMutex *mutex);
+ GCond* (*cond_new) (void);
+ void (*cond_signal) (GCond *cond);
+ void (*cond_broadcast) (GCond *cond);
+ void (*cond_wait) (GCond *cond,
+ GMutex *mutex);
+ gboolean (*cond_timed_wait) (GCond *cond,
+ GMutex *mutex,
+ GTimeVal *end_time);
+ void (*cond_free) (GCond *cond);
+ GPrivate* (*private_new) (GDestroyNotify destructor);
+ gpointer (*private_get) (GPrivate *private_key);
+ void (*private_set) (GPrivate *private_key,
+ gpointer data);
+ gpointer (*thread_create) (GThreadFunc thread_func,
+ gpointer arg,
+ gulong stack_size,
+ gboolean joinable,
+ gboolean bound,
+ GThreadPriority priority);
+ void (*thread_yield) (void);
+ void (*thread_join) (gpointer thread);
+ void (*thread_exit) (void);
+ void (*thread_set_priority)(gpointer thread,
+ GThreadPriority priority);
+ gpointer (*thread_self) (void);
};
GUTILS_C_VAR GThreadFunctions g_thread_functions_for_glib_use;
(void) (private_key = \
(GPrivate*) (value)), \
(private_key, value))
+#define g_thread_yield() G_THREAD_CF (thread_yield, (void)0, ())
+#define g_thread_exit() G_THREAD_CF (thread_exit, (void)0, ())
+
+GThread* g_thread_create (GThreadFunc thread_func,
+ gpointer arg,
+ gulong stack_size,
+ gboolean joinable,
+ gboolean bound,
+ GThreadPriority priority);
+GThread* g_thread_self ();
+void g_thread_join (GThread* thread);
+void g_thread_set_priority (GThread* thread,
+ GThreadPriority priority);
+
/* GStaticMutexes can be statically initialized with the value
* G_STATIC_MUTEX_INIT, and then they can directly be used, that is
* much easier, than having to explicitly allocate the mutex before
g_mutex_trylock (g_static_mutex_get_mutex (mutex))
#define g_static_mutex_unlock(mutex) \
g_mutex_unlock (g_static_mutex_get_mutex (mutex))
+
struct _GStaticPrivate
{
guint index;
void g_static_private_set (GStaticPrivate *private_key,
gpointer data,
GDestroyNotify notify);
+gpointer g_static_private_get_for_thread (GStaticPrivate *private_key,
+ GThread *thread);
+void g_static_private_set_for_thread (GStaticPrivate *private_key,
+ GThread *thread,
+ gpointer data,
+ GDestroyNotify notify);
+#ifndef G_STATIC_REC_MUTEX_INIT
+/* if GStaticRecMutex is not just a differently initialized GStaticMutex,
+ * the following is done:
+ * This can't be done in glibconfig.h, as GStaticPrivate and gboolean
+ * are not yet known there
+ */
+typedef struct _GStaticRecMutex GStaticRecMutex;
+struct _GStaticRecMutex
+{
+ GStaticMutex mutex;
+ GStaticPrivate counter;
+};
+#define G_STATIC_REC_MUTEX_INIT { G_STATIC_MUTEX_INIT, G_STATIC_PRIVATE_INIT }
+void g_static_rec_mutex_lock (GStaticRecMutex* mutex);
+gboolean g_static_rec_mutex_trylock (GStaticRecMutex* mutex);
+void g_static_rec_mutex_unlock (GStaticRecMutex* mutex);
+#define g_static_rec_mutex_get_mutex(mutex) ((mutex)->mutex)
+#endif /* G_STATIC_REC_MUTEX_INIT */
+
+typedef struct _GStaticRWLock GStaticRWLock;
+struct _GStaticRWLock
+{
+ GStaticMutex mutex;
+ GCond *read_cond;
+ GCond *write_cond;
+ guint read_counter;
+ gboolean write;
+ guint want_to_write;
+};
+
+#define G_STATIC_RW_LOCK_INIT { G_STATIC_MUTEX_INIT, NULL, NULL, 0, FALSE, FALSE }
+
+void g_static_rw_lock_reader_lock (GStaticRWLock* lock);
+gboolean g_static_rw_lock_reader_trylock (GStaticRWLock* lock);
+void g_static_rw_lock_reader_unlock (GStaticRWLock* lock);
+void g_static_rw_lock_writer_lock (GStaticRWLock* lock);
+gboolean g_static_rw_lock_writer_trylock (GStaticRWLock* lock);
+void g_static_rw_lock_writer_unlock (GStaticRWLock* lock);
+void g_static_rw_lock_free (GStaticRWLock* lock);
/* these are some convenience macros that expand to nothing if GLib
* was configured with --disable-threads. for using StaticMutexes,