[Cbe-oss-dev] [PATCH 20/22]MARS/task: destroy check no waiting tasks

Yuji Mano yuji.mano at am.sony.com
Fri Mar 20 07:54:54 EST 2009


This patch updates task synchronization objects' destroy function so it checks
whether there are any tasks still waiting on it and returns error if there are.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 task/include/host/mars/task_barrier.h    |    1 +
 task/include/host/mars/task_event_flag.h |    1 +
 task/include/host/mars/task_queue.h      |    1 +
 task/include/host/mars/task_semaphore.h  |    1 +
 task/src/host/lib/task_barrier.c         |   13 +++++++++++++
 task/src/host/lib/task_event_flag.c      |   13 +++++++++++++
 task/src/host/lib/task_queue.c           |    4 ++++
 task/src/host/lib/task_semaphore.c       |   13 +++++++++++++
 8 files changed, 47 insertions(+)

--- a/task/include/host/mars/task_barrier.h
+++ b/task/include/host/mars/task_barrier.h
@@ -93,6 +93,7 @@ int mars_task_barrier_create(struct mars
  *	MARS_SUCCESS		- successfully destroyed barrier
  * \n	MARS_ERROR_NULL		- null pointer specified
  * \n	MARS_ERROR_ALIGN	- ea not properly aligned
+ * \n	MARS_ERROR_STATE	- tasks still waiting
  */
 int mars_task_barrier_destroy(uint64_t barrier_ea);
 
--- a/task/include/host/mars/task_event_flag.h
+++ b/task/include/host/mars/task_event_flag.h
@@ -104,6 +104,7 @@ int mars_task_event_flag_create(struct m
  *	MARS_SUCCESS		- successfully destroyed event flag
  * \n	MARS_ERROR_NULL		- null pointer specified
  * \n	MARS_ERROR_ALIGN	- ea not properly aligned
+ * \n	MARS_ERROR_STATE	- tasks still waiting
  */
 int mars_task_event_flag_destroy(uint64_t event_flag_ea);
 
--- a/task/include/host/mars/task_queue.h
+++ b/task/include/host/mars/task_queue.h
@@ -112,6 +112,7 @@ int mars_task_queue_create(struct mars_c
  *	MARS_SUCCESS		- successfully destroyed queue
  * \n	MARS_ERROR_NULL		- null pointer specified
  * \n	MARS_ERROR_ALIGN	- ea not properly aligned
+ * \n	MARS_ERROR_STATE	- tasks still waiting
  */
 int mars_task_queue_destroy(uint64_t queue_ea);
 
--- a/task/include/host/mars/task_semaphore.h
+++ b/task/include/host/mars/task_semaphore.h
@@ -92,6 +92,7 @@ int mars_task_semaphore_create(struct ma
  *	MARS_SUCCESS		- successfully destroyed semaphore
  * \n	MARS_ERROR_NULL		- null pointer specified
  * \n	MARS_ERROR_ALIGN	- ea not properly aligned
+ * \n	MARS_ERROR_STATE	- tasks still waiting
  */
 int mars_task_semaphore_destroy(uint64_t semaphore_ea);
 
--- a/task/src/host/lib/task_barrier.c
+++ b/task/src/host/lib/task_barrier.c
@@ -93,10 +93,23 @@ int mars_task_barrier_create(struct mars
 
 int mars_task_barrier_destroy(uint64_t barrier_ea)
 {
+	struct mars_task_barrier *barrier;
+
 	/* check function params */
 	if (!barrier_ea)
 		return MARS_ERROR_NULL;
 
+	/* prepare work area */
+	barrier = mars_ea_work_area_get(barrier_ea,
+					MARS_TASK_BARRIER_ALIGN,
+					MARS_TASK_BARRIER_SIZE);
+
+	mars_ea_get(barrier_ea, barrier, MARS_TASK_BARRIER_SIZE);
+
+	/* make sure no tasks in wait list */
+	if (barrier->wait_count)
+		return MARS_ERROR_STATE;
+
 	mars_ea_free(barrier_ea);
 
 	return MARS_SUCCESS;
--- a/task/src/host/lib/task_event_flag.c
+++ b/task/src/host/lib/task_event_flag.c
@@ -109,10 +109,23 @@ int mars_task_event_flag_create(struct m
 
 int mars_task_event_flag_destroy(uint64_t event_flag_ea)
 {
+	struct mars_task_event_flag *event_flag;
+
 	/* check function params */
 	if (!event_flag_ea)
 		return MARS_ERROR_NULL;
 
+	/* prepare work area */
+	event_flag = mars_ea_work_area_get(event_flag_ea,
+					   MARS_TASK_EVENT_FLAG_ALIGN,
+					   MARS_TASK_EVENT_FLAG_SIZE);
+
+	mars_ea_get(event_flag_ea, event_flag, MARS_TASK_EVENT_FLAG_SIZE);
+
+	/* make sure no tasks in wait list */
+	if (event_flag->wait_count)
+		return MARS_ERROR_STATE;
+
 	mars_ea_free(event_flag_ea);
 
 	return MARS_SUCCESS;
--- a/task/src/host/lib/task_queue.c
+++ b/task/src/host/lib/task_queue.c
@@ -136,6 +136,10 @@ int mars_task_queue_destroy(uint64_t que
 
 	mars_ea_get(queue_ea, queue, MARS_TASK_QUEUE_SIZE);
 
+	/* make sure no tasks in wait list */
+	if (queue->push_wait_count || queue->pop_wait_count)
+		return MARS_ERROR_STATE;
+
 	/* free shared memory */
 	mars_ea_free(queue->buffer_ea);
 	mars_ea_free(queue_ea);
--- a/task/src/host/lib/task_semaphore.c
+++ b/task/src/host/lib/task_semaphore.c
@@ -89,10 +89,23 @@ int mars_task_semaphore_create(struct ma
 
 int mars_task_semaphore_destroy(uint64_t semaphore_ea)
 {
+	struct mars_task_semaphore *semaphore;
+
 	/* check function params */
 	if (!semaphore_ea)
 		return MARS_ERROR_NULL;
 
+	/* prepare work area */
+	semaphore = mars_ea_work_area_get(semaphore_ea,
+					  MARS_TASK_SEMAPHORE_ALIGN,
+					  MARS_TASK_SEMAPHORE_SIZE);
+
+	mars_ea_get(semaphore_ea, semaphore, MARS_TASK_SEMAPHORE_SIZE);
+
+	/* make sure no tasks in wait list */
+	if (semaphore->wait_count)
+		return MARS_ERROR_STATE;
+
 	mars_ea_free(semaphore_ea);
 
 	return MARS_SUCCESS;





More information about the cbe-oss-dev mailing list