2
* arch-tag: Implementation of atomic integers for Rhythmbox
3
* Copyright (C) 2002, 2003 Red Hat, Inc.
4
* Copyright (C) 2003 CodeFactory AB
6
* Licensed under the Academic Free License version 1.2
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
#include "rb-atomic.h"
27
#error "rb-atomic shouldn't be compiled with GTK+ 2.4, please file a bug on bugzilla.gnome.org"
30
#ifdef RB_USE_ATOMIC_INT_486
31
/* Taken from CVS version 1.7 of glibc's sysdeps/i386/i486/atomicity.h */
32
/* Since the asm stuff here is gcc-specific we go ahead and use "inline" also */
34
atomic_exchange_and_add (RBAtomic *atomic,
37
register gint32 result;
39
__asm__ __volatile__ ("lock; xaddl %0,%1"
40
: "=r" (result), "=m" (atomic->value)
41
: "0" (val), "m" (atomic->value));
45
GStaticMutex rb_atomic_mutex = G_STATIC_MUTEX_INIT;
49
* Atomically increments an integer
51
* @param atomic pointer to the integer to increment
52
* @returns the value before incrementing
54
* @todo implement arch-specific faster atomic ops
57
rb_atomic_inc (RBAtomic *atomic)
59
#ifdef RB_USE_ATOMIC_INT_486
60
return atomic_exchange_and_add (atomic, 1);
63
g_static_mutex_lock (&rb_atomic_mutex);
66
g_static_mutex_unlock (&rb_atomic_mutex);
72
* Atomically decrement an integer
74
* @param atomic pointer to the integer to decrement
75
* @returns the value before decrementing
77
* @todo implement arch-specific faster atomic ops
80
rb_atomic_dec (RBAtomic *atomic)
82
#ifdef RB_USE_ATOMIC_INT_486
83
return atomic_exchange_and_add (atomic, -1);
87
g_static_mutex_lock (&rb_atomic_mutex);
90
g_static_mutex_unlock (&rb_atomic_mutex);
95
#endif /* HAVE_GTK_2_3 */