Changes between Version 1 and Version 5 of Ticket #37


Ignore:
Timestamp:
Aug 2, 2010, 10:59:06 AM (15 years ago)
Author:
Nicolas Pouillon
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #37

    • Property Milestone changed from to Preempt merge
  • Ticket #37 – Description

    v1 v5  
    66#!c
    77
    8 // Skipped GPCT stuff to declare a queue as "worker_internal".
    9 
    108/**
    119 @this is an item pushable to a worker queue.
     
    1311struct worker_item_s
    1412{
    15     worker_internal_item_t item;
     13    CONTAINER_ENTRY_TYPE(DLIST) list_entry;
    1614};
     15
     16/** @intenral */
     17CONTAINER_TYPE(worker_internal, DLIST, struct worker_item_s, list_entry);
    1718
    1819
     
    2122 pointer
    2223 */
    23 #define WORKER_ITEM_TO_STRUCT(struct_type, field, item)
     24#define WORKER_ITEM_TO_STRUCT(struct_type, field, item) \
     25    (struct_type *)((uintptr_t)(item) - __builtin_offsetof(struct_type, field))
     26
     27
     28/**
     29 @this is a worker function prototype macro.
     30*/
     31#define WORKER_FUNC(n) void (n)(struct worker_thread_s *worker, \
     32                                struct worker_item_s *item, \
     33                                void *priv)
    2434
    2535/**
     
    2737
    2838 Function must return once it handled the reason of wakeup.
     39
     40 @param worker Worker thread context, may be used to stop self
     41 @param item Item to work on
     42 @param priv Private data passed on init
    2943 */
    30 typedef void worker_func_t(struct worker_item_s *item, void *priv);
     44typedef WORKER_FUNC(worker_func_t);
    3145
    3246struct worker_thread_s
    3347{
     48    worker_internal_root_t to_handle;
     49   
     50    struct sched_context_s context;
     51    bool_t killed;
     52    lock_t lock;
    3453    worker_func_t *func;
    35     void *priv;
    36     // lock, queue, whatever
     54    void *func_priv;
    3755};
    3856
    3957/***/
    4058void worker_thread_init(struct worker_thread_s*,
     59                        void *stack,
     60                        size_t stack_size,
    4161                        worker_func_t *func,
    4262                        void *func_priv);
     
    4464/**
    4565 @this runs a context, i.e. this makes the worker ready for wake
    46  up. This does not make function to be called
     66 up. This waits until a work is pushed.
    4767 */
    4868void worker_thread_start(struct worker_thread_s*);
     
    6080
    6181 @param item The item to pass to the woken-up function
     82 @returns -EAGAIN if the thread is not started yet, -EINVAL if the
     83          thread already got killed, 0 if OK.
    6284 */
    63 void worker_thread_wakeup(struct worker_thread_s*, struct worker_item_s *item);
     85error_t worker_thread_wakeup(struct worker_thread_s*, struct worker_item_s *item);
    6486}}}
    65 
    66 Open questions:
    67  * Allow function to sucide worker context