VirtualBox

source: vbox/trunk/src/VBox/Main/AutoLock.cpp@ 25279

Last change on this file since 25279 was 25279, checked in by vboxsync, 15 years ago

Main: preparation for deadlock detection: clean up autolock classes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1/** @file
2 *
3 * AutoWriteLock/AutoReadLock: smart R/W semaphore wrappers
4 */
5
6/*
7 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#include "AutoLock.h"
23
24#include "Logging.h"
25
26#include <iprt/string.h>
27
28
29namespace util
30{
31
32////////////////////////////////////////////////////////////////////////////////
33//
34// RWLockHandle
35//
36////////////////////////////////////////////////////////////////////////////////
37
38RWLockHandle::RWLockHandle()
39{
40 int vrc = RTSemRWCreate (&mSemRW);
41 AssertRC (vrc);
42}
43
44
45RWLockHandle::~RWLockHandle()
46{
47 RTSemRWDestroy (mSemRW);
48}
49
50
51bool RWLockHandle::isWriteLockOnCurrentThread() const
52{
53 return RTSemRWIsWriteOwner (mSemRW);
54}
55
56
57void RWLockHandle::lockWrite()
58{
59 int vrc = RTSemRWRequestWrite (mSemRW, RT_INDEFINITE_WAIT);
60 AssertRC (vrc);
61}
62
63
64void RWLockHandle::unlockWrite()
65{
66 int vrc = RTSemRWReleaseWrite (mSemRW);
67 AssertRC (vrc);
68}
69
70
71void RWLockHandle::lockRead()
72{
73 int vrc = RTSemRWRequestRead (mSemRW, RT_INDEFINITE_WAIT);
74 AssertRC (vrc);
75}
76
77
78void RWLockHandle::unlockRead()
79{
80 int vrc = RTSemRWReleaseRead (mSemRW);
81 AssertRC (vrc);
82}
83
84
85uint32_t RWLockHandle::writeLockLevel() const
86{
87 return RTSemRWGetWriteRecursion (mSemRW);
88}
89
90} /* namespace util */
91/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use