librfn
An ad-hoc utility library
Data Structures | Macros | Typedefs | Enumerations | Functions
fibre.h File Reference
#include <stdint.h>
#include "list.h"
#include "messageq.h"
#include "protothreads.h"

Go to the source code of this file.

Data Structures

struct  fibre
 Fibre descriptor. More...
 
struct  fibre_eventq
 Fibre and eventq descriptor. More...
 

Macros

#define FIBRE_UNBOUNDED_SLEEP   ((uint32_t) 0x7fffffff)
 An approximation of infinitely far in the future. More...
 
#define FIBRE_VAR_INIT(fn)   { (fn), 0, 0, 0, LIST_NODE_VAR_INIT }
 Static initializer for a fibre descriptor. More...
 
#define FIBRE_EVENTQ_VAR_INIT(fn, basep, base_len, msg_len)
 Static initializer for a fibre and eventq descriptor. More...
 
#define PT_BEGIN_FIBRE(f)   PT_BEGIN(&((f)->priv))
 Fibre aware alternative to PT_BEGIN(). More...
 

Typedefs

typedef int fibre_entrypoint_t(struct fibre *)
 
typedef struct fibre fibre_t
 Fibre descriptor. More...
 
typedef struct fibre_eventq fibre_eventq_t
 Fibre and eventq descriptor. More...
 

Enumerations

enum  fibre_state_t {
  FIBRE_STATE_YIELDED = PT_YIELDED, FIBRE_STATE_WAITING = PT_WAITING, FIBRE_STATE_EXITED = PT_EXITED, FIBRE_STATE_RUNNING,
  FIBRE_STATE_QUEUED = 0x10, FIBRE_STATE_TIMER_WAITING = FIBRE_STATE_WAITING | FIBRE_STATE_QUEUED, FIBRE_STATE_RUNNABLE = FIBRE_STATE_RUNNING | FIBRE_STATE_QUEUED
}
 

Functions

fibre_tfibre_self (void)
 Returns the currently active fibre descriptor. More...
 
uint32_t fibre_scheduler_next (uint32_t time)
 Schedule the next fibre. More...
 
void fibre_init (fibre_t *f, fibre_entrypoint_t *fn)
 Dynamic initializer for a fibre descriptor. More...
 
void fibre_run (fibre_t *f)
 
bool fibre_run_atomic (fibre_t *f)
 
bool fibre_kill (fibre_t *f)
 
bool fibre_timeout (uint32_t duetime)
 
void fibre_eventq_init (fibre_eventq_t *evtq, fibre_entrypoint_t *fn, void *basep, size_t base_len, size_t msg_len)
 Dynamic initializer for a fibre and eventq descriptor. More...
 
void * fibre_eventq_claim (fibre_eventq_t *evtq)
 Request memory resources to send an event to a fibre. More...
 
bool fibre_eventq_send (fibre_eventq_t *evtq, void *evtp)
 Send an event to a fibre. More...
 
bool fibre_eventq_empty (fibre_eventq_t *evtq)
 Return true if the fibre's event queue is empty. More...
 
void * fibre_eventq_receive (fibre_eventq_t *evtq)
 Recevied a message previously send to the fibre. More...
 
void fibre_eventq_release (fibre_eventq_t *evtq, void *evtp)
 Release a message previously received by a fibre. More...
 
void fibre_scheduler_main_loop (void)