ardour
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
CrossThreadChannel Class Reference

#include <crossthread.h>

Public Member Functions

 CrossThreadChannel (bool non_blocking)
 
 ~CrossThreadChannel ()
 
void wakeup ()
 
int deliver (char msg)
 
int receive (char &msg, bool wait=false)
 
void drain ()
 
void set_receive_handler (sigc::slot< bool, Glib::IOCondition > s)
 
void attach (Glib::RefPtr< Glib::MainContext >)
 

Private Member Functions

bool poll_for_request ()
 

Private Attributes

GIOChannel * receive_channel
 
GSource * receive_source
 
sigc::slot< bool,
Glib::IOCondition > 
receive_slot
 
int fds [2]
 

Friends

gboolean cross_thread_channel_call_receive_slot (GIOChannel *, GIOCondition condition, void *data)
 

Detailed Description

A simple abstraction of a mechanism of signalling one thread from another. The signaller calls ::wakeup() to tell the signalled thread to check for work to be done.

This implementation provides both ::selectable() for use in direct poll/select-based event loops, and a Glib::IOSource via ::ios() for use in Glib main loop based situations.

Definition at line 45 of file crossthread.h.

Constructor & Destructor Documentation

CrossThreadChannel::CrossThreadChannel ( bool  non_blocking)

if non_blocking is true, the channel will not cause blocking when used in an event loop based on poll/select or the glib main loop.

Definition at line 3 of file crossthread.posix.cc.

CrossThreadChannel::~CrossThreadChannel ( )

Definition at line 29 of file crossthread.posix.cc.

Member Function Documentation

void CrossThreadChannel::attach ( Glib::RefPtr< Glib::MainContext >  context)

Definition at line 59 of file crossthread.cc.

int CrossThreadChannel::deliver ( char  msg)

Definition at line 61 of file crossthread.posix.cc.

void CrossThreadChannel::drain ( )

empty the channel of all requests. Typically this is done as soon as input is noticed on the channel, because the handler will look at a separately managed work queue. The actual number of queued "wakeups" in the channel will not be important.

Definition at line 54 of file crossthread.posix.cc.

bool CrossThreadChannel::poll_for_request ( )
private

Definition at line 67 of file crossthread.posix.cc.

int CrossThreadChannel::receive ( char &  msg,
bool  wait = false 
)

if using ::deliver() to wakeup the listening thread, then the listener should call ::receive() to fetch the message type from the channel.

wait = true only make sense for non_blocking channels, it polls for data to become available.

Definition at line 91 of file crossthread.posix.cc.

void CrossThreadChannel::set_receive_handler ( sigc::slot< bool, Glib::IOCondition >  s)

Definition at line 53 of file crossthread.cc.

void CrossThreadChannel::wakeup ( )

Tell the listening thread that is has work to do.

Definition at line 47 of file crossthread.posix.cc.

Friends And Related Function Documentation

gboolean cross_thread_channel_call_receive_slot ( GIOChannel *  ,
GIOCondition  condition,
void *  data 
)
friend

Definition at line 46 of file crossthread.cc.

Member Data Documentation

int CrossThreadChannel::fds[2]
private

Definition at line 98 of file crossthread.h.

GIOChannel* CrossThreadChannel::receive_channel
private

Definition at line 91 of file crossthread.h.

sigc::slot<bool,Glib::IOCondition> CrossThreadChannel::receive_slot
private

Definition at line 93 of file crossthread.h.

GSource* CrossThreadChannel::receive_source
private

Definition at line 92 of file crossthread.h.


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