11cb0ef41Sopenharmony_ci/* Copyright (c) 2013, Sony Mobile Communications AB 21cb0ef41Sopenharmony_ci * Copyright (c) 2012, Google Inc. 31cb0ef41Sopenharmony_ci All rights reserved. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci Redistribution and use in source and binary forms, with or without 61cb0ef41Sopenharmony_ci modification, are permitted provided that the following conditions are 71cb0ef41Sopenharmony_ci met: 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci * Redistributions of source code must retain the above copyright 101cb0ef41Sopenharmony_ci notice, this list of conditions and the following disclaimer. 111cb0ef41Sopenharmony_ci * Redistributions in binary form must reproduce the above 121cb0ef41Sopenharmony_ci copyright notice, this list of conditions and the following disclaimer 131cb0ef41Sopenharmony_ci in the documentation and/or other materials provided with the 141cb0ef41Sopenharmony_ci distribution. 151cb0ef41Sopenharmony_ci * Neither the name of Google Inc. nor the names of its 161cb0ef41Sopenharmony_ci contributors may be used to endorse or promote products derived from 171cb0ef41Sopenharmony_ci this software without specific prior written permission. 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 201cb0ef41Sopenharmony_ci "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 211cb0ef41Sopenharmony_ci LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 221cb0ef41Sopenharmony_ci A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 231cb0ef41Sopenharmony_ci OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 241cb0ef41Sopenharmony_ci SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 251cb0ef41Sopenharmony_ci LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 261cb0ef41Sopenharmony_ci DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 271cb0ef41Sopenharmony_ci THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 281cb0ef41Sopenharmony_ci (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 291cb0ef41Sopenharmony_ci OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 301cb0ef41Sopenharmony_ci*/ 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci/* Android versions < 4.1 have a broken pthread_sigmask. */ 331cb0ef41Sopenharmony_ci#include "uv-common.h" 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci#include <errno.h> 361cb0ef41Sopenharmony_ci#include <pthread.h> 371cb0ef41Sopenharmony_ci#include <signal.h> 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ciint uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset) { 401cb0ef41Sopenharmony_ci static int workaround; 411cb0ef41Sopenharmony_ci int err; 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci if (uv__load_relaxed(&workaround)) { 441cb0ef41Sopenharmony_ci return sigprocmask(how, set, oset); 451cb0ef41Sopenharmony_ci } else { 461cb0ef41Sopenharmony_ci err = pthread_sigmask(how, set, oset); 471cb0ef41Sopenharmony_ci if (err) { 481cb0ef41Sopenharmony_ci if (err == EINVAL && sigprocmask(how, set, oset) == 0) { 491cb0ef41Sopenharmony_ci uv__store_relaxed(&workaround, 1); 501cb0ef41Sopenharmony_ci return 0; 511cb0ef41Sopenharmony_ci } else { 521cb0ef41Sopenharmony_ci return -1; 531cb0ef41Sopenharmony_ci } 541cb0ef41Sopenharmony_ci } 551cb0ef41Sopenharmony_ci } 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci return 0; 581cb0ef41Sopenharmony_ci} 59