Opened 16 years ago
Last modified 16 years ago
#37 new enhancement
Add a Worker thread API — at Version 5
| Reported by: | anonymous | Owned by: | becoulet |
|---|---|---|---|
| Priority: | minor | Milestone: | Preemptive scheduler usage |
| Component: | mutek | Keywords: | |
| Cc: |
Description (last modified by )
We sometimes use a worker-thread-like service. Each time it is recreated from scratch. Let's add an API for this.
Here is such a proposal
/**
@this is an item pushable to a worker queue.
*/
struct worker_item_s
{
CONTAINER_ENTRY_TYPE(DLIST) list_entry;
};
/** @intenral */
CONTAINER_TYPE(worker_internal, DLIST, struct worker_item_s, list_entry);
/**
@this permits to retrieve an actual structure from an item
pointer
*/
#define WORKER_ITEM_TO_STRUCT(struct_type, field, item) \
(struct_type *)((uintptr_t)(item) - __builtin_offsetof(struct_type, field))
/**
@this is a worker function prototype macro.
*/
#define WORKER_FUNC(n) void (n)(struct worker_thread_s *worker, \
struct worker_item_s *item, \
void *priv)
/**
@this is a worker function type definition.
Function must return once it handled the reason of wakeup.
@param worker Worker thread context, may be used to stop self
@param item Item to work on
@param priv Private data passed on init
*/
typedef WORKER_FUNC(worker_func_t);
struct worker_thread_s
{
worker_internal_root_t to_handle;
struct sched_context_s context;
bool_t killed;
lock_t lock;
worker_func_t *func;
void *func_priv;
};
/***/
void worker_thread_init(struct worker_thread_s*,
void *stack,
size_t stack_size,
worker_func_t *func,
void *func_priv);
/**
@this runs a context, i.e. this makes the worker ready for wake
up. This waits until a work is pushed.
*/
void worker_thread_start(struct worker_thread_s*);
/**
@this kills the context, but waits for completion of all actions
pending.
*/
void worker_thread_stop(struct worker_thread_s*);
/**
@this makes the worker function to be called once. Multiple
calls to this function yields multiple consecutive calls to
the worker function.
@param item The item to pass to the woken-up function
@returns -EAGAIN if the thread is not started yet, -EINVAL if the
thread already got killed, 0 if OK.
*/
error_t worker_thread_wakeup(struct worker_thread_s*, struct worker_item_s *item);
Change History (5)
comment:1 by , 16 years ago
| Component: | Build system → mutek |
|---|---|
| Description: | modified (diff) |
| Owner: | changed from to |
| Priority: | major → minor |
| Type: | defect → enhancement |
comment:2 by , 16 years ago
comment:3 by , 16 years ago
| Milestone: | → Preempt merge |
|---|
comment:4 by , 16 years ago
Why not include an API to delay some work from irq handlers ? It could be helpful for RT purposes.
comment:5 by , 16 years ago
| Description: | modified (diff) |
|---|
Note:
See TracTickets
for help on using tickets.


Who does the allocation of stack space ? Probably we must pass it to the creation...