12581d4aaSFrançois Tigeot /* 2*c6002f72SFrançois Tigeot * Copyright (c) 2014-2019 François Tigeot <ftigeot@wolfpond.org> 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 30d6aa1cc5SFrançois Tigeot #include <asm/current.h> 31d6aa1cc5SFrançois Tigeot #include <linux/list.h> 32961a6190SFrançois Tigeot #include <linux/lockdep.h> 33d6aa1cc5SFrançois Tigeot #include <linux/atomic.h> 34*c6002f72SFrançois Tigeot #include <asm/processor.h> 352581d4aaSFrançois Tigeot 363b6a19b2SMatthew Dillon #define mutex_is_locked(lock) (lockinuse(lock)) 372581d4aaSFrançois Tigeot 38303d234dSFrançois Tigeot #define mutex_lock(lock) lockmgr(lock, LK_EXCLUSIVE) 39303d234dSFrançois Tigeot #define mutex_unlock(lock) lockmgr(lock, LK_RELEASE) 40303d234dSFrançois Tigeot 413558045eSSascha Wildner #define mutex_trylock(lock) lockmgr_try(lock, LK_EXCLUSIVE) 428634e73aSFrançois Tigeot 4317bbf32eSFrançois Tigeot static inline int 4417bbf32eSFrançois Tigeot mutex_lock_interruptible(struct lock *lock) 4517bbf32eSFrançois Tigeot { 46beb32878SFrançois Tigeot if (lockmgr(lock, LK_EXCLUSIVE|LK_SLEEPFAIL|LK_PCATCH)) 4717bbf32eSFrançois Tigeot return -EINTR; 4817bbf32eSFrançois Tigeot 4917bbf32eSFrançois Tigeot return 0; 5017bbf32eSFrançois Tigeot } 518634e73aSFrançois Tigeot 52115eefbdSFrançois Tigeot #define DEFINE_MUTEX(mutex) \ 53115eefbdSFrançois Tigeot struct lock mutex; \ 54115eefbdSFrançois Tigeot LOCK_SYSINIT(mutex, &mutex, "lmutex", LK_CANRECURSE) 55115eefbdSFrançois Tigeot 5639cfddd2SFrançois Tigeot static inline void 5739cfddd2SFrançois Tigeot mutex_destroy(struct lock *mutex) 5839cfddd2SFrançois Tigeot { 5939cfddd2SFrançois Tigeot lockuninit(mutex); 6039cfddd2SFrançois Tigeot } 6139cfddd2SFrançois Tigeot 622581d4aaSFrançois Tigeot #endif /* _LINUX_MUTEX_H_ */ 63