Path: blob/master/Utilities/cmlibuv/src/unix/pthread-fixes.c
3156 views
/* Copyright (c) 2013, Sony Mobile Communications AB1* Copyright (c) 2012, Google Inc.2All rights reserved.34Redistribution and use in source and binary forms, with or without5modification, are permitted provided that the following conditions are6met:78* Redistributions of source code must retain the above copyright9notice, this list of conditions and the following disclaimer.10* Redistributions in binary form must reproduce the above11copyright notice, this list of conditions and the following disclaimer12in the documentation and/or other materials provided with the13distribution.14* Neither the name of Google Inc. nor the names of its15contributors may be used to endorse or promote products derived from16this software without specific prior written permission.1718THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR21A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT22OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,23SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT24LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,25DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY26THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE28OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.29*/3031/* Android versions < 4.1 have a broken pthread_sigmask. */32#include "uv-common.h"3334#include <errno.h>35#include <pthread.h>36#include <signal.h>3738int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset) {39static int workaround;40int err;4142if (uv__load_relaxed(&workaround)) {43return sigprocmask(how, set, oset);44} else {45err = pthread_sigmask(how, set, oset);46if (err) {47if (err == EINVAL && sigprocmask(how, set, oset) == 0) {48uv__store_relaxed(&workaround, 1);49return 0;50} else {51return -1;52}53}54}5556return 0;57}585960