2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 // ILockable.h (Cortex)
34 // Simple interface by which an object's locking capabilites
35 // are declared/exposed. Includes support for multiple lock
36 // modes (read/write) which objects can choose to support if
39 // * IMPLEMENTATION/USAGE
40 // Implementations are expected to follow the rules described
41 // in the MultiLock documentation (Be Developer Newsletter
42 // Vol.2 #36, Sep '98). In brief: write locks can be nested
43 // (a thread holding the write lock may nest as many read or
44 // or write locks as it likes) but read locks may not (only one
47 // If using a simple BLocker to implement, ignore the mode.
50 // e.moon 26jul99 Moved Autolock into this file to
51 // resolve header-naming conflict.
52 // e.moon 7jul99 Reworked slightly for Cortex.
53 // e.moon 13apr99 Begun (beDub)
55 #ifndef __ILockable_H__
56 #define __ILockable_H__
60 #include "cortex_defs.h"
61 __BEGIN_CORTEX_NAMESPACE
63 // the locking interface
68 virtual ~ILockable() { }
78 bigtime_t timeout
=B_INFINITE_TIMEOUT
)=0;
83 virtual bool isLocked(
84 lock_t type
=WRITE
) const=0;
89 // a simple hands-free lock helper
92 public: // *** ctor/dtor
99 Autolock(ILockable
& target
) : m_target(&target
) { init(); }
100 Autolock(ILockable
* target
) : m_target( target
) { init(); }
102 Autolock(const ILockable
& target
) :
103 m_target(const_cast<ILockable
*>(&target
)) { init(); }
104 Autolock(const ILockable
* target
) :
105 m_target(const_cast<ILockable
*>( target
)) { init(); }
110 m_locked
= m_target
->lock();
117 __END_CORTEX_NAMESPACE
118 #endif /*__ILockable_H__*/