AutoLock.h revision 13b82bf0e999d7c0c1a30fd67d5f3db8905c27ae
af062818b47340eef15700d2f0211576ba3506eevboxsync * Automatic locks, implementation
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright (C) 2006-2009 Sun Microsystems, Inc.
af062818b47340eef15700d2f0211576ba3506eevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
af062818b47340eef15700d2f0211576ba3506eevboxsync * available from http://www.virtualbox.org. This file is free software;
af062818b47340eef15700d2f0211576ba3506eevboxsync * you can redistribute it and/or modify it under the terms of the GNU
af062818b47340eef15700d2f0211576ba3506eevboxsync * General Public License (GPL) as published by the Free Software
af062818b47340eef15700d2f0211576ba3506eevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
af062818b47340eef15700d2f0211576ba3506eevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
af062818b47340eef15700d2f0211576ba3506eevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
af062818b47340eef15700d2f0211576ba3506eevboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
af062818b47340eef15700d2f0211576ba3506eevboxsync * additional information or have any questions.
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync// macros for automatic lock validation; these will amount to nothing
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync// unless lock validation is enabled for the runtime
af062818b47340eef15700d2f0211576ba3506eevboxsync# define COMMA_LOCKVAL_SRC_POS_DECL , RT_SRC_POS_DECL
af062818b47340eef15700d2f0211576ba3506eevboxsync# define COMMA_LOCKVAL_SRC_POS_ARGS , RT_SRC_POS_ARGS
af062818b47340eef15700d2f0211576ba3506eevboxsync////////////////////////////////////////////////////////////////////////////////
af062818b47340eef15700d2f0211576ba3506eevboxsync// Order classes for lock validation
af062818b47340eef15700d2f0211576ba3506eevboxsync////////////////////////////////////////////////////////////////////////////////
af062818b47340eef15700d2f0211576ba3506eevboxsync * IPRT now has a sophisticated system of run-time locking classes to validate
af062818b47340eef15700d2f0211576ba3506eevboxsync * locking order. Since the Main code is handled by simpler minds, we want
af062818b47340eef15700d2f0211576ba3506eevboxsync * compile-time constants for simplicity, and we'll look up the run-time classes
af062818b47340eef15700d2f0211576ba3506eevboxsync * in AutoLock.cpp transparently. These are passed to the constructors of the
af062818b47340eef15700d2f0211576ba3506eevboxsync * LockHandle classes.
af062818b47340eef15700d2f0211576ba3506eevboxsync LOCKCLASS_VIRTUALBOXOBJECT = 1, // highest order: VirtualBox object lock
af062818b47340eef15700d2f0211576ba3506eevboxsync LOCKCLASS_USBPROXYSERVICE = 2, // USB proxy service object lock
af062818b47340eef15700d2f0211576ba3506eevboxsync LOCKCLASS_LISTOFMACHINES = 4, // list of machines in VirtualBox object
af062818b47340eef15700d2f0211576ba3506eevboxsync LOCKCLASS_MACHINEOBJECT = 5, // Machine object lock
af062818b47340eef15700d2f0211576ba3506eevboxsync LOCKCLASS_LISTOFSNAPSHOTS = 6, // list of snapshots in Machine object
af062818b47340eef15700d2f0211576ba3506eevboxsync LOCKCLASS_SNAPSHOTOBJECT = 7, // snapshot object locks (need to have lower order
af062818b47340eef15700d2f0211576ba3506eevboxsync // than both MACHINEOBJECT and LOCKCLASS_MACHINELIST since
af062818b47340eef15700d2f0211576ba3506eevboxsync // the list of snapshots in Machine is LOCKCLASS_MACHINELIST)
af062818b47340eef15700d2f0211576ba3506eevboxsync LOCKCLASS_LISTOFMEDIA = 8, // list of media (hard disks, DVDs, floppies) in VirtualBox object
af062818b47340eef15700d2f0211576ba3506eevboxsync LOCKCLASS_LISTOFOTHEROBJECTS = 9, // any other list of objects
af062818b47340eef15700d2f0211576ba3506eevboxsync LOCKCLASS_OTHEROBJECT = 10, // any regular object member variable lock
af062818b47340eef15700d2f0211576ba3506eevboxsync LOCKCLASS_USBLIST = 11, // temporary hack to avoid having to clean up the USB filters
af062818b47340eef15700d2f0211576ba3506eevboxsync // too much @todo r=dj get rid of this!
af062818b47340eef15700d2f0211576ba3506eevboxsync LOCKCLASS_PROGRESSLIST = 12, // list of progress objects in VirtualBox; no other object lock
af062818b47340eef15700d2f0211576ba3506eevboxsync // may be held after this!
af062818b47340eef15700d2f0211576ba3506eevboxsync LOCKCLASS_OBJECTSTATE = 13 // object state lock (handled by AutoCaller classes)
af062818b47340eef15700d2f0211576ba3506eevboxsync////////////////////////////////////////////////////////////////////////////////
af062818b47340eef15700d2f0211576ba3506eevboxsync// LockHandle and friends
af062818b47340eef15700d2f0211576ba3506eevboxsync////////////////////////////////////////////////////////////////////////////////
af062818b47340eef15700d2f0211576ba3506eevboxsync * Abstract base class for semaphore handles (RWLockHandle and WriteLockHandle).
af062818b47340eef15700d2f0211576ba3506eevboxsync * Don't use this directly, but this implements lock validation for them.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Returns @c true if the current thread holds a write lock on this
af062818b47340eef15700d2f0211576ba3506eevboxsync * read/write semaphore. Intended for debugging only.
af062818b47340eef15700d2f0211576ba3506eevboxsync virtual bool isWriteLockOnCurrentThread() const = 0;
af062818b47340eef15700d2f0211576ba3506eevboxsync * Returns the current write lock level of this semaphore. The lock level
af062818b47340eef15700d2f0211576ba3506eevboxsync * determines the number of nested #lock() calls on the given semaphore
af062818b47340eef15700d2f0211576ba3506eevboxsync * Note that this call is valid only when the current thread owns a write
af062818b47340eef15700d2f0211576ba3506eevboxsync * lock on the given semaphore handle and will assert otherwise.
af062818b47340eef15700d2f0211576ba3506eevboxsync // prohibit copy + assignment
af062818b47340eef15700d2f0211576ba3506eevboxsync * Full-featured read/write semaphore handle implementation.
af062818b47340eef15700d2f0211576ba3506eevboxsync * This is an auxiliary base class for classes that need full-featured
af062818b47340eef15700d2f0211576ba3506eevboxsync * read/write locking as described in the AutoWriteLock class documentation.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Instances of classes inherited from this class can be passed as arguments to
af062818b47340eef15700d2f0211576ba3506eevboxsync * the AutoWriteLock and AutoReadLock constructors.
struct Data;
Data *m;
struct Data;
Data *m;
* Returns a pointer to a LockHandle used by AutoWriteLock/AutoReadLock
* the AutoWriteLock/AutoReadLock object constructed using an instance of
bool isWriteLockOnCurrentThread()
return h ? h->isWriteLockOnCurrentThread() : false;
struct Data;
Data *m;
void callLockOnAllHandles();
void callUnlockOnAllHandles();
void cleanup();
void acquire();
void release();
acquire();
acquire();
acquire();
acquire();
* leave/enter/maybeEnter methods, which are common to all
void leave();
void enter();
void maybeEnter();
acquire();
acquire();
acquire();
acquire();
cleanup();
bool isWriteLockOnCurrentThread() const;
cleanup();
cleanup();