PebbleOS v4.45.0-223-gf3212a729
Loading...
Searching...
No Matches
work.h File Reference
#include <stddef.h>
#include <pbl/kernel/sem.h>
#include <pbl/kernel/timer.h>
#include <pbl/kernel/types.h>

Data Structures

struct  pbl_work
 Work item. More...
 
struct  pbl_delayed_work
 Work item submitted after a delay. More...
 
struct  pbl_wallclock_work
 Work item submitted at wall clock boundaries. More...
 
struct  pbl_workq_ops
 Optional hooks run on a queue's thread. More...
 
struct  pbl_workq
 Work queue. More...
 
struct  pbl_work_pool
 Slots for pbl_work_call(). More...
 

Macros

#define PBL_WORK_INITIALIZER(_fn)   {.fn = (_fn)}
 Static initializer for a work item.
 
#define PBL_WORK_DEFINE(name, fn)   struct pbl_work name = PBL_WORK_INITIALIZER(fn)
 Define a work item, usable without pbl_work_init().
 
#define PBL_DELAYED_WORK_INITIALIZER(_fn)
 Static initializer for a delayed work item.
 
#define PBL_DELAYED_WORK_DEFINE(name, fn)    struct pbl_delayed_work name = PBL_DELAYED_WORK_INITIALIZER(fn)
 Define a delayed work item, usable without pbl_delayed_work_init().
 
#define PBL_WORKQ_INITIALIZER   {.wake = PBL_SEM_INITIALIZER(0, 1)}
 Static initializer for a work queue.
 
#define PBL_WORKQ_DEFINE(name)   struct pbl_workq name = PBL_WORKQ_INITIALIZER
 Define a work queue, usable without pbl_workq_init().
 
#define PBL_WORK_POOL_DEFINE(name, n)
 Define a pool for pbl_work_call(), usable without pbl_work_pool_init().
 

Typedefs

typedef void(* pbl_work_fn_t) (struct pbl_work *work)
 Work function, run on the queue's thread.
 
typedef void(* pbl_work_call_fn_t) (void *data)
 Function run by pbl_work_call().
 

Functions

void pbl_workq_init (struct pbl_workq *q)
 Initialize a work queue in dynamically allocated memory.
 
void pbl_workq_set_ops (struct pbl_workq *q, const struct pbl_workq_ops *ops)
 Set the hooks of a queue, which take effect once it is next idle.
 
void pbl_workq_thread (void *arg)
 Thread entry serving a queue, with the queue as its argument.
 
void pbl_workq_flush (struct pbl_workq *q)
 Wait until everything submitted so far has run.
 
struct pbl_thread * pbl_workq_get_thread (const struct pbl_workq *q)
 Get the thread serving a queue.
 
bool pbl_workq_is_current (const struct pbl_workq *q)
 Check whether the caller runs on a queue's thread.
 
void * pbl_workq_current_fn (const struct pbl_workq *q)
 Get the function being run, for debugging.
 
void pbl_work_init (struct pbl_work *work, pbl_work_fn_t fn)
 Initialize a work item.
 
bool pbl_work_submit (struct pbl_workq *q, struct pbl_work *work)
 Queue a work item.
 
void pbl_workq_set_boost_prio (struct pbl_workq *q, pbl_prio_t prio)
 Set the priority a queue's thread runs at while it has boosted work.
 
bool pbl_work_submit_boosted (struct pbl_workq *q, struct pbl_work *work)
 Queue a work item that raises its queue's priority until it has run.
 
bool pbl_work_cancel (struct pbl_work *work)
 Remove a work item from its queue, without waiting for it if it is running.
 
bool pbl_work_cancel_sync (struct pbl_work *work)
 Remove a work item from its queue and wait for it to finish running.
 
bool pbl_work_flush (struct pbl_work *work)
 Wait for a work item to finish its last submission.
 
bool pbl_work_is_pending (const struct pbl_work *work)
 Check whether a work item is queued.
 
bool pbl_work_is_running (const struct pbl_work *work)
 Check whether a work item's function is running.
 
void pbl_delayed_work_init (struct pbl_delayed_work *dwork, pbl_work_fn_t fn)
 Initialize a delayed work item.
 
bool pbl_delayed_work_schedule (struct pbl_workq *q, struct pbl_delayed_work *dwork, pbl_timeout_t delay)
 Queue a delayed work item after a delay, unless it is already pending.
 
bool pbl_delayed_work_reschedule (struct pbl_workq *q, struct pbl_delayed_work *dwork, pbl_timeout_t delay)
 Queue a delayed work item after a delay, replacing any pending delay.
 
void pbl_delayed_work_schedule_next (struct pbl_delayed_work *dwork, pbl_tick_t period)
 Queue a delayed work item one period after its last expiry, so it does not drift.
 
bool pbl_delayed_work_cancel (struct pbl_delayed_work *dwork)
 Stop a delayed work item, without waiting for it if it is running.
 
bool pbl_delayed_work_cancel_sync (struct pbl_delayed_work *dwork)
 Stop a delayed work item and wait for it to finish running.
 
bool pbl_delayed_work_is_pending (const struct pbl_delayed_work *dwork)
 Check whether a delayed work item is pending.
 
pbl_tick_t pbl_delayed_work_remaining (const struct pbl_delayed_work *dwork)
 Get the time left on a delayed work item.
 
void pbl_work_pool_init (struct pbl_work_pool *pool, struct pbl_work_call *slots, size_t num_slots)
 Initialize a pool in dynamically allocated memory.
 
size_t pbl_work_pool_num_free (const struct pbl_work_pool *pool)
 Get the free slots of a pool.
 
int pbl_work_call (struct pbl_workq *q, struct pbl_work_pool *pool, pbl_work_call_fn_t fn, void *data, pbl_timeout_t timeout)
 Run a function with a payload on a queue.
 
void pbl_wallclock_work_init (struct pbl_wallclock_work *w, pbl_work_fn_t fn)
 Initialize a wall clock work item.
 
void pbl_wallclock_work_start (struct pbl_workq *q, struct pbl_wallclock_work *w, uint32_t unit_s, uint32_t every)
 Queue a work item at every every -th boundary of the wall clock's unit_s seconds.
 
bool pbl_wallclock_work_stop (struct pbl_wallclock_work *w)
 Stop a wall clock work item, and remove it from its queue if it is pending.
 
bool pbl_wallclock_work_is_running (const struct pbl_wallclock_work *w)
 Check whether a wall clock work item is started.
 
bool pbl_sys_work_call (pbl_work_call_fn_t fn, void *data)
 Run a function with a payload on pbl_sys_workq.
 
bool pbl_sys_work_call_from_isr (pbl_work_call_fn_t fn, void *data)
 Like pbl_sys_work_call(), from an ISR: stops the system at once if no slot is free.
 
bool pbl_sys_work_try_call (pbl_work_call_fn_t fn, void *data)
 Like pbl_sys_work_call(), but never waits nor stops the system.
 
bool pbl_sys_work_call_high (pbl_work_call_fn_t fn, void *data)
 Run a short, time sensitive function with a payload on pbl_sys_workq_high.
 
void pbl_sys_work_call_high_from_isr (pbl_work_call_fn_t fn, void *data)
 Like pbl_sys_work_call_high(), from an ISR: the call is dropped if no slot is free.
 
void pbl_sys_work_block (bool block)
 Refuse new calls to pbl_sys_workq, e.g.
 
size_t pbl_sys_work_num_free (void)
 Get how many calls the caller can make to pbl_sys_workq without waiting.
 
void * pbl_sys_work_current_fn (void)
 Get the function running on pbl_sys_workq, for debugging.
 

Variables

struct pbl_workq pbl_sys_workq
 Queue for background work, which may block and take a while.
 
struct pbl_workq pbl_sys_workq_high
 Queue for short, time sensitive work, at the highest thread priority.