contents up previous next

wxcriticalsectionlocker

this is a small helper class to be used with wxcriticalsection objects. a wxcriticalsectionlocker enters the critical section in the constructor and leaves it in the destructor making it much more difficult to forget to leave a critical section (which, in general, will lead to serious and difficult to debug problems).

example of using it:

void set foo()
{
    // gs_critsect is some (global) critical section guarding access to the
    // object "foo"
    wxcriticalsectionlocker locker(gs_critsect);

    if ( ... )
    {
        // do something
        ...

        return;
    }

    // do something else
    ...

    return;
}
without wxcriticalsectionlocker, you would need to remember to manually leave the critical section before each return.

derived from

none.

include files

<wx/thread.h>

see also

wxcriticalsection, wxmutexlocker

members

wxcriticalsectionlocker::wxcriticalsectionlocker
wxcriticalsectionlocker::~wxcriticalsectionlocker


wxcriticalsectionlocker::wxcriticalsectionlocker

wxcriticalsectionlocker(wxcriticalsection& criticalsection)

constructs a wxcriticalsectionlocker object associated with given criticalsection and enters it.


wxcriticalsectionlocker::~wxcriticalsectionlocker

~wxcriticalsectionlocker()

destructor leaves the critical section.