Thread Worker =================== Threading, locking, and handoff between libev and python --------------------------------- Definitions --------------------------------- .. c:struct:: ymo_wsgi_worker Data structure which represents a single thread worker. .. code-block:: c :caption: Definition struct ymo_wsgi_worker { ymo_queue_t queue_in; ymo_queue_t queue_out; ymo_queue_node_t pool_in[YMO_WSGI_WORKER_QUEUE_POOL_SIZE]; ymo_queue_node_t pool_out[YMO_WSGI_WORKER_QUEUE_POOL_SIZE]; /* Callbacks: */ ev_prepare prepare_watcher; ev_check check_watcher; ev_idle idle_watcher; /* Output data is signalled to the evloop using an async watcher: */ ev_async event_out; pthread_mutex_t lock_out; /* Inbound data is signalled using a condition var: */ pthread_mutex_t lock_in; pthread_cond_t ready_in; /* And the thread itself: */ pthread_t thread; size_t id; int running; }; --------------------------------- Functions --------------------------------- .. c:function:: ymo_status_t ymo_wsgi_worker_init( struct ev_loop* loop, size_t thread_id, ymo_wsgi_worker_t* worker) Initialize a worker thread. .. c:function:: ymo_status_t ymo_wsgi_worker_start(ymo_wsgi_worker_t* worker) Start a worker thread. .. c:function:: static inline int ymo_wsgi_worker_lock_in(ymo_wsgi_worker_t* worker) Lock the worker input queue. .. c:function:: static inline int ymo_wsgi_worker_unlock_in(ymo_wsgi_worker_t* worker) Unlock the worker input queue. .. c:function:: static inline int ymo_wsgi_worker_lock_out(ymo_wsgi_worker_t* worker) Lock the worker output queue. .. c:function:: static inline int ymo_wsgi_worker_unlock_out(ymo_wsgi_worker_t* worker) Unlock the worker output queue. .. c:function:: ymo_status_t ymo_wsgi_worker_add_exchange( ymo_wsgi_worker_t* worker, ymo_wsgi_exchange_t* exchange) Add an exchange to the workers input queue. .. c:function:: ymo_status_t ymo_wsgi_worker_response_body_append( ymo_wsgi_exchange_t* exchange, ymo_bucket_t* body_item, int done) Append body data to the response on in the output queue. .. c:function:: ymo_status_t ymo_wsgi_worker_notify(ymo_wsgi_worker_t* worker) Signals across thread boundaries to notify a worker that input data is available for processing. .. c:function:: int ymo_wsgi_worker_join(ymo_wsgi_worker_t* worker) Join the worker thread.