1290245Sgonzo/** 2290245Sgonzo * Copyright (c) 2010-2012 Broadcom. All rights reserved. 3290245Sgonzo * 4290245Sgonzo * Redistribution and use in source and binary forms, with or without 5290245Sgonzo * modification, are permitted provided that the following conditions 6290245Sgonzo * are met: 7290245Sgonzo * 1. Redistributions of source code must retain the above copyright 8290245Sgonzo * notice, this list of conditions, and the following disclaimer, 9290245Sgonzo * without modification. 10290245Sgonzo * 2. Redistributions in binary form must reproduce the above copyright 11290245Sgonzo * notice, this list of conditions and the following disclaimer in the 12290245Sgonzo * documentation and/or other materials provided with the distribution. 13290245Sgonzo * 3. The names of the above-listed copyright holders may not be used 14290245Sgonzo * to endorse or promote products derived from this software without 15290245Sgonzo * specific prior written permission. 16290245Sgonzo * 17290245Sgonzo * ALTERNATIVELY, this software may be distributed under the terms of the 18290245Sgonzo * GNU General Public License ("GPL") version 2, as published by the Free 19290245Sgonzo * Software Foundation. 20290245Sgonzo * 21290245Sgonzo * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 22290245Sgonzo * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 23290245Sgonzo * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24290245Sgonzo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 25290245Sgonzo * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26290245Sgonzo * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27290245Sgonzo * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28290245Sgonzo * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29290245Sgonzo * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30290245Sgonzo * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31290245Sgonzo * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32290245Sgonzo */ 33290245Sgonzo 34290245Sgonzo#ifndef VCHIQ_KILLABLE_H 35290245Sgonzo#define VCHIQ_KILLABLE_H 36290245Sgonzo 37290245Sgonzo#ifdef notyet 38290245Sgonzo#include <linux/mutex.h> 39290245Sgonzo#include <linux/semaphore.h> 40290245Sgonzo 41290245Sgonzo#define SHUTDOWN_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | sigmask(SIGQUIT) | sigmask(SIGTRAP) | sigmask(SIGSTOP) | sigmask(SIGCONT)) 42290245Sgonzo 43290245Sgonzostatic inline int __must_check down_interruptible_killable(struct semaphore *sem) 44290245Sgonzo{ 45290245Sgonzo /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */ 46290245Sgonzo int ret; 47290245Sgonzo sigset_t blocked, oldset; 48290245Sgonzo siginitsetinv(&blocked, SHUTDOWN_SIGS); 49290245Sgonzo sigprocmask(SIG_SETMASK, &blocked, &oldset); 50290245Sgonzo ret = down_interruptible(sem); 51290245Sgonzo sigprocmask(SIG_SETMASK, &oldset, NULL); 52290245Sgonzo return ret; 53290245Sgonzo} 54290245Sgonzo#define down_interruptible down_interruptible_killable 55290245Sgonzo 56290245Sgonzo 57290245Sgonzostatic inline int __must_check mutex_lock_interruptible_killable(struct mutex *lock) 58290245Sgonzo{ 59290245Sgonzo /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */ 60290245Sgonzo int ret; 61290245Sgonzo sigset_t blocked, oldset; 62290245Sgonzo siginitsetinv(&blocked, SHUTDOWN_SIGS); 63290245Sgonzo sigprocmask(SIG_SETMASK, &blocked, &oldset); 64290245Sgonzo ret = mutex_lock_interruptible(lock); 65290245Sgonzo sigprocmask(SIG_SETMASK, &oldset, NULL); 66290245Sgonzo return ret; 67290245Sgonzo} 68290245Sgonzo#define mutex_lock_interruptible mutex_lock_interruptible_killable 69290245Sgonzo 70290245Sgonzo#endif 71290245Sgonzo 72290245Sgonzo#endif 73