Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / include / zthread / FastRecursiveMutex.h
bloba30f4b53aa743466bf29665ef828d73aaf1a243f
1 /*
2 * Copyright (c) 2005, Eric Crahen
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is furnished
9 * to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef __ZTFASTRECURSIVEMUTEX_H__
24 #define __ZTFASTRECURSIVEMUTEX_H__
26 #include "zthread/Lockable.h"
27 #include "zthread/NonCopyable.h"
29 namespace ZThread {
31 class FastRecursiveLock;
33 /**
34 * @class FastRecursiveMutex
36 * @author Eric Crahen <http://www.code-foo.com>
37 * @date <2003-07-19T19:00:25-0400>
38 * @version 2.2.0
40 * A FastRecursiveMutex is a small fast implementation of a recursive, mutally exclusive
41 * Lockable object. This implementation is a bit faster than the other Mutex classes
42 * as it involved the least overhead. However, this slight increase in speed is
43 * gained by sacrificing the robustness provided by the other classes.
45 * A FastRecursiveMutex has the useful property of not being interruptable; that is to say
46 * that acquire() and tryAcquire() will not throw Interrupted_Exceptions.
48 * @see RecursiveMutex
50 * <b>Scheduling</b>
52 * Scheduling is left to the operating systems and may vary.
54 * <b>Error Checking</b>
56 * No error checking is performed, this means there is the potential for deadlock.
57 */
58 class ZTHREAD_API FastRecursiveMutex : public Lockable, private NonCopyable {
60 FastRecursiveLock* _lock;
62 public:
64 //! Create a new FastRecursiveMutex
65 FastRecursiveMutex();
67 //! Destroy this FastRecursiveMutex
68 virtual ~FastRecursiveMutex();
70 /**
71 * Acquire exclusive access to the mutex. The calling thread will block until the
72 * lock can be acquired. No safety or state checks are performed. The calling thread
73 * may acquire the mutex nore than once.
75 * @post The calling thread obtains the lock successfully if no exception is thrown.
76 * @exception Interrupted_Exception never thrown
78 virtual void acquire();
80 /**
81 * Release access. No safety or state checks are performed.
83 * @pre the caller should have previously acquired this lock at least once.
85 virtual void release();
87 /**
88 * Try to acquire exclusive access to the mutex. The calling thread will block until the
89 * lock can be acquired. No safety or state checks are performed. The calling thread
90 * may acquire the mutex more than once.
92 * @param timeout unused
93 * @return
94 * - <em>true</em> if the lock was acquired
95 * - <em>false</em> if the lock was acquired
97 * @post The calling thread obtains the lock successfully if no exception is thrown.
98 * @exception Interrupted_Exception never thrown
100 virtual bool tryAcquire(unsigned long timeout);
104 } // namespace ZThread
106 #endif // __ZTFASTRECURSIVEMUTEX_H__