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