mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-02 15:46:17 +01:00
parent
7211f7f8eb
commit
37716bd00a
19
configure.in
19
configure.in
@ -2412,7 +2412,22 @@ dnl ********************************
|
||||
|
||||
AC_MSG_CHECKING([whether to use assembler code for atomic operations])
|
||||
|
||||
glib_cv_gcc_has_builtin_atomic_operations=no
|
||||
if test x"$GCC" = xyes; then
|
||||
AC_MSG_CHECKING([whether GCC supports build-in atomic intrinsics])
|
||||
AC_TRY_LINK([],
|
||||
[int i;
|
||||
__sync_synchronize ();
|
||||
__sync_bool_compare_and_swap (&i, 0, 1);
|
||||
__sync_fetch_and_add (&i, 1);
|
||||
],
|
||||
[glib_cv_gcc_has_builtin_atomic_operations=yes],
|
||||
[glib_cv_gcc_has_builtin_atomic_operations=no])
|
||||
|
||||
AC_MSG_RESULT($glib_cv_gcc_has_builtin_atomic_operations)
|
||||
if test $glib_cv_gcc_has_builtin_atomic_operations = yes; then
|
||||
glib_memory_barrier_needed=yes
|
||||
else
|
||||
case $host_cpu in
|
||||
i386)
|
||||
AC_MSG_RESULT([none])
|
||||
@ -2509,6 +2524,7 @@ if test x"$GCC" = xyes; then
|
||||
glib_memory_barrier_needed=yes
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
if test $glib_native_win32 = yes; then
|
||||
# For Windows but not using gcc. No barriers needed then either.
|
||||
@ -2516,6 +2532,9 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(HAVE_GCC_BUILTINS_FOR_ATOMIC_OPERATIONS,
|
||||
[test $glib_cv_gcc_has_builtin_atomic_operations = yes])
|
||||
|
||||
dnl ****************************************
|
||||
dnl *** GLib POLL* compatibility defines ***
|
||||
dnl ****************************************
|
||||
|
@ -19,6 +19,12 @@ gregex_c =
|
||||
gregex_h =
|
||||
endif
|
||||
|
||||
if HAVE_GCC_BUILTINS_FOR_ATOMIC_OPERATIONS
|
||||
gatomic_c = gatomic-gcc.c
|
||||
else
|
||||
gatomic_c = gatomic.c
|
||||
endif
|
||||
|
||||
SUBDIRS = libcharset $(PRINTF_SUBDIR) $(MAYBE_PCRE) update-pcre . tests
|
||||
|
||||
DIST_SUBDIRS = libcharset gnulib pcre update-pcre tests
|
||||
@ -100,7 +106,7 @@ uninstall-ms-lib:
|
||||
libglib_2_0_la_SOURCES = \
|
||||
garray.c \
|
||||
gasyncqueue.c \
|
||||
gatomic.c \
|
||||
$(gatomic_c) \
|
||||
gbacktrace.c \
|
||||
gbase64.c \
|
||||
gbookmarkfile.c \
|
||||
|
92
glib/gatomic-gcc.c
Normal file
92
glib/gatomic-gcc.c
Normal file
@ -0,0 +1,92 @@
|
||||
/* GLIB - Library of useful routines for C programming
|
||||
* gatomic-gcc.c: atomic operations using GCC builtins.
|
||||
* Copyright (C) 2009 Hiroyuki Ikezoe
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "glib.h"
|
||||
#include "galias.h"
|
||||
|
||||
gint
|
||||
g_atomic_int_exchange_and_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
|
||||
gint val)
|
||||
{
|
||||
return __sync_fetch_and_add (atomic, val);
|
||||
}
|
||||
|
||||
void
|
||||
g_atomic_int_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
|
||||
gint val)
|
||||
{
|
||||
__sync_fetch_and_add (atomic, val);
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_atomic_int_compare_and_exchange (volatile gint G_GNUC_MAY_ALIAS *atomic,
|
||||
gint oldval,
|
||||
gint newval)
|
||||
{
|
||||
return __sync_bool_compare_and_swap (atomic, oldval, newval);
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_atomic_pointer_compare_and_exchange (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
|
||||
gpointer oldval,
|
||||
gpointer newval)
|
||||
{
|
||||
return __sync_bool_compare_and_swap (atomic, oldval, newval);
|
||||
}
|
||||
|
||||
void
|
||||
_g_atomic_thread_init (void)
|
||||
{
|
||||
}
|
||||
|
||||
gint
|
||||
(g_atomic_int_get) (volatile gint G_GNUC_MAY_ALIAS *atomic)
|
||||
{
|
||||
__sync_synchronize ();
|
||||
return *atomic;
|
||||
}
|
||||
|
||||
void
|
||||
(g_atomic_int_set) (volatile gint G_GNUC_MAY_ALIAS *atomic,
|
||||
gint newval)
|
||||
{
|
||||
*atomic = newval;
|
||||
__sync_synchronize ();
|
||||
}
|
||||
|
||||
gpointer
|
||||
(g_atomic_pointer_get) (volatile gpointer G_GNUC_MAY_ALIAS *atomic)
|
||||
{
|
||||
__sync_synchronize ();
|
||||
return *atomic;
|
||||
}
|
||||
|
||||
void
|
||||
(g_atomic_pointer_set) (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
|
||||
gpointer newval)
|
||||
{
|
||||
*atomic = newval;
|
||||
__sync_synchronize ();
|
||||
}
|
||||
|
||||
#define __G_ATOMIC_C__
|
||||
#include "galiasdef.c"
|
Loading…
Reference in New Issue
Block a user