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 __ZTFASTMUTEX_H__
24 #define __ZTFASTMUTEX_H__
26 #include "zthread/Lockable.h"
27 #include "zthread/NonCopyable.h"
35 * @author Eric Crahen <http://www.code-foo.com>
36 * @date <2003-07-19T18:45:39-0400>
39 * A FastMutex is a small fast implementation of a non-recursive, mutually exclusive
40 * Lockable object. This implementation is a bit faster than the other Mutex classes
41 * as it involved the least overhead. However, this slight increase in speed is
42 * gained by sacrificing the robustness provided by the other classes.
44 * A FastMutex has the useful property of not being interruptable; that is to say
45 * that acquire() and tryAcquire() will not throw Interrupted_Exceptions.
51 * Scheduling is left to the operating systems and may vary.
53 * <b>Error Checking</b>
55 * No error checking is performed, this means there is the potential for deadlock.
57 class ZTHREAD_API FastMutex
: public Lockable
, private NonCopyable
{
63 //! Create a FastMutex
66 //! Destroy a FastMutex
70 * Acquire exclusive access to the mutex. The calling thread will block until the
71 * lock can be acquired. No safety or state checks are performed.
73 * @pre The calling thread should <i>not</i> have previously acquired this lock.
74 * Deadlock will result if the same thread attempts to acquire the mutex more
77 * @post The calling thread obtains the lock successfully if no exception is thrown.
78 * @exception Interrupted_Exception never thrown
80 virtual void acquire();
83 * Release exclusive access. No safety or state checks are performed.
85 * @pre the caller should have previously acquired this lock
87 virtual void release();
90 * Try to acquire exclusive access to the mutex. The calling thread will block until the
91 * lock can be acquired. No safety or state checks are performed.
93 * @pre The calling thread should <i>not</i> have previously acquired this lock.
94 * Deadlock will result if the same thread attempts to acquire the mutex more
97 * @param timeout unused
99 * - <em>true</em> if the lock was acquired
100 * - <em>false</em> if the lock was acquired
102 * @post The calling thread obtains the lock successfully if no exception is thrown.
103 * @exception Interrupted_Exception never thrown
105 virtual bool tryAcquire(unsigned long timeout
);
111 #endif // __ZTFASTMUTEX_H__