cothreads

Name

cothreads -- userspace threads

Synopsis


#include <gst/gst.h>


#define     CURRENT_STACK_FRAME
struct      cothread_state;
struct      cothread_context;
int         (*cothread_func)                (int argc,
                                             char **argv);
#define     COTHREAD_STARTED
#define     COTHREAD_DESTROYED
cothread_context* cothread_context_init     (void);
void        cothread_context_free           (cothread_context *ctx);
gpointer    cothread_get_private            (cothread_state *thread);
void        cothread_set_private            (cothread_state *thread,
                                             gpointer data);
cothread_state* cothread_create             (cothread_context *ctx);
void        cothread_free                   (cothread_state *thread);
void        cothread_setfunc                (cothread_state *thread,
                                             cothread_func func,
                                             int argc,
                                             char **argv);
void        cothread_stop                   (cothread_state *thread);
void        cothread_switch                 (cothread_state *thread);
gpointer    cothread_context_get_data       (cothread_state *thread,
                                             gchar *key);
void        cothread_context_set_data       (cothread_state *thread,
                                             gchar *key,
                                             gpointer data);
void        cothread_lock                   (cothread_state *thread);
gboolean    cothread_trylock                (cothread_state *thread);
void        cothread_unlock                 (cothread_state *thread);
cothread_state* cothread_main               (cothread_context *ctx);
cothread_state* cothread_current_main       (void);
cothread_state* cothread_current            (void);

Description

Cothreads are a simple user-space method for switching between subtasks. They're based on setjmp()/longjmp() in their current form.

Cothreads are used for loop-based elements that pull data instead of being fed with data. They can also be used to pull a specific region of data out of their src element.

Details

CURRENT_STACK_FRAME

#define CURRENT_STACK_FRAME  ({ char __csf; &__csf; })

Get the current stack frame.


struct cothread_state

struct cothread_state {
  cothread_context *ctx;
  int threadnum;
  gpointer priv;

  cothread_func func;
  int argc;
  char **argv;

  int flags;
  void *sp;
  jmp_buf jmp;
  /* is this needed any more? */
  void *top_sp;
  void *pc;

  int magic_number;
  _lock_t lock;
};


struct cothread_context

struct cothread_context;


cothread_func ()

int         (*cothread_func)                (int argc,
                                             char **argv);

the function that will be called when the cothread starts. The function prototype is like a main() function, so you can do whatever you want with it.


COTHREAD_STARTED

#define COTHREAD_STARTED	0x01

Indicates the cothread is started.


COTHREAD_DESTROYED

#define COTHREAD_DESTROYED	0x02

Indicates the cothread is destroyed.


cothread_context_init ()

cothread_context* cothread_context_init     (void);

Create and initialize a new cothread context


cothread_context_free ()

void        cothread_context_free           (cothread_context *ctx);

Free the cothread context.


cothread_get_private ()

gpointer    cothread_get_private            (cothread_state *thread);

get the private data from the cothread


cothread_set_private ()

void        cothread_set_private            (cothread_state *thread,
                                             gpointer data);

set private data for the cothread.


cothread_create ()

cothread_state* cothread_create             (cothread_context *ctx);

Create a new cothread state in the given context


cothread_free ()

void        cothread_free                   (cothread_state *thread);

Free the given cothread state


cothread_setfunc ()

void        cothread_setfunc                (cothread_state *thread,
                                             cothread_func func,
                                             int argc,
                                             char **argv);

Set the cothread function


cothread_stop ()

void        cothread_stop                   (cothread_state *thread);

Stop the cothread and reset the stack and program counter.


cothread_switch ()

void        cothread_switch                 (cothread_state *thread);

Switches to the given cothread state


cothread_context_get_data ()

gpointer    cothread_context_get_data       (cothread_state *thread,
                                             gchar *key);

get data from the cothread


cothread_context_set_data ()

void        cothread_context_set_data       (cothread_state *thread,
                                             gchar *key,
                                             gpointer data);

adds data to a cothread


cothread_lock ()

void        cothread_lock                   (cothread_state *thread);

Locks the cothread state.


cothread_trylock ()

gboolean    cothread_trylock                (cothread_state *thread);

Try to lock the cothread state


cothread_unlock ()

void        cothread_unlock                 (cothread_state *thread);

Unlock the cothread state.


cothread_main ()

cothread_state* cothread_main               (cothread_context *ctx);

Get the main thread.


cothread_current_main ()

cothread_state* cothread_current_main       (void);

Get the main thread in the current pthread.


cothread_current ()

cothread_state* cothread_current            (void);

Get the currenttly executing cothread