12581d4aaSFrançois Tigeot /* 2303d234dSFrançois Tigeot * Copyright (c) 2014-2015 François Tigeot 32581d4aaSFrançois Tigeot * All rights reserved. 42581d4aaSFrançois Tigeot * 52581d4aaSFrançois Tigeot * Redistribution and use in source and binary forms, with or without 62581d4aaSFrançois Tigeot * modification, are permitted provided that the following conditions 72581d4aaSFrançois Tigeot * are met: 82581d4aaSFrançois Tigeot * 1. Redistributions of source code must retain the above copyright 92581d4aaSFrançois Tigeot * notice unmodified, this list of conditions, and the following 102581d4aaSFrançois Tigeot * disclaimer. 112581d4aaSFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright 122581d4aaSFrançois Tigeot * notice, this list of conditions and the following disclaimer in the 132581d4aaSFrançois Tigeot * documentation and/or other materials provided with the distribution. 142581d4aaSFrançois Tigeot * 152581d4aaSFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 162581d4aaSFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 172581d4aaSFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 182581d4aaSFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 192581d4aaSFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 202581d4aaSFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 212581d4aaSFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 222581d4aaSFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 232581d4aaSFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 242581d4aaSFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 252581d4aaSFrançois Tigeot */ 262581d4aaSFrançois Tigeot 272581d4aaSFrançois Tigeot #ifndef _LINUX_MUTEX_H_ 282581d4aaSFrançois Tigeot #define _LINUX_MUTEX_H_ 292581d4aaSFrançois Tigeot 302581d4aaSFrançois Tigeot #include <sys/lock.h> 312581d4aaSFrançois Tigeot 322581d4aaSFrançois Tigeot #define mutex_is_locked(lock) (lockcount(lock) != 0) 332581d4aaSFrançois Tigeot 34303d234dSFrançois Tigeot #define mutex_lock(lock) lockmgr(lock, LK_EXCLUSIVE) 35303d234dSFrançois Tigeot #define mutex_unlock(lock) lockmgr(lock, LK_RELEASE) 36303d234dSFrançois Tigeot 378634e73aSFrançois Tigeot #define mutex_trylock(lock) lockmgr(lock, LK_EXCLUSIVE|LK_NOWAIT) 388634e73aSFrançois Tigeot 3917bbf32eSFrançois Tigeot static inline int 4017bbf32eSFrançois Tigeot mutex_lock_interruptible(struct lock *lock) 4117bbf32eSFrançois Tigeot { 42*beb32878SFrançois Tigeot if (lockmgr(lock, LK_EXCLUSIVE|LK_SLEEPFAIL|LK_PCATCH)) 4317bbf32eSFrançois Tigeot return -EINTR; 4417bbf32eSFrançois Tigeot 4517bbf32eSFrançois Tigeot return 0; 4617bbf32eSFrançois Tigeot } 478634e73aSFrançois Tigeot 482581d4aaSFrançois Tigeot #endif /* _LINUX_MUTEX_H_ */ 49