aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunita Nadampalli2013-09-13 06:28:28 -0500
committerSunita Nadampalli2013-09-13 06:28:28 -0500
commit2951de0afaf2ce000d37ec8505b27b05924012dd (patch)
treee1f58fe24cb6f5ea99c7281ef449ce2958f872f1 /libdce.c
parent667b28c0f3f46db827e3060bb3604ec3d238f5e2 (diff)
downloadrepo-libdce-2951de0afaf2ce000d37ec8505b27b05924012dd.tar.gz
repo-libdce-2951de0afaf2ce000d37ec8505b27b05924012dd.tar.xz
repo-libdce-2951de0afaf2ce000d37ec8505b27b05924012dd.zip
[LIBDCE] Move semaphore handling into dce_sem_* methods
Inorder to unify semaphore handling across multiple OSes semphore calls are moved into dce_sem_* methods. Change-Id: I32e8fc2ffdbf9ee91365923a28dded7f1d8784ce Signed-off-by: Sunita Nadampalli <sunitan@ti.com>
Diffstat (limited to 'libdce.c')
-rw-r--r--libdce.c49
1 files changed, 40 insertions, 9 deletions
diff --git a/libdce.c b/libdce.c
index f7f6211..2b2b179 100644
--- a/libdce.c
+++ b/libdce.c
@@ -145,6 +145,40 @@ void dce_free(void *ptr)
145 memplugin_free(ptr); 145 memplugin_free(ptr);
146} 146}
147 147
148static inline int dce_sem_init(sem_t **sem)
149{
150 if (*sem)
151 return DCE_EOK;;
152
153 *sem = sem_open("/dce_semaphore", O_CREAT, S_IRWXU | S_IRWXO | S_IRWXG, 1);
154 return (*sem) ? DCE_EOK : SEM_FAILED;
155}
156
157static inline int dce_sem_wait(sem_t *sem)
158{
159 if (NULL == sem)
160 return DCE_EINVALID_INPUT;
161
162 return sem_wait(sem);
163}
164
165static inline int dce_sem_post(sem_t *sem)
166{
167 if (NULL == sem)
168 return DCE_EINVALID_INPUT;
169
170 return sem_post(sem);
171}
172
173static inline void dce_sem_close(sem_t **sem)
174{
175 if (NULL == *sem)
176 return;
177
178 sem_close(*sem);
179 *sem = NULL;
180}
181
148/*=====================================================================================*/ 182/*=====================================================================================*/
149/** dce_ipc_init : Initialize MmRpc. This function is called within Engine_open(). 183/** dce_ipc_init : Initialize MmRpc. This function is called within Engine_open().
150 * 184 *
@@ -213,11 +247,9 @@ Engine_Handle Engine_open(String name, Engine_Attrs *attrs, Engine_Error *ec)
213 247
214 _ASSERT(name != '\0', DCE_EINVALID_INPUT); 248 _ASSERT(name != '\0', DCE_EINVALID_INPUT);
215 249
216 if( dce_semaphore == NULL ) { 250 _ASSERT(dce_sem_init(&dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL);
217 _ASSERT((dce_semaphore = sem_open("/dce_semaphore", O_CREAT, S_IRWXU | S_IRWXO | S_IRWXG, 1)) != SEM_FAILED, DCE_ESEMAPHORE_FAIL);
218 }
219 /* Lock dce_ipc_init() and Engine_open() IPU call to prevent hang*/ 251 /* Lock dce_ipc_init() and Engine_open() IPU call to prevent hang*/
220 _ASSERT(sem_wait(dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL); 252 _ASSERT(dce_sem_wait(dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL);
221 253
222 /* Initialize IPC. In case of Error Deinitialize them */ 254 /* Initialize IPC. In case of Error Deinitialize them */
223 _ASSERT_AND_EXECUTE(dce_ipc_init() == DCE_EOK, DCE_EIPC_CREATE_FAIL, dce_ipc_deinit()); 255 _ASSERT_AND_EXECUTE(dce_ipc_init() == DCE_EOK, DCE_EIPC_CREATE_FAIL, dce_ipc_deinit());
@@ -255,7 +287,7 @@ Engine_Handle Engine_open(String name, Engine_Attrs *attrs, Engine_Error *ec)
255 287
256EXIT: 288EXIT:
257 /* Unlock dce_ipc_init() and Engine_open() IPU call */ 289 /* Unlock dce_ipc_init() and Engine_open() IPU call */
258 _ASSERT(sem_post(dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL); 290 _ASSERT(dce_sem_post(dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL);
259 291
260 memplugin_free(engine_open_msg); 292 memplugin_free(engine_open_msg);
261 if( engine_attrs ) { 293 if( engine_attrs ) {
@@ -278,7 +310,7 @@ Void Engine_close(Engine_Handle engine)
278 _ASSERT(engine != NULL, DCE_EINVALID_INPUT); 310 _ASSERT(engine != NULL, DCE_EINVALID_INPUT);
279 311
280 /* Lock dce_ipc_deinit() and Engine_close() IPU call */ 312 /* Lock dce_ipc_deinit() and Engine_close() IPU call */
281 _ASSERT(sem_wait(dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL); 313 _ASSERT(dce_sem_wait(dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL);
282 314
283 /* Marshall function arguments into the send buffer */ 315 /* Marshall function arguments into the send buffer */
284 Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_ENGINE_CLOSE, 1, 0, NULL); 316 Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_ENGINE_CLOSE, 1, 0, NULL);
@@ -293,9 +325,8 @@ EXIT:
293 dce_ipc_deinit(); 325 dce_ipc_deinit();
294 326
295 /* Unlock dce_ipc_deinit() and Engine_close() IPU call */ 327 /* Unlock dce_ipc_deinit() and Engine_close() IPU call */
296 _ASSERT(sem_post(dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL); 328 _ASSERT(dce_sem_post(dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL);
297 sem_close(dce_semaphore); 329 dce_sem_close(&dce_semaphore);
298
299 return; 330 return;
300} 331}
301 332