root/trunk/dep/include/zthread/RecursiveMutex.h @ 2

Revision 2, 4.2 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (c) 2005, Eric Crahen
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
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.
20 *
21 */
22
23#ifndef __ZTRECURSIVEMUTEX_H__
24#define __ZTRECURSIVEMUTEX_H__
25
26#include "zthread/Lockable.h"
27#include "zthread/NonCopyable.h"
28
29namespace ZThread { 
30 
31  class RecursiveMutexImpl;
32
33  /**
34   * @class RecursiveMutex
35   *
36   * @author Eric Crahen <http://www.code-foo.com>
37   * @date <2003-07-16T17:51:33-0400>
38   * @version 2.2.1
39   *
40   * A RecursiveMutex is a recursive, MUTual EXclusion Lockable object. It is 
41   * recursive because it can be acquire()d and release()d more than once
42   * by the same thread, instead of causing a Deadlock_Exception.
43   *
44   * @see Mutex
45   * @see Guard
46   *
47   * <b>Scheduling</b>
48   *
49   * Threads competing to acquire() a Mutex are granted access in FIFO order.
50   *
51   * <b>Error Checking</b>
52   *
53   * A Mutex will throw an InvalidOp_Exception if an attempt to release() a Mutex is
54   * made from the context of a thread that does not currently own that Mutex.
55   */
56  class ZTHREAD_API RecursiveMutex : public Lockable, private NonCopyable {
57 
58    RecursiveMutexImpl* _impl;
59 
60  public:
61 
62    //! Create a new RecursiveMutex.
63    RecursiveMutex();
64
65    //! Destroy this RecursiveMutex.
66    virtual ~RecursiveMutex();
67
68    /**
69     * Acquire a RecursiveMutex, possibly blocking until the the current owner of the
70     * releases it or until an exception is thrown.
71     *
72     * Only one thread may acquire the RecursiveMutex at any given time.
73     * The same thread may acquire a RecursiveMutex multiple times.
74     *
75     * @exception Interrupted_Exception thrown when the calling thread is interrupted.
76     *            A thread may be interrupted at any time, prematurely ending any wait.
77     *
78     * @post the calling thread successfully acquire ed RecursiveMutex only if no exception
79     *       was thrown.
80     *
81     * @see Lockable::acquire()
82     */
83    virtual void acquire(); 
84
85    /**
86     * Acquire a RecursiveMutex, possibly blocking until the the current owner
87     * releases it, until an exception is thrown or until the given amount
88     * of time expires.
89     *
90     * Only one thread may acquire the RecursiveMutex at any given time.
91     * The same thread may acquire a RecursiveMutex multiple times.
92     *
93     * @param timeout maximum amount of time (milliseconds) this method could block
94     * @return
95     * - <em>true</em> if the lock was acquired
96     * - <em>false</em> if the lock was acquired
97     *
98     * @exception Interrupted_Exception thrown when the calling thread is interrupted.
99     *            A thread may be interrupted at any time, prematurely ending any wait.
100     *
101     * @post the calling thread successfully acquired RecursiveMutex only if no exception
102     *       was thrown.
103     *
104     * @see Lockable::tryAcquire(unsigned long timeout)
105     */
106    virtual bool tryAcquire(unsigned long timeout);
107
108
109    /**
110     * Release exclusive access. No safety or state checks are performed.
111     *
112     * @pre This should not be called more times than the acquire() method was
113     *      called.
114     *
115     * @see Lockable::release()
116     */
117    virtual void release();
118   
119  }; 
120 
121} // namespace ZThread
122
123#endif // __ZTRECURSIVEMUTEX_H__
Note: See TracBrowser for help on using the browser.