2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_SCOPEDWRITELOCK_JUCEHEADER__
27 #define __JUCE_SCOPEDWRITELOCK_JUCEHEADER__
29 #include "juce_ReadWriteLock.h"
32 //==============================================================================
34 Automatically locks and unlocks a ReadWriteLock object.
36 Use one of these as a local variable to control access to a ReadWriteLock.
44 const ScopedWriteLock myScopedLock (myLock);
45 // myLock is now locked
49 // myLock gets unlocked here.
53 @see ReadWriteLock, ScopedReadLock
55 class JUCE_API ScopedWriteLock
58 //==============================================================================
59 /** Creates a ScopedWriteLock.
61 As soon as it is created, this will call ReadWriteLock::enterWrite(), and
62 when the ScopedWriteLock object is deleted, the ReadWriteLock will
65 Make sure this object is created and deleted by the same thread,
66 otherwise there are no guarantees what will happen! Best just to use it
67 as a local stack object, rather than creating one with the new() operator.
69 inline explicit ScopedWriteLock (const ReadWriteLock
& lock
) noexcept
: lock_ (lock
) { lock
.enterWrite(); }
73 The ReadWriteLock's exitWrite() method will be called when the destructor is called.
75 Make sure this object is created and deleted by the same thread,
76 otherwise there are no guarantees what will happen!
78 inline ~ScopedWriteLock() noexcept
{ lock_
.exitWrite(); }
82 //==============================================================================
83 const ReadWriteLock
& lock_
;
85 JUCE_DECLARE_NON_COPYABLE (ScopedWriteLock
);
89 #endif // __JUCE_SCOPEDWRITELOCK_JUCEHEADER__