1 /* 2 * barrier -- mouse and keyboard sharing utility 3 * Copyright (C) 2012-2016 Symless Ltd. 4 * Copyright (C) 2002 Chris Schoeneman 5 * 6 * This package is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * found in the file LICENSE that should have accompanied this file. 9 * 10 * This package is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #pragma once 20 21 #include "arch/IArchMultithread.h" 22 23 //! Mutual exclusion 24 /*! 25 A non-recursive mutual exclusion object. Only one thread at a time can 26 hold a lock on a mutex. Any thread that attempts to lock a locked mutex 27 will block until the mutex is unlocked. At that time, if any threads are 28 blocked, exactly one waiting thread will acquire the lock and continue 29 running. A thread may not lock a mutex it already owns the lock on; if 30 it tries it will deadlock itself. 31 */ 32 class Mutex { 33 public: 34 Mutex(); 35 //! Equivalent to default c'tor 36 /*! 37 Copy c'tor doesn't copy anything. It just makes it possible to 38 copy objects that contain a mutex. 39 */ 40 Mutex(const Mutex&); 41 ~Mutex(); 42 43 //! @name manipulators 44 //@{ 45 46 //! Does nothing 47 /*! 48 This does nothing. It just makes it possible to assign objects 49 that contain a mutex. 50 */ 51 Mutex& operator=(const Mutex&); 52 53 //@} 54 //! @name accessors 55 //@{ 56 57 //! Lock the mutex 58 /*! 59 Locks the mutex, which must not have been previously locked by the 60 calling thread. This blocks if the mutex is already locked by another 61 thread. 62 63 (cancellation point) 64 */ 65 void lock() const; 66 67 //! Unlock the mutex 68 /*! 69 Unlocks the mutex, which must have been previously locked by the 70 calling thread. 71 */ 72 void unlock() const; 73 74 //@} 75 76 private: 77 friend class CondVarBase; 78 ArchMutex m_mutex; 79 }; 80