Add pointer constructor to CriticalSectionScoped.

Mainly added to simplyfy the code, e.g. when having critsect as scoped_ptr in classes.

Review URL: http://webrtc-codereview.appspot.com/302005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1144 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mflodman@webrtc.org 2011-12-09 10:02:16 +00:00
parent af225d6bf6
commit b19582b7dc

View File

@ -33,18 +33,26 @@ public:
virtual void Leave() = 0; virtual void Leave() = 0;
}; };
// RAII extension of the critical section. Prevents Enter/Leave missmatches and // RAII extension of the critical section. Prevents Enter/Leave mismatches and
// provides more compact critical section syntax. // provides more compact critical section syntax.
class CriticalSectionScoped class CriticalSectionScoped
{ {
public: public:
CriticalSectionScoped(CriticalSectionWrapper& critsec) // Deprecated, don't add more users of this constructor.
: // TODO(mflodman) Remove this version of the constructor when no one is
_ptrCritSec(&critsec) // using it any longer.
explicit CriticalSectionScoped(CriticalSectionWrapper& critsec)
: _ptrCritSec(&critsec)
{ {
_ptrCritSec->Enter(); _ptrCritSec->Enter();
} }
explicit CriticalSectionScoped(CriticalSectionWrapper* critsec)
: _ptrCritSec(critsec)
{
_ptrCritSec->Enter();
}
~CriticalSectionScoped() ~CriticalSectionScoped()
{ {
if (_ptrCritSec) if (_ptrCritSec)