Name
cothreads -- userspace threads
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;
#ifdef COTHREAD_ATOMIC
atomic_t lock;
#else
GMutex *lock;
#endif
}; |
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 ()
Create and initialize a new cothread context
cothread_context_free ()
Free the cothread context.
cothread_create ()
Create a new cothread state in the given context
cothread_free ()
Free the given cothread state
cothread_setfunc ()
Set the cothread function
cothread_stop ()
Stop the cothread and reset the stack and program counter.
cothread_switch ()
Switches to the given cothread state
cothread_lock ()
Locks the cothread state.
cothread_trylock ()
Try to lock the cothread state
cothread_unlock ()
Unlock the cothread state.
cothread_main ()
Get the main thread.
cothread_current_main ()
Get the main thread in the current pthread.
cothread_current ()
Get the currenttly executing cothread