gatomic.h

Go to the documentation of this file.
00001 /* GLIB - Library of useful routines for C programming
00002  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
00003  *
00004  * g_atomic_*: atomic operations.
00005  * Copyright (C) 2003 Sebastian Wilhelmi
00006  * Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021  * Boston, MA 02111-1307, USA.
00022  */
00023  
00024 /*
00025  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
00026  * file for a list of people on the GLib Team.  See the ChangeLog
00027  * files for a list of changes.  These files are distributed with
00028  * GLib at ftp://ftp.gtk.org/pub/gtk/.
00029  */
00030  
00031 #ifndef __G_ATOMIC_H__
00032 #define __G_ATOMIC_H__
00033  
00034 #include <_ansi.h> 
00035 #include <glib/gtypes.h>
00036 
00037 G_BEGIN_DECLS
00038  
00039 IMPORT_C gint     g_atomic_int_exchange_and_add         (volatile gint     *atomic, 
00040                                                 gint               val);
00041 IMPORT_C void     g_atomic_int_add                      (volatile gint     *atomic, 
00042                                                 gint               val);
00043 IMPORT_C gboolean g_atomic_int_compare_and_exchange     (volatile gint     *atomic, 
00044                                                 gint               oldval,
00045                                                 gint               newval);
00046 IMPORT_C gboolean g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, 
00047                                                 gpointer           oldval, 
00048                                                 gpointer           newval);
00049 
00050 IMPORT_C gint     g_atomic_int_get                      (volatile  gint     *atomic);
00051 IMPORT_C void     g_atomic_int_set                      (volatile gint            *atomic,
00052                                                 gint               newval);
00053 IMPORT_C gpointer g_atomic_pointer_get                  (volatile gpointer *atomic);
00054 IMPORT_C void     g_atomic_pointer_set                  (volatile gpointer *atomic,
00055                                                 gpointer           newval);
00056 
00057 #ifndef G_ATOMIC_OP_MEMORY_BARRIER_NEEDED
00058 # define g_atomic_int_get(atomic)               (*(atomic))
00059 # define g_atomic_int_set(atomic, newval)       ((void) (*(atomic) = (newval)))
00060 # define g_atomic_pointer_get(atomic)           (*(atomic))
00061 # define g_atomic_pointer_set(atomic, newval)   ((void) (*(atomic) = (newval)))
00062 #endif /* G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */
00063 
00064 #define g_atomic_int_inc(atomic) (g_atomic_int_add ((atomic), 1))
00065 #define g_atomic_int_dec_and_test(atomic)                               \
00066   (g_atomic_int_exchange_and_add ((atomic), -1) == 1)
00067 
00068 G_END_DECLS
00069  
00070 #endif /* __G_ATOMIC_H__ */

Copyright © Nokia Corporation 2001-2008
Back to top