EVE 1.0
Generic work scheduler
Collaboration diagram for Generic work scheduler:

Data Structures

struct  work_t
 
struct  swint_state_t
 

Macros

#define WORK_INIT(work, callback)
 
#define WORK_INIT_TYPED(work, callback)   (struct work_t) WORK_INIT(work, callback)
 
#define DECLARE_WORK(work, callback)   struct work_t work = WORK_INIT(work, callback)
 
#define SWINT_AUTO_LOCK()
 

Typedefs

typedef void(* work_cb_t) (struct work_t *work)
 

Functions

void work_schedule (struct work_t *work)
 
void work_cancel (struct work_t *work)
 
static bool work_pending (struct work_t *work)
 
swint_state_t swint_disable (void)
 
void swint_enable (swint_state_t state)
 
 __attribute__ ((always_inline)) static inline void swint_enable_indirect_adapter(swint_state_t *state)
 

Detailed Description

Macro Definition Documentation

#define WORK_INIT (   work,
  callback 
)
Value:
{ \
.link.next = &work.link, \
.link.prev = &work.link, \
.cb = callback, \
}

Initializes a work structure.

The macro is used to initialize a work structure instance.

Parameters
workwork structure
callbackwork callback

Usage:

1 static void MyWorkCallback(struct work_t *Work);
2 struct work_t MyWork = WORK_INIT(MyWork, MyWorkCallback);

Definition at line 65 of file work.h.

#define WORK_INIT_TYPED (   work,
  callback 
)    (struct work_t) WORK_INIT(work, callback)

Initializes a work structure. Typed version of WORK_INIT

Definition at line 76 of file work.h.

#define DECLARE_WORK (   work,
  callback 
)    struct work_t work = WORK_INIT(work, callback)

Instantiates a work structure.

The macro is used to instantiate a work structure.

Parameters
workname of the work structure
callbackthe work callback

Usage:

1 static void MyWorkCallback(struct work_t *Work);
2 DECLARE_WORK(MyWork, MyWorkCallback);

Definition at line 94 of file work.h.

#define SWINT_AUTO_LOCK ( )
Value:
swint_state_t swint_auto_lock_state __attribute__((cleanup(swint_enable_indirect_adapter))); \
do { swint_auto_lock_state = swint_disable(); } while (0)
__attribute__((always_inline)) static inline void swint_enable_indirect_adapter(swint_state_t *state)
Definition: work.h:245
swint_state_t swint_disable(void)

Declares an anonymous software interrupt lock, which disables software interrupts in scope of the the auto variable visibility block

Usage:

1 {
2  SWINT_AUTO_LOCK();
3  // Do something protected by the lock
4 }
5 // The lock is released here

Note: taking in mind lazy nature of releasing the clock locks, use of auto clock locks is negligible.

Definition at line 113 of file work.h.

Typedef Documentation

typedef void(* work_cb_t) (struct work_t *work)

Work callback type.

Parameters
workpointer to the work structure

Definition at line 126 of file work.h.

Function Documentation

void work_schedule ( struct work_t work)

Schedules a work.

The function schedules a work item for execution at the software interrupt level. Depending on the current interrupt level and the software interrupt enable status, the work item callback may be called immediately or be queued until the software interrupt level is available.

Framework keeps order of execution of the scheduled work items. First scheduled work is executed first.

Is the work structure, pointed by the work parameter is already scheduled for execution, then it is re-scheduled at the tail of the work queue.

Parameters
workpointer to the work structure
void work_cancel ( struct work_t work)

Removes a work from the work queue.

The function removes a previously scheduled work from the work queue.

Parameters
workpointer to the work structure
static bool work_pending ( struct work_t work)
inlinestatic

Checks if the work is scheduled and pending execution.

The function checks if the work is scheduled for execution.

Parameters
workpointer to the work structure
Returns
true if the work is scheduled for execution
false if the work is not scheduled
false if the work is being executed

Definition at line 195 of file work.h.

References dlist_is_empty(), work_t::link, swint_disable(), and swint_enable().

swint_state_t swint_disable ( void  )

Disables software interrupt processing

The function disables software interrupt processing

Usage:

1 swint_state_t swint_state = swint_disable();
2 // Do something atomically
3 swint_enable(swint_state);
Returns
previous software interrupt status

Referenced by app_timer_start(), and work_pending().

void swint_enable ( swint_state_t  state)

Restores software interrupt processing

The function conditionally enables software interrupt processing

Usage:

1 swint_state_t swint_state = swint_disable();
2 // Do something atomically
3 swint_enable(swint_state);
Parameters
statestate, obtained by corresponding swint_disable() call

Referenced by __attribute__(), app_timer_start(), and work_pending().

__attribute__ ( (always_inline)  )

Cleanup adapter for SWINT_AUTO_LOCK()

Definition at line 245 of file work.h.

References swint_enable().

Referenced by uip_log().