DSPBRIDGE: modify sync event functions to use completions instead of sems
Subsystems (2)
PATCH 3/4 DSPBRIDGE: modify sync event functions to use completions instead of sems
Quoted 1 line
From
fe3614b420203e22e4e30125ccdef05c8786f595Mon Sep 17 00:00:00 2001
From: Fernando Guzman Lugo <[email protected]>
Date: Tue, 23 Mar 2010 19:59:38 -0600
Subject: [PATCH] DSPBRIDGE: modify sync event functions to use completions instead of sems
This functions modifies sync event functions to use completions instead of semaphores and also simplifies the code.
Signed-off-by Fernando Guzman Lugo <[email protected]>
--- arch/arm/plat-omap/include/dspbridge/sync.h | 201 +++++++-------------- drivers/dsp/bridge/rmgr/node.c | 12 +- drivers/dsp/bridge/rmgr/strm.c | 4 +- drivers/dsp/bridge/services/ntfy.c | 16 +- drivers/dsp/bridge/services/sync.c | 259 +++++++-------------------- drivers/dsp/bridge/wmd/chnl_sm.c | 17 +- drivers/dsp/bridge/wmd/msg_sm.c | 51 ++++-- 7 files changed, 195 insertions(+), 365 deletions(-)
arch/arm/plat-omap/include/dspbridge/sync.h +70 -131
@@ -19,6 +19,7 @@#ifndef _SYNC_H#define _SYNC_H +#include <dspbridge/errbase.h> #define SIGNATURECS 0x53435953/* "SYCS" (in reverse) */ #define SIGNATUREDPCCS 0x53445953/* "SYDS" (in reverse) */
@@ -28,8 +29,16 @@/* Maximum string length of a named event */ #define SYNC_MAXNAMELENGTH 32 -/* Generic SYNC object: */ -struct sync_object ; +/** +* struct sync_object - the basic sync_object structure +* @comp: use to signal events +* @multi_comp: use to signal multiple events. +* +*/ +struct sync_object { +struct completion comp; +struct completion *multi_comp; +};/* Generic SYNC CS object: */ struct sync_csobject {
@@ -46,25 +55,6 @@ struct sync_attrs { };/* -* ======== sync_close_event ======== -* Purpose: -* Close this event handle, freeing resources allocated in sync_open_event -* if necessary. -* Parameters: -* event_obj: Handle to a synchronization event, created/opened in -* sync_open_event. -* Returns: -* DSP_SOK: Success; -* DSP_EFAIL: Failed to close event handle. -* DSP_EHANDLE: Invalid handle. -* Requires: -* SYNC initialized. -* Ensures: -* Any subsequent usage of event_obj would be invalid. -*/ -extern dsp_status sync_close_event(IN struct sync_object *event_obj); - -/* * ======== sync_delete_cs ======== * Purpose: * Delete a critical section.
@@ -162,39 +152,18 @@ extern dsp_status sync_initialize_dpccs(OUT struct sync_csobject*/ extern dsp_status sync_leave_cs(IN struct sync_csobject *hcs_obj); -/* -* ======== sync_open_event ======== -* Purpose: -* Create/open and initialize an event object for thread synchronization, -* which is initially in the non-signalled state. -* Parameters: -* ph_event: Pointer to location to receive the event object handle. -* pattrs: Pointer to sync_attrs object containing initial SYNC -* sync_object attributes. If this pointer is NULL, then -* sync_open_event will create and manage an OS specific -* syncronization object. -* pattrs->user_event: Platform's User Mode synchronization object. -* -* The behaviour of the SYNC methods depend on the value of -* the user_event attr: +/** +* sync_init_event() - set initial state for a sync_event element +* @event: event to be initialized. * -* 1. (user_event == NULL): -* A user mode event is created. -* 2. (user_event != NULL): -* A user mode event is supplied by the caller of sync_open_event(). -* Returns: -* DSP_SOK: Success. -* DSP_EFAIL: Unable to create user mode event. -* DSP_EMEMORY: Insufficient memory. -* DSP_EINVALIDARG sync_attrs values are invalid. -* Requires: -* - SYNC initialized. -* - ph_event != NULL. -* Ensures: -* If function succeeded, event->event_obj must be a valid event handle. +* Set the initial state for a sync_event element. */ -extern dsp_status sync_open_event(OUT struct sync_object **ph_event, - IN OPTIONAL struct sync_attrs *pattrs); + +static inline void sync_init_event (struct sync_object *event) +{ +init_completion (&event->comp); + event->multi_comp =NULL ; +}/* * ========= sync_post_message ========
@@ -213,91 +182,61 @@ extern dsp_status sync_open_event(OUT struct sync_object **ph_event,*/ extern dsp_status sync_post_message(IN bhandle hWindow, IN u32 uMsg); -/* -* ======== sync_reset_event ======== -* Purpose: -* Reset a syncronization event object state to non-signalled. -* Parameters: -* event_obj: Handle to a sync event. -* Returns: -* DSP_SOK: Success; -* DSP_EFAIL: Failed to reset event. -* DSP_EHANDLE: Invalid handle. -* Requires: -* SYNC initialized. -* Ensures: +/** +* sync_reset_event() - reset a sync_event element +* @event: event to be reset. +* +* This function reset to the initial state to @event. */ -extern dsp_status sync_reset_event(IN struct sync_object *event_obj); -/* -* ======== sync_set_event ======== -* Purpose: -* Signal the event. Will unblock one waiting thread. -* Parameters: -* event_obj: Handle to an event object. -* Returns: -* DSP_SOK: Success. -* DSP_EFAIL: Failed to signal event. -* DSP_EHANDLE: Invalid handle. -* Requires: -* SYNC initialized. -* Ensures: +static inline void sync_reset_event (struct sync_object *event) +{ +INIT_COMPLETION (event->comp); + event->multi_comp =NULL ; +} + +/** +* sync_set_event() - set or signal and specified event +* @event: Event to be set.. +* +* set the @event, if there is an thread waiting for the event +* it will be waken up, this function only wakes one thread. */ -extern dsp_status sync_set_event(IN struct sync_object *event_obj); -/* -* ======== sync_wait_on_event ======== -* Purpose: -* Wait for an event to be signalled, up to the specified timeout. -* Parameters: -* event_obj: Handle to an event object. -* dwTimeOut: The time-out interval, in milliseconds. -* The function returns if the interval elapses, even if -* the object's state is nonsignaled. -* If zero, the function tests the object's state and -* returns immediately. -* If SYNC_INFINITE, the function's time-out interval -* never elapses. -* Returns: -* DSP_SOK: The object was signalled. -* DSP_EHANDLE: Invalid handle. -* SYNC_E_FAIL: Wait failed, possibly because the process terminated. -* SYNC_E_TIMEOUT: Timeout expired while waiting for event to be signalled. -* Requires: -* Ensures: +void sync_set_event (struct sync_object *event); + +/** +* sync_wait_on_event() - waits for a event to be set. +* @event: events to wait for it. +* @timeout timeout on waiting for the evetn. +* +* This functios will wait until @event is set or until timeout. In case of +* success the function will return DSP_SOK and +* in case of timeout the function will return DSP_ETIMEOUT */ -extern dsp_status sync_wait_on_event(IN struct sync_object *event_obj, - IN u32 dwTimeOut); -/* -* ======== sync_wait_on_multiple_events ======== -* Purpose: -* Wait for any of an array of events to be signalled, up to the -* specified timeout. -* Note: dwTimeOut must be SYNC_INFINITE to signal infinite wait. -* Parameters: -* sync_events: Array of handles to event objects. -* count: Number of event handles. -* dwTimeOut: The time-out interval, in milliseconds. -* The function returns if the interval elapses, even if -* no event is signalled. -* If zero, the function tests the object's state and -* returns immediately. -* If SYNC_INFINITE, the function's time-out interval -* never elapses. -* pu_index: Location to store index of event that was signalled. -* Returns: -* DSP_SOK: The object was signalled. -* SYNC_E_FAIL: Wait failed, possibly because the process terminated. -* SYNC_E_TIMEOUT: Timeout expired before event was signalled. -* DSP_EMEMORY: Memory allocation failed. -* Requires: -* Ensures: +static inline dsp_status sync_wait_on_event (struct sync_object *event, +unsigned timeout) +{ +return wait_for_completion_timeout (&event->comp, +msecs_to_jiffies (timeout)) ?DSP_SOK :DSP_ETIMEOUT ; +} + +/** +* sync_wait_on_multiple_events() - waits for multiple events to be set. +* @events: Array of events to wait for them. +* @count: number of elements of the array. +* @timeout timeout on waiting for the evetns. +* @pu_index index of the event set. +* +* This functios will wait until any of the array element is set or until +* timeout. In case of success the function will return DSP_SOK and +* @pu_index will store the index of the array element set and in case +* of timeout the function will return DSP_ETIMEOUT. */ -extern dsp_status sync_wait_on_multiple_events(IN struct sync_object - **sync_events, - IN u32 count, - IN u32 dwTimeout, - OUT u32 *pu_index); + +dsp_status sync_wait_on_multiple_events (struct sync_object **events, +unsigned count,unsigned timeout, +unsigned *index);#endif /* _SYNC_H */
drivers/dsp/bridge/rmgr/node.c +9 -3
@@ -515,7 +515,13 @@ func_cont:if (DSP_SUCCEEDED (status) && (node_type !=NODE_DEVICE )) {/* Create an event that will be posted when RMS_EXIT is * received. */ - status =sync_open_event (&pnode->sync_done,NULL ); + pnode->sync_done =kzalloc (sizeof (struct sync_object ), +GFP_KERNEL ); +if (pnode->sync_done) +sync_init_event (pnode->sync_done); +else + status =DSP_EMEMORY ; +if (DSP_SUCCEEDED (status)) {/*Get the shared mem mgr for this nodes dev object */ status =cmm_get_handle (hprocessor, &hcmm_mgr);
@@ -2533,8 +2539,8 @@ static void delete_node(struct node_object *hnode, msg_queue_obj); hnode->msg_queue_obj =NULL ; } -if (hnode->sync_done) - (void )sync_close_event (hnode->sync_done); + +kfree (hnode->sync_done);/* Free all stream info */ if (hnode->inputs) {
drivers/dsp/bridge/rmgr/strm.c +2 -2
@@ -789,8 +789,8 @@ dsp_status strm_select(IN struct strm_object **strm_tab, u32 nStrms,if (DSP_SUCCEEDED (status) && utimeout >0 && *pmask ==0 ) {/* Non-zero timeout */ sync_events = (struct sync_object **)mem_alloc (nStrms * -sizeof (struct sync_object *), -MEM_PAGED ); +sizeof (struct sync_object *),MEM_PAGED ); +if (sync_events ==NULL ) { status =DSP_EMEMORY ; }else {
drivers/dsp/bridge/services/ntfy.c +9 -7
@@ -201,7 +201,6 @@ dsp_status ntfy_register(struct ntfy_object *ntfy_obj, u32 event_mask, u32 notify_type) {struct notifier *notifier_obj; -struct sync_attrs sync_attrs_obj;dsp_status status =DSP_SOK ;DBC_REQUIRE (MEM_IS_VALID_HANDLE (ntfy_obj,NTFY_SIGNATURE ));
@@ -251,9 +250,14 @@ dsp_status ntfy_register(struct ntfy_object *ntfy_obj,lst_init_elem ((struct list_head *)notifier_obj);/* If there is more than one notification type, each * type may require its own handler code. */ - status = -sync_open_event (¬ifier_obj->sync_obj, - &sync_attrs_obj); + notifier_obj->sync_obj =kzalloc ( +sizeof (struct sync_object ),GFP_KERNEL ); + +if (notifier_obj->sync_obj) +sync_init_event (notifier_obj->sync_obj); +else + status =DSP_EMEMORY ; + hnotification->handle = notifier_obj->sync_obj;if (DSP_SUCCEEDED (status)) {
@@ -288,9 +292,7 @@ dsp_status ntfy_register(struct ntfy_object *ntfy_obj,*/ static void delete_notify (struct notifier *notifier_obj) { -if (notifier_obj->sync_obj) - (void )sync_close_event (notifier_obj->sync_obj); - +kfree (notifier_obj->sync_obj);kfree (notifier_obj->pstr_name);kfree (notifier_obj);
drivers/dsp/bridge/services/sync.c +63 -200
304 lines not on this page · raw message
drivers/dsp/bridge/wmd/chnl_sm.c +10 -7
@@ -353,7 +353,7 @@ func_cont:* context.). */ if (pchnl->sync_event) {sync_reset_event (pchnl->sync_event); -sync_close_event (pchnl->sync_event); +kfree (pchnl->sync_event); pchnl->sync_event =NULL ; }/* Free I/O request and I/O completion queues: */
@@ -789,7 +789,6 @@ dsp_status bridge_chnl_open(OUT struct chnl_object **phChnl,dsp_status status =DSP_SOK ;struct chnl_mgr *chnl_mgr_obj = hchnl_mgr;struct chnl_object *pchnl =NULL ; -struct sync_attrs *sync_attr_obj =NULL ;struct sync_object *sync_event =NULL ;/* Ensure DBC requirements: */ DBC_REQUIRE (phChnl !=NULL );
@@ -835,7 +834,12 @@ dsp_status bridge_chnl_open(OUT struct chnl_object **phChnl, pchnl->chnl_packets = pattrs->uio_reqs; pchnl->cio_cs =0 ; pchnl->cio_reqs =0 ; - status =sync_open_event (&sync_event, sync_attr_obj); + sync_event =kzalloc (sizeof (struct sync_object ),GFP_KERNEL ); +if (sync_event) +sync_init_event (sync_event); +else + status =DSP_EMEMORY ; +if (DSP_SUCCEEDED (status)) status =ntfy_create (&pchnl->ntfy_obj);
@@ -874,10 +878,9 @@ dsp_status bridge_chnl_open(OUT struct chnl_object **phChnl,free_chirp_list (pchnl->free_packets_list); pchnl->free_packets_list =NULL ; } -if (sync_event) { -sync_close_event (sync_event); - sync_event =NULL ; - } +kfree (sync_event); + sync_event =NULL ; +if (pchnl->ntfy_obj) {ntfy_delete (pchnl->ntfy_obj); pchnl->ntfy_obj =NULL ;
drivers/dsp/bridge/wmd/msg_sm.c +34 -17
82 lines not on this page · raw message
--
1.6.0.4