Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

VirtualBoxBaseProto::AutoMayUninitSpan Class Reference

#include <VirtualBoxBase.h>

List of all members.


Detailed Description

Smart class to enclose the state transition Ready->MayUninit->NotReady or Ready->MayUninit->WillUninit.

The purpose of this span is to safely check if unintialization is possible at the given moment and seamlessly perform it if so.

Instances must be created as a stack-based variable taking |this| pointer as the argument at the beginning of methods of VirtualBoxBase subclasses that want to uninitialize the object if a necessary set of criteria is met and leave it Ready otherwise.

When this variable is created it automatically places the object to the MayUninit state if it is Ready, does nothing but returns |true| in response to alreadyInProgress() if it is already in MayUninit, or returns a failure in response to rc() in any other case. The example below shows how the user must react in latter two cases.

When this variable goes out of scope (i.e. gets destroyed), it places the object back to Ready state unless acceptUninit() is called in which case the object is placed to WillUninit state and uninit() is immediately called after that.

A typical usage pattern is: void Component::uninit() { AutoMayUninitSpan mayUninitSpan (this); CheckComRCReturnRC (mayUninitSpan.rc()); if (mayUninitSpan.alreadyInProgress()) return S_OK; ... if (FAILED (rc)) return rc; // will go back to Ready ... if (SUCCEEDED (rc)) mayUninitSpan.acceptUninit(); // will call uninit() return rc; }

Note:
The constructor of this class blocks the current thread execution until the number of callers added to the object using addCaller() or AutoCaller drops to zero. For this reason, it is forbidden to create instances of this class (or call uninit()) within the AutoCaller or addCaller() scope because it is a guaranteed deadlock.

Definition at line 1129 of file VirtualBoxBase.h.


Public Member Functions

void acceptUninit ()
bool alreadyInProgress ()
 AutoMayUninitSpan (VirtualBoxBaseProto *aObj)
HRESULT rc ()
 ~AutoMayUninitSpan ()

Private Attributes

bool mAcceptUninit: 1
bool mAlreadyInProgress: 1
VirtualBoxBaseProtomObj
HRESULT mRC

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index