libshevek
Public Member Functions | Static Public Member Functions | List of all members
shevek::closure Class Reference

Block and resume without blocking the main loop. More...

#include <closure.hh>

Inheritance diagram for shevek::closure:
shevek::refbase

Public Member Functions

bool empty () const
 Check if the closure is empty.
void set_function (sigc::slot0< void > func, bool run=true, sigc::slot0< void > cb=sigc::slot0< void >())
 Set running function on an empty closure.
 ~closure ()
 Destructor.
void wake ()
 Continue running the closure.
- Public Member Functions inherited from shevek::refbase
template<typename _T >
Glib::RefPtr< _T > cast_dynamic ()
 Identical to GLib::RefPtr <>::cast_dynamic, but nicer to type.

Static Public Member Functions

static Glib::RefPtr< closurecreate ()
 Create a new closure.
static void block ()
 Sleep, returning control to the caller until awoken.

Additional Inherited Members

- Protected Member Functions inherited from shevek::refbase
 refbase ()
 Constructor, increments reference count.
virtual ~refbase ()
 Destructor, decrements reference count and destroys the object if it reaches 0.
template<typename T >
Glib::RefPtr< T > refptr_this ()
 Get a RefPtr to this, protected because only members should need it.

Detailed Description

Block and resume without blocking the main loop.

Closures allow blocking and resuming the main loop. They are implemented with threads, which means that they don't work well with multi-threaded programs.

If a function wants to be able to block using a closure, it must be called using closure(). It (or any function it calls) can then suspend by calling closure::block(). It can be awoken again by calling closure::wake() on the closure object.

Member Function Documentation

static void shevek::closure::block ( )
static

Sleep, returning control to the caller until awoken.

This function puts the current closure to sleep. It will continue to run when awoken with wake(). It can also be destroyed. This function uses a global variable to know which is the current closure, so it can be called without an object, as closure::block (); .

static Glib::RefPtr<closure> shevek::closure::create ( )
inlinestatic

Create a new closure.

Create a new closure. It will be empty initially.

bool shevek::closure::empty ( ) const
inline

Check if the closure is empty.

Check if the closure is empty. If it is, set_function() can be called.

void shevek::closure::set_function ( sigc::slot0< void >  func,
bool  run = true,
sigc::slot0< void >  cb = sigc::slot0< void >() 
)

Set running function on an empty closure.

Set running function. The closure must be empty when this is called. When the function exits, the closure returns to the empty state, and the callback is called, if given.

void shevek::closure::wake ( )

Continue running the closure.

Wake a closure. It is an error to wake a closure which isn't blocking (in particular also the currently running closure).


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