/* * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE.
*/
/* * Initialized data and out-of-line functions to support atomic_ops.h * go here. Currently this is needed only for pthread-based atomics * emulation, or for compare-and-swap emulation. * Pthreads emulation isn't useful on a native Windows platform, and * cas emulation is not needed. Thus we skip this on Windows.
*/
#ifdefined(HAVE_CONFIG_H) # include "config.h" #endif
#if (defined(__hexagon__) || defined(__native_client__)) \
&& !defined(AO_USE_NO_SIGNALS) && !defined(AO_USE_NANOSLEEP) /* Hexagon QuRT does not have sigprocmask (but Hexagon does not need */ /* emulation, so it is OK not to bother about signals blocking). */ /* Since NaCl is not recognized by configure yet, we do it here. */ # define AO_USE_NO_SIGNALS # define AO_USE_NANOSLEEP #endif
#ifndef AO_NO_PTHREADS # include <pthread.h> #endif
#ifndef AO_USE_NO_SIGNALS # include <signal.h> #endif
#ifdef AO_USE_NANOSLEEP /* This requires _POSIX_TIMERS feature. */ # include <sys/time.h> # include <time.h> #elifdefined(AO_USE_WIN32_PTHREADS) # include <windows.h> /* for Sleep() */ #elifdefined(_HPUX_SOURCE) # include <sys/time.h> #else # include <sys/select.h> #endif
#ifndef AO_HAVE_double_t # include "atomic_ops/sysdeps/standard_ao_double_t.h" #endif
/* * Out of line compare-and-swap emulation based on test and set. * * We use a small table of locks for different compare_and_swap locations. * Before we update perform a compare-and-swap, we grab the corresponding * lock. Different locations may hash to the same lock, but since we * never acquire more than one lock at a time, this can't deadlock. * We explicitly disable signals while we perform this operation. * * TODO: Probably also support emulation based on Lamport * locks, since we may not have test_and_set either.
*/ #define AO_HASH_SIZE 16
AO_INLINE void block_all_signals(sigset_t *old_sigs_ptr)
{ if (AO_EXPECT_FALSE(!AO_load_acquire(&initialized)))
{
lock(&init_lock); if (!initialized)
sigfillset(&all_sigs);
unlock(&init_lock);
AO_store_release(&initialized, 1);
}
sigprocmask(SIG_BLOCK, &all_sigs, old_sigs_ptr); /* Neither sigprocmask nor pthread_sigmask is 100% */ /* guaranteed to work here. Sigprocmask is not */ /* guaranteed be thread safe, and pthread_sigmask */ /* is not async-signal-safe. Under linuxthreads, */ /* sigprocmask may block some pthreads-internal */ /* signals. So long as we do that for short periods, */ /* we should be OK. */
} #endif/* !AO_USE_NO_SIGNALS */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.