[Cbe-oss-dev] [PATCH 12/17]MARS/modules/task: Host api use ea

Yuji Mano yuji.mano at am.sony.com
Wed Nov 26 14:40:27 EST 2008


From: Kazunori Asayama <asayama at sm.sony.co.jp>

Change type of MARS object from pointer to uint64_t

Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
---
 modules/task/include/host/mars/task_barrier.h    |    8 +-
 modules/task/include/host/mars/task_event_flag.h |   26 +++----
 modules/task/include/host/mars/task_queue.h      |   40 +++++------
 modules/task/include/host/mars/task_semaphore.h  |    8 +-
 modules/task/src/host/lib/task.c                 |   30 ++++----
 modules/task/src/host/lib/task_barrier.c         |   17 ++--
 modules/task/src/host/lib/task_event_flag.c      |   63 +++++++++--------
 modules/task/src/host/lib/task_queue.c           |   83 +++++++++++++----------
 modules/task/src/host/lib/task_semaphore.c       |   17 ++--
 9 files changed, 161 insertions(+), 131 deletions(-)

--- a/modules/task/include/host/mars/task_barrier.h
+++ b/modules/task/include/host/mars/task_barrier.h
@@ -70,7 +70,7 @@ extern "C" {
  * - Total must be a value between 1 and \ref MARS_TASK_BARRIER_WAIT_MAX.
  *
  * \param[in] mars		- pointer to MARS context
- * \param[out] barrier		- address of pointer to barrier instance
+ * \param[out] barrier_ea	- address of 64-bit address of barrier instance
  * \param[in] total		- number of notifies before barrier released
  * \return
  *	MARS_SUCCESS		- successfully created barrier
@@ -78,7 +78,7 @@ extern "C" {
  * \n	MARS_ERROR_PARAMS	- total exceeds allowed limit
  */
 int mars_task_barrier_create(struct mars_context *mars,
-				struct mars_task_barrier **barrier,
+				uint64_t *barrier_ea,
 				uint32_t total);
 
 /**
@@ -88,13 +88,13 @@ int mars_task_barrier_create(struct mars
  * This function will free any resources allocated during creation of the task
  * barrier.
  *
- * \param[in] barrier		- pointer to barrier instance
+ * \param[in] barrier_ea	- 64-bit address of barrier instance
  * \return
  *	MARS_SUCCESS		- successfully destroyed barrier
  * \n	MARS_ERROR_NULL		- null pointer specified
  * \n	MARS_ERROR_ALIGN	- instance not properly aligned
  */
-int mars_task_barrier_destroy(struct mars_task_barrier *barrier);
+int mars_task_barrier_destroy(uint64_t barrier_ea);
 
 #if defined(__cplusplus)
 }
--- a/modules/task/include/host/mars/task_event_flag.h
+++ b/modules/task/include/host/mars/task_event_flag.h
@@ -79,7 +79,7 @@ extern "C" {
  * \ref mars_task_event_flag_clear.
  *
  * \param[in] mars		- pointer to MARS context
- * \param[out] event_flag	- address of pointer to event flag instance
+ * \param[out] event_flag_ea	- address of 64-bit address of event flag instance
  * \param[in] direction		- direction of the event flag
  * \param[in] clear_mode	- behavior of how the event flag is cleared
  * \return
@@ -88,7 +88,7 @@ extern "C" {
  * \n	MARS_ERROR_PARAMS	- invalid direction or clear mode specified
  */
 int mars_task_event_flag_create(struct mars_context *mars,
-				struct mars_task_event_flag **event_flag,
+				uint64_t *event_flag_ea,
 				uint8_t direction,
 				uint8_t clear_mode);
 
@@ -99,13 +99,13 @@ int mars_task_event_flag_create(struct m
  * This function will free any resources allocated during creation of the task
  * event flag.
  *
- * \param[in] event_flag	- pointer to event flag instance
+ * \param[in] event_flag_ea	- 64-bit address of event flag instance
  * \return
  *	MARS_SUCCESS		- successfully destroyed event flag
  * \n	MARS_ERROR_NULL		- null pointer specified
  * \n	MARS_ERROR_ALIGN	- instance not properly aligned
  */
-int mars_task_event_flag_destroy(struct mars_task_event_flag *event_flag);
+int mars_task_event_flag_destroy(uint64_t event_flag_ea);
 
 /**
  * \ingroup group_mars_task_event_flag
@@ -119,15 +119,14 @@ int mars_task_event_flag_destroy(struct 
  * \e bits
  * - Specify only the bits you want to be cleared from the event flag bits.
  *
- * \param[in] event_flag	- pointer to event flag instance
+ * \param[in] event_flag_ea	- 64-bit address of event flag instance
  * \param[in] bits		- bits to clear
  * \return
  *	MARS_SUCCESS		- successfully cleared event flag bits
  * \n	MARS_ERROR_NULL		- null pointer specified
  * \n	MARS_ERROR_ALIGN	- instance not aligned properly
  */
-int mars_task_event_flag_clear(struct mars_task_event_flag *event_flag,
-				uint32_t bits);
+int mars_task_event_flag_clear(uint64_t event_flag_ea, uint32_t bits);
 
 /**
  * \ingroup group_mars_task_event_flag
@@ -144,7 +143,7 @@ int mars_task_event_flag_clear(struct ma
  * \e bits
  * - Specify only the bits you want to set in the event flag bits.
  *
- * \param[in] event_flag	- pointer to event flag instance
+ * \param[in] event_flag_ea	- 64-bit address of event flag instance
  * \param[in] bits		- bits to set
  * \return
  *	MARS_SUCCESS		- successfully cleared event flag bits
@@ -152,8 +151,7 @@ int mars_task_event_flag_clear(struct ma
  * \n	MARS_ERROR_ALIGN	- instance not aligned properly
  * \n	MARS_ERROR_STATE	- invalid direction
  */
-int mars_task_event_flag_set(struct mars_task_event_flag *event_flag,
-				uint32_t bits);
+int mars_task_event_flag_set(uint64_t event_flag_ea, uint32_t bits);
 
 /**
  * \ingroup group_mars_task_event_flag
@@ -182,7 +180,7 @@ int mars_task_event_flag_set(struct mars
  * automatic clearing of bits (if \ref MARS_TASK_EVENT_FLAG_CLEAR_AUTO was
  * specified at creation).
  *
- * \param[in] event_flag	- pointer to event flag instance
+ * \param[in] event_flag_ea	- 64-bit address of event flag instance
  * \param[in] mask		- bit mask to test event flag bits against
  * \param[in] mask_mode		- specifies how to mask bits (AND, OR)
  * \param[out] bits		- pointer to instance to store bits upon release
@@ -193,7 +191,7 @@ int mars_task_event_flag_set(struct mars
  * \n	MARS_ERROR_PARAMS	- invalid mask mode
  * \n	MARS_ERROR_STATE	- invalid direction
  */
-int mars_task_event_flag_wait(struct mars_task_event_flag *event_flag,
+int mars_task_event_flag_wait(uint64_t event_flag_ea,
 				uint32_t mask, uint8_t mask_mode,
 				uint32_t *bits);
 
@@ -226,7 +224,7 @@ int mars_task_event_flag_wait(struct mar
  * automatic clearing of bits (if \ref MARS_TASK_EVENT_FLAG_CLEAR_AUTO was
  * specified at creation).
  *
- * \param[in] event_flag	- pointer to event flag instance
+ * \param[in] event_flag_ea	- 64-bit address of event flag instance
  * \param[in] mask		- bit mask to test event flag bits against
  * \param[in] mask_mode		- specifies how to mask bits (AND, OR)
  * \param[out] bits		- pointer to instance to store bits upon release
@@ -238,7 +236,7 @@ int mars_task_event_flag_wait(struct mar
  * \n	MARS_ERROR_STATE	- invalid direction
  * \n	MARS_ERROR_BUSY		- event not yet received
  */
-int mars_task_event_flag_try_wait(struct mars_task_event_flag *event_flag,
+int mars_task_event_flag_try_wait(uint64_t event_flag_ea,
 				uint32_t mask, uint8_t mask_mode,
 				uint32_t *bits);
 
--- a/modules/task/include/host/mars/task_queue.h
+++ b/modules/task/include/host/mars/task_queue.h
@@ -82,7 +82,7 @@ extern "C" {
  * \ref MARS_TASK_QUEUE_MPU_TO_HOST, \ref MARS_TASK_QUEUE_MPU_TO_MPU.
  *
  * \param[in] mars		- pointer to MARS context
- * \param[out] queue		- address of pointer to queue instance
+ * \param[out] queue_ea		- address of 64-bit address of queue instance
  * \param[in] size		- size of each data item in data buffer
  * \param[in] depth		- maximum number of data entries in data buffer
  * \param[in] direction		- direction of the event flag
@@ -95,7 +95,7 @@ extern "C" {
  * \n	MARS_ERROR_PARAMS	- invalid direction specified
  */
 int mars_task_queue_create(struct mars_context *mars,
-				struct mars_task_queue **queue,
+				uint64_t *queue_ea,
 				uint32_t size,
 				uint32_t depth,
 				uint8_t direction);
@@ -107,13 +107,13 @@ int mars_task_queue_create(struct mars_c
  * This function will free any resources allocated during creation of the task
  * queue.
  *
- * \param[in] queue		- pointer to queue instance
+ * \param[in] queue_ea		- 64-bit address of queue instance
  * \return
  *	MARS_SUCCESS		- successfully destroyed queue
  * \n	MARS_ERROR_NULL		- null pointer specified
  * \n	MARS_ERROR_ALIGN	- instance not properly aligned
  */
-int mars_task_queue_destroy(struct mars_task_queue *queue);
+int mars_task_queue_destroy(uint64_t queue_ea);
 
 /**
  * \ingroup group_mars_task_queue
@@ -122,14 +122,14 @@ int mars_task_queue_destroy(struct mars_
  * This function will return the total number of data items in the queue at the
  * time of the call.
  *
- * \param[in] queue		- pointer to queue instance
+ * \param[in] queue_ea		- 64-bit address of queue instance
  * \param[out] count		- pointer to variable to store return count
  * \return
  *	MARS_SUCCESS		- successfully returned count
  * \n	MARS_ERROR_NULL		- null pointer specified
  * \n	MARS_ERROR_ALIGN	- instance not aligned properly
  */
-int mars_task_queue_count(struct mars_task_queue *queue, uint32_t *count);
+int mars_task_queue_count(uint64_t queue_ea, uint32_t *count);
 
 /**
  * \ingroup group_mars_task_queue
@@ -139,13 +139,13 @@ int mars_task_queue_count(struct mars_ta
  * Tasks waiting to pop data from the queue will remain waiting.
  * Tasks waiting to push data into the queue will resume.
  *
- * \param[in] queue		- pointer to queue instance
+ * \param[in] queue_ea		- 64-bit address of queue instance
  * \return
  *	MARS_SUCCESS		- successfully cleared queue
  * \n	MARS_ERROR_NULL		- null pointer specified
  * \n	MARS_ERROR_ALIGN	- instance not aligned properly
  */
-int mars_task_queue_clear(struct mars_task_queue *queue);
+int mars_task_queue_clear(uint64_t queue_ea);
 
 /**
  * \ingroup group_mars_task_queue
@@ -163,7 +163,7 @@ int mars_task_queue_clear(struct mars_ta
  * - Specify the pointer to user data to copy into the queue.
  * - The size of data should be equal to the size specified at queue creation.
  *
- * \param[in] queue		- pointer to queue instance
+ * \param[in] queue_ea		- 64-bit address of queue instance
  * \param[in] data		- address of data to be pushed into queue
  * \return
  *	MARS_SUCCESS		- successfully pushed data into queue
@@ -171,7 +171,7 @@ int mars_task_queue_clear(struct mars_ta
  * \n	MARS_ERROR_ALIGN	- instance not aligned properly
  * \n	MARS_ERROR_STATE	- invalid direction
  */
-int mars_task_queue_push(struct mars_task_queue *queue, const void *data);
+int mars_task_queue_push(uint64_t queue_ea, const void *data);
 
 /**
  * \ingroup group_mars_task_queue
@@ -189,7 +189,7 @@ int mars_task_queue_push(struct mars_tas
  * - Specify the pointer to user data to copy into the queue.
  * - The size of data should be equal to the size specified at queue creation.
  *
- * \param[in] queue		- pointer to queue instance
+ * \param[in] queue_ea		- 64-bit address of queue instance
  * \param[in] data		- address of data to be pushed into queue
  * \return
  *	MARS_SUCCESS		- successfully pushed data into queue
@@ -198,7 +198,7 @@ int mars_task_queue_push(struct mars_tas
  * \n	MARS_ERROR_BUSY		- queue is full
  * \n	MARS_ERROR_STATE	- invalid direction
  */
-int mars_task_queue_try_push(struct mars_task_queue *queue, const void *data);
+int mars_task_queue_try_push(uint64_t queue_ea, const void *data);
 
 /**
  * \ingroup group_mars_task_queue
@@ -216,7 +216,7 @@ int mars_task_queue_try_push(struct mars
  * - The size of the allocated memory area should be equal to the size specified
  * at queue creation.
  *
- * \param[in] queue		- pointer to task instance
+ * \param[in] queue_ea		- 64-bit address of queue instance
  * \param[in] data		- address of data to be popped from queue
  * \return
  *	MARS_SUCCESS		- successfully received event
@@ -224,7 +224,7 @@ int mars_task_queue_try_push(struct mars
  * \n	MARS_ERROR_ALIGN	- instance not aligned properly
  * \n	MARS_ERROR_STATE	- invalid direction
  */
-int mars_task_queue_pop(struct mars_task_queue *queue, void *data);
+int mars_task_queue_pop(uint64_t queue_ea, void *data);
 
 /**
  * \ingroup group_mars_task_queue
@@ -242,7 +242,7 @@ int mars_task_queue_pop(struct mars_task
  * - The size of the allocated memory area should be equal to the size specified
  * at queue creation.
  *
- * \param[in] queue		- pointer to task instance
+ * \param[in] queue_ea		- 64-bit address of queue instance
  * \param[in] data		- address of data to be popped from queue
  * \return
  *	MARS_SUCCESS		- successfully received event
@@ -251,7 +251,7 @@ int mars_task_queue_pop(struct mars_task
  * \n	MARS_ERROR_BUSY		- queue is empty
  * \n	MARS_ERROR_STATE	- invalid direction
  */
-int mars_task_queue_try_pop(struct mars_task_queue *queue, void *data);
+int mars_task_queue_try_pop(uint64_t queue_ea, void *data);
 
 /**
  * \ingroup group_mars_task_queue
@@ -270,7 +270,7 @@ int mars_task_queue_try_pop(struct mars_
  * - The size of the allocated memory area should be equal to the size specified
  * at queue creation.
  *
- * \param[in] queue		- pointer to task instance
+ * \param[in] queue_ea		- 64-bit address of queue instance
  * \param[in] data		- address of data to be popped from queue
  * \return
  *	MARS_SUCCESS		- successfully received event
@@ -278,7 +278,7 @@ int mars_task_queue_try_pop(struct mars_
  * \n	MARS_ERROR_ALIGN	- instance not aligned properly
  * \n	MARS_ERROR_STATE	- invalid direction
  */
-int mars_task_queue_peek(struct mars_task_queue *queue, void *data);
+int mars_task_queue_peek(uint64_t queue_ea, void *data);
 
 /**
  * \ingroup group_mars_task_queue
@@ -296,7 +296,7 @@ int mars_task_queue_peek(struct mars_tas
  * - The size of the allocated memory area should be equal to the size specified
  * at queue creation.
  *
- * \param[in] queue		- pointer to task instance
+ * \param[in] queue_ea		- 64-bit address of queue instance
  * \param[in] data		- address of data to be popped from queue
  * \return
  *	MARS_SUCCESS		- successfully received event
@@ -305,7 +305,7 @@ int mars_task_queue_peek(struct mars_tas
  * \n	MARS_ERROR_BUSY		- queue is empty
  * \n	MARS_ERROR_STATE	- invalid direction
  */
-int mars_task_queue_try_peek(struct mars_task_queue *queue, void *data);
+int mars_task_queue_try_peek(uint64_t queue_ea, void *data);
 
 #if defined(__cplusplus)
 }
--- a/modules/task/include/host/mars/task_semaphore.h
+++ b/modules/task/include/host/mars/task_semaphore.h
@@ -69,7 +69,7 @@ extern "C" {
  * - Must not be greater than \ref MARS_TASK_SEMAPHORE_WAIT_MAX.
  *
  * \param[in] mars		- pointer to MARS context
- * \param[out] semaphore	- address of pointer to semaphore instance
+ * \param[out] semaphore_ea	- address of 64-bit address of semaphore instance
  * \param[in] count		- initial number of task accesses allowed
  * \return
  *	MARS_SUCCESS		- successfully created semaphore
@@ -77,7 +77,7 @@ extern "C" {
  * \n	MARS_ERROR_PARAMS	- count exceeds allowed limit
  */
 int mars_task_semaphore_create(struct mars_context *mars,
-				struct mars_task_semaphore **semaphore,
+				uint64_t *semaphore_ea,
 				int32_t count);
 
 /**
@@ -87,13 +87,13 @@ int mars_task_semaphore_create(struct ma
  * This function will free any resources allocated during creation of the task
  * semaphore.
  *
- * \param[in] semaphore		- pointer to semaphore instance
+ * \param[in] semaphore_ea	- 64-bit address of semaphore instance
  * \return
  *	MARS_SUCCESS		- successfully destroyed semaphore
  * \n	MARS_ERROR_NULL		- null pointer specified
  * \n	MARS_ERROR_ALIGN	- instance not properly aligned
  */
-int mars_task_semaphore_destroy(struct mars_task_semaphore *semaphore);
+int mars_task_semaphore_destroy(uint64_t semaphore_ea);
 
 #if defined(__cplusplus)
 }
--- a/modules/task/src/host/lib/task.c
+++ b/modules/task/src/host/lib/task.c
@@ -69,7 +69,7 @@ int mars_task_create(struct mars_context
 	Elf32_Phdr *phdr_module, *phdr_task;
 
 	uint16_t workload_id;
-	struct mars_workload_context *workload;
+	uint64_t workload_ea;
 	struct mars_task_context *task;
 
 	const struct mars_task_context_save_unit *p = context_save_unit;
@@ -101,12 +101,12 @@ int mars_task_create(struct mars_context
 		return MARS_ERROR_FORMAT;
 
 	/* begin process to add the task to the workload queue */
-	ret = mars_workload_queue_add_begin(mars, &workload_id, &workload);
+	ret = mars_workload_queue_add_begin(mars, &workload_id, &workload_ea);
 	if (ret != MARS_SUCCESS)
 		return ret;
 
 	/* cast workload context to task context */
-	task = (struct mars_task_context *)workload;
+	task = mars_ea_to_ptr(workload_ea);
 
 	/* initialize the module elf parameters */
 	task->module.exec_ea =
@@ -203,7 +203,7 @@ int mars_task_destroy(struct mars_task_i
 	int ret;
 	struct mars_context *mars;
 	struct mars_task_context *task;
-	struct mars_workload_context *workload;
+	uint64_t workload_ea;
 
 	/* check function params */
 	if (!id)
@@ -216,12 +216,12 @@ int mars_task_destroy(struct mars_task_i
 
 	/* begin process to remove the task from the workload queue */
 	ret = mars_workload_queue_remove_begin(mars, id->workload_id,
-		&workload);
+		&workload_ea);
 	if (ret != MARS_SUCCESS)
 		return ret;
 
 	/* cast workload context to task context */
-	task = (struct mars_task_context *)workload;
+	task = mars_ea_to_ptr(workload_ea);
 
 	/* free the allocated context save area if it has one */
 	if (task->context_save_area_ea)
@@ -245,7 +245,7 @@ int mars_task_schedule(struct mars_task_
 	int ret;
 	struct mars_context *mars;
 	struct mars_task_context *task;
-	struct mars_workload_context *workload;
+	uint64_t workload_ea;
 
 	/* check function params */
 	if (!id)
@@ -258,12 +258,12 @@ int mars_task_schedule(struct mars_task_
 
 	/* begin process to schedule the workload in the workload queue */
 	ret = mars_workload_queue_schedule_begin(mars, id->workload_id,
-		priority, &workload);
+		priority, &workload_ea);
 	if (ret != MARS_SUCCESS)
 		return ret;
 
 	/* cast workload context to task context */
-	task = (struct mars_task_context *)workload;
+	task = mars_ea_to_ptr(workload_ea);
 
 	/* initialize task specific context variables */
 	task->stack = 0;
@@ -283,7 +283,7 @@ int mars_task_wait(struct mars_task_id *
 	int ret;
 	struct mars_context *mars;
 	struct mars_task_context *task;
-	struct mars_workload_context *workload;
+	uint64_t workload_ea;
 
 	/* check function params */
 	if (!id)
@@ -295,12 +295,12 @@ int mars_task_wait(struct mars_task_id *
 	mars = mars_ea_to_ptr(id->mars_context_ea);
 
 	/* blocking wait for workload completion */
-	ret = mars_workload_queue_wait(mars, id->workload_id, &workload);
+	ret = mars_workload_queue_wait(mars, id->workload_id, &workload_ea);
 	if (ret != MARS_SUCCESS)
 		return ret;
 
 	/* cast workload context to task context */
-	task = (struct mars_task_context *)workload;
+	task = mars_ea_to_ptr(workload_ea);
 
 	/* exit_code requested so return it to caller */
 	if (exit_code)
@@ -314,7 +314,7 @@ int mars_task_try_wait(struct mars_task_
 	int ret;
 	struct mars_context *mars;
 	struct mars_task_context *task;
-	struct mars_workload_context *workload;
+	uint64_t workload_ea;
 
 	/* check function params */
 	if (!id)
@@ -326,12 +326,12 @@ int mars_task_try_wait(struct mars_task_
 	mars = mars_ea_to_ptr(id->mars_context_ea);
 
 	/* non-blocking wait for workload completion */
-	ret = mars_workload_queue_try_wait(mars, id->workload_id, &workload);
+	ret = mars_workload_queue_try_wait(mars, id->workload_id, &workload_ea);
 	if (ret != MARS_SUCCESS)
 		return ret;
 
 	/* cast workload context to task context */
-	task = (struct mars_task_context *)workload;
+	task = mars_ea_to_ptr(workload_ea);
 
 	/* exit_code requested so return it to caller */
 	if (exit_code)
--- a/modules/task/src/host/lib/task_barrier.c
+++ b/modules/task/src/host/lib/task_barrier.c
@@ -46,15 +46,16 @@
 #include "task_barrier_internal_types.h"
 
 int mars_task_barrier_create(struct mars_context *mars,
-				struct mars_task_barrier **barrier_ret,
+				uint64_t *barrier_ea_ret,
 				uint32_t total)
 {
 	struct mars_task_barrier *barrier;
+	uint64_t barrier_ea;
 
 	/* check function params */
 	if (!mars)
 		return MARS_ERROR_NULL;
-	if (!barrier_ret)
+	if (!barrier_ea_ret)
 		return MARS_ERROR_NULL;
 	if (!total || total > MARS_TASK_BARRIER_WAIT_MAX)
 		return MARS_ERROR_PARAMS;
@@ -65,7 +66,9 @@ int mars_task_barrier_create(struct mars
 	if (!barrier)
 		return MARS_ERROR_MEMORY;
 
-	mars_mutex_reset((struct mars_mutex *)barrier);
+	barrier_ea = mars_ptr_to_ea(barrier);
+
+	mars_mutex_reset(barrier_ea);
 
 	/* initialize barrier instance */
 	barrier->mars_context_ea = mars_ptr_to_ea(mars);
@@ -76,18 +79,18 @@ int mars_task_barrier_create(struct mars
 	barrier->wait_count = 0;
 
 	/* return barrier instance pointer */
-	*barrier_ret = barrier;
+	*barrier_ea_ret = barrier_ea;
 
 	return MARS_SUCCESS;
 }
 
-int mars_task_barrier_destroy(struct mars_task_barrier *barrier)
+int mars_task_barrier_destroy(uint64_t barrier_ea)
 {
 	/* check function params */
-	if (!barrier)
+	if (!barrier_ea)
 		return MARS_ERROR_NULL;
 
-	mars_ea_free(barrier);
+	mars_ea_free(mars_ea_to_ptr(barrier_ea));
 
 	return MARS_SUCCESS;
 }
--- a/modules/task/src/host/lib/task_event_flag.c
+++ b/modules/task/src/host/lib/task_event_flag.c
@@ -51,16 +51,17 @@
 #include "task_event_flag_internal_types.h"
 
 int mars_task_event_flag_create(struct mars_context *mars,
-				struct mars_task_event_flag **event_flag_ret,
+				uint64_t *event_flag_ea_ret,
 				uint8_t direction,
 				uint8_t clear_mode)
 {
 	struct mars_task_event_flag *event_flag;
+	uint64_t event_flag_ea;
 
 	/* check function params */
 	if (!mars)
 		return MARS_ERROR_NULL;
-	if (!event_flag_ret)
+	if (!event_flag_ea_ret)
 		return MARS_ERROR_NULL;
 	if (direction != MARS_TASK_EVENT_FLAG_HOST_TO_MPU &&
 		direction != MARS_TASK_EVENT_FLAG_MPU_TO_HOST &&
@@ -76,7 +77,9 @@ int mars_task_event_flag_create(struct m
 	if (!event_flag)
 		return MARS_ERROR_MEMORY;
 
-	mars_mutex_reset((struct mars_mutex *)event_flag);
+	event_flag_ea = mars_ptr_to_ea(event_flag);
+
+	mars_mutex_reset(event_flag_ea);
 
 	/* intialize event flag instance */
 	event_flag->mars_context_ea = mars_ptr_to_ea(mars);
@@ -86,44 +89,47 @@ int mars_task_event_flag_create(struct m
 	event_flag->wait_count = 0;
 
 	/* return event flag instance pointer */
-	*event_flag_ret = event_flag;
+	*event_flag_ea_ret = event_flag_ea;
 
 	return MARS_SUCCESS;
 }
 
-int mars_task_event_flag_destroy(struct mars_task_event_flag *event_flag)
+int mars_task_event_flag_destroy(uint64_t event_flag_ea)
 {
 	/* check function params */
-	if (!event_flag)
+	if (!event_flag_ea)
 		return MARS_ERROR_NULL;
 
-	mars_ea_free(event_flag);
+	mars_ea_free(mars_ea_to_ptr(event_flag_ea));
 
 	return MARS_SUCCESS;
 }
 
-int mars_task_event_flag_clear(struct mars_task_event_flag *event_flag,
-				uint32_t bits)
+int mars_task_event_flag_clear(uint64_t event_flag_ea, uint32_t bits)
 {
-	if (!event_flag)
+	struct mars_task_event_flag *event_flag =
+		mars_ea_to_ptr(event_flag_ea);
+
+	if (!event_flag_ea)
 		return MARS_ERROR_NULL;
 
-	mars_mutex_lock((struct mars_mutex *)event_flag);
+	mars_mutex_lock(event_flag_ea);
 
 	/* clear the necessary bits */
 	event_flag->bits &= ~bits;
 
-	mars_mutex_unlock((struct mars_mutex *)event_flag);
+	mars_mutex_unlock(event_flag_ea);
 
 	return MARS_SUCCESS;
 }
 
-int mars_task_event_flag_set(struct mars_task_event_flag *event_flag,
-				uint32_t bits)
+int mars_task_event_flag_set(uint64_t event_flag_ea, uint32_t bits)
 {
 	int ret;
 	int i;
 	struct mars_context *mars;
+	struct mars_task_event_flag *event_flag =
+		mars_ea_to_ptr(event_flag_ea);
 
 	/* check function params */
 	if (!event_flag)
@@ -133,7 +139,7 @@ int mars_task_event_flag_set(struct mars
 	if (event_flag->direction != MARS_TASK_EVENT_FLAG_HOST_TO_MPU)
 		return MARS_ERROR_STATE;
 
-	mars_mutex_lock((struct mars_mutex *)event_flag);
+	mars_mutex_lock(event_flag_ea);
 
 	/* get mars context pointer */
 	mars = mars_ea_to_ptr(event_flag->mars_context_ea);
@@ -179,14 +185,17 @@ int mars_task_event_flag_set(struct mars
 		i--;
 	}
 
-	mars_mutex_unlock((struct mars_mutex *)event_flag);
+	mars_mutex_unlock(event_flag_ea);
 
 	return MARS_SUCCESS;
 }
 
-static int wait(struct mars_task_event_flag *event_flag,
+static int wait(uint64_t event_flag_ea,
 		uint32_t mask, uint8_t mask_mode, uint32_t *bits, int try)
 {
+	struct mars_task_event_flag *event_flag =
+		mars_ea_to_ptr(event_flag_ea);
+
 	/* check function params */
 	if (!event_flag)
 		return MARS_ERROR_NULL;
@@ -196,13 +205,13 @@ static int wait(struct mars_task_event_f
 		mask_mode != MARS_TASK_EVENT_FLAG_MASK_AND)
 		return MARS_ERROR_PARAMS;
 
-	mars_mutex_lock((struct mars_mutex *)event_flag);
+	mars_mutex_lock(event_flag_ea);
 
 	/* check condition based on wait mode */
 	switch (mask_mode) {
 	case MARS_TASK_EVENT_FLAG_MASK_OR:
 		while ((event_flag->bits & mask) == 0) {
-			mars_mutex_unlock((struct mars_mutex *)event_flag);
+			mars_mutex_unlock(event_flag_ea);
 
 			/* only try so return busy */
 			if (try)
@@ -212,12 +221,12 @@ static int wait(struct mars_task_event_f
 			while ((event_flag->bits & mask) == 0)
 				sched_yield();
 
-			mars_mutex_lock((struct mars_mutex *)event_flag);
+			mars_mutex_lock(event_flag_ea);
 		}
 		break;
 	case MARS_TASK_EVENT_FLAG_MASK_AND:
 		while ((event_flag->bits & mask) != mask) {
-			mars_mutex_unlock((struct mars_mutex *)event_flag);
+			mars_mutex_unlock(event_flag_ea);
 
 			/* only try so return busy */
 			if (try)
@@ -227,7 +236,7 @@ static int wait(struct mars_task_event_f
 			while ((event_flag->bits & mask) != mask)
 				sched_yield();
 
-			mars_mutex_lock((struct mars_mutex *)event_flag);
+			mars_mutex_lock(event_flag_ea);
 		}
 		break;
 	}
@@ -240,21 +249,21 @@ static int wait(struct mars_task_event_f
 	if (event_flag->clear_mode == MARS_TASK_EVENT_FLAG_CLEAR_AUTO)
 		event_flag->bits &= ~mask;
 
-	mars_mutex_unlock((struct mars_mutex *)event_flag);
+	mars_mutex_unlock(event_flag_ea);
 
 	return MARS_SUCCESS;
 }
 
-int mars_task_event_flag_wait(struct mars_task_event_flag *event_flag,
+int mars_task_event_flag_wait(uint64_t event_flag_ea,
 				uint32_t mask, uint8_t mask_mode,
 				uint32_t *bits)
 {
-	return wait(event_flag, mask, mask_mode, bits, 0);
+	return wait(event_flag_ea, mask, mask_mode, bits, 0);
 }
 
-int mars_task_event_flag_try_wait(struct mars_task_event_flag *event_flag,
+int mars_task_event_flag_try_wait(uint64_t event_flag_ea,
 				uint32_t mask, uint8_t mask_mode,
 				uint32_t *bits)
 {
-	return wait(event_flag, mask, mask_mode, bits, 1);
+	return wait(event_flag_ea, mask, mask_mode, bits, 1);
 }
--- a/modules/task/src/host/lib/task_queue.c
+++ b/modules/task/src/host/lib/task_queue.c
@@ -51,18 +51,19 @@
 #include "task_queue_internal_types.h"
 
 int mars_task_queue_create(struct mars_context *mars,
-				struct mars_task_queue **queue_ret,
+				uint64_t *queue_ea_ret,
 				uint32_t size,
 				uint32_t depth,
 				uint8_t direction)
 {
 	struct mars_task_queue *queue;
+	uint64_t queue_ea;
 	void *buffer;
 
 	/* check function params */
 	if (!mars)
 		return MARS_ERROR_NULL;
-	if (!queue_ret)
+	if (!queue_ea_ret)
 		return MARS_ERROR_NULL;
 	if (size & MARS_TASK_QUEUE_ENTRY_SIZE_MASK)
 		return MARS_ERROR_PARAMS;
@@ -79,12 +80,14 @@ int mars_task_queue_create(struct mars_c
 	if (!queue)
 		return MARS_ERROR_MEMORY;
 
+	queue_ea = mars_ptr_to_ea(queue);
+
 	/* allocate queue buffer instance */
 	buffer = mars_ea_memalign(MARS_TASK_QUEUE_BUFFER_ALIGN, size * depth);
 	if (!buffer)
 		return MARS_ERROR_MEMORY;
 
-	mars_mutex_reset((struct mars_mutex *)queue);
+	mars_mutex_reset(queue_ea);
 
 	/* initialize queue instance */
 	queue->mars_context_ea = mars_ptr_to_ea(mars);
@@ -99,13 +102,16 @@ int mars_task_queue_create(struct mars_c
 	queue->pop_wait_count = 0;
 
 	/* return queue instance pointer */
-	*queue_ret = queue;
+	*queue_ea_ret = queue_ea;
 
 	return MARS_SUCCESS;
 }
 
-int mars_task_queue_destroy(struct mars_task_queue *queue)
+int mars_task_queue_destroy(uint64_t queue_ea)
 {
+	struct mars_task_queue *queue =
+		mars_ea_to_ptr(queue_ea);
+
 	/* check function params */
 	if (!queue)
 		return MARS_ERROR_NULL;
@@ -116,8 +122,11 @@ int mars_task_queue_destroy(struct mars_
 	return MARS_SUCCESS;
 }
 
-int mars_task_queue_count(struct mars_task_queue *queue, uint32_t *count)
+int mars_task_queue_count(uint64_t queue_ea, uint32_t *count)
 {
+	struct mars_task_queue *queue =
+		mars_ea_to_ptr(queue_ea);
+
 	/* check function params */
 	if (!queue)
 		return MARS_ERROR_NULL;
@@ -126,20 +135,22 @@ int mars_task_queue_count(struct mars_ta
 	if ((uintptr_t)queue & MARS_TASK_QUEUE_ALIGN_MASK)
 		return MARS_ERROR_ALIGN;
 
-	mars_mutex_lock((struct mars_mutex *)queue);
+	mars_mutex_lock(queue_ea);
 
 	/* return current items in queue */
 	*count = queue->count;
 
-	mars_mutex_unlock((struct mars_mutex *)queue);
+	mars_mutex_unlock(queue_ea);
 
 	return MARS_SUCCESS;
 }
 
-int mars_task_queue_clear(struct mars_task_queue *queue)
+int mars_task_queue_clear(uint64_t queue_ea)
 {
 	int i;
 	struct mars_context *mars;
+	struct mars_task_queue *queue =
+		mars_ea_to_ptr(queue_ea);
 
 	/* check function params */
 	if (!queue)
@@ -147,7 +158,7 @@ int mars_task_queue_clear(struct mars_ta
 	if ((uintptr_t)queue & MARS_TASK_QUEUE_ALIGN_MASK)
 		return MARS_ERROR_ALIGN;
 
-	mars_mutex_lock((struct mars_mutex *)queue);
+	mars_mutex_lock(queue_ea);
 
 	/* get mars context pointer */
 	mars = mars_ea_to_ptr(queue->mars_context_ea);
@@ -164,7 +175,7 @@ int mars_task_queue_clear(struct mars_ta
 	queue->push_ea = queue->buffer_ea;
 	queue->pop_ea = queue->buffer_ea;
 
-	mars_mutex_unlock((struct mars_mutex *)queue);
+	mars_mutex_unlock(queue_ea);
 
 	return MARS_SUCCESS;
 }
@@ -195,8 +206,11 @@ static void push_update(struct mars_task
 		queue->push_ea = queue->buffer_ea;
 }
 
-static int push(struct mars_task_queue *queue, const void *data, int try)
+static int push(uint64_t queue_ea, const void *data, int try)
 {
+	struct mars_task_queue *queue =
+		mars_ea_to_ptr(queue_ea);
+
 	/* check function params */
 	if (!queue)
 		return MARS_ERROR_NULL;
@@ -205,11 +219,11 @@ static int push(struct mars_task_queue *
 	if (queue->direction != MARS_TASK_QUEUE_HOST_TO_MPU)
 		return MARS_ERROR_STATE;
 
-	mars_mutex_lock((struct mars_mutex *)queue);
+	mars_mutex_lock(queue_ea);
 
 	/* queue is full so wait */
 	while (queue->count == queue->depth) {
-		mars_mutex_unlock((struct mars_mutex *)queue);
+		mars_mutex_unlock(queue_ea);
 
 		/* only try so return busy */
 		if (try)
@@ -218,7 +232,7 @@ static int push(struct mars_task_queue *
 		while (queue->count == queue->depth)
 			sched_yield();
 
-		mars_mutex_lock((struct mars_mutex *)queue);
+		mars_mutex_lock(queue_ea);
 	}
 
 	/* copy data into queue */
@@ -227,19 +241,19 @@ static int push(struct mars_task_queue *
 	/* update queue data */
 	push_update(queue);
 
-	mars_mutex_unlock((struct mars_mutex *)queue);
+	mars_mutex_unlock(queue_ea);
 
 	return MARS_SUCCESS;
 }
 
-int mars_task_queue_push(struct mars_task_queue *queue, const void *data)
+int mars_task_queue_push(uint64_t queue_ea, const void *data)
 {
-	return push(queue, data, 0);
+	return push(queue_ea, data, 0);
 }
 
-int mars_task_queue_try_push(struct mars_task_queue *queue, const void *data)
+int mars_task_queue_try_push(uint64_t queue_ea, const void *data)
 {
-	return push(queue, data, 1);
+	return push(queue_ea, data, 1);
 }
 
 static void pop_update(struct mars_task_queue *queue)
@@ -268,8 +282,11 @@ static void pop_update(struct mars_task_
 		queue->pop_ea = queue->buffer_ea;
 }
 
-static int pop(struct mars_task_queue *queue, void *data, int peek, int try)
+static int pop(uint64_t queue_ea, void *data, int peek, int try)
 {
+	struct mars_task_queue *queue =
+		mars_ea_to_ptr(queue_ea);
+
 	/* check function params */
 	if (!queue)
 		return MARS_ERROR_NULL;
@@ -278,11 +295,11 @@ static int pop(struct mars_task_queue *q
 	if (queue->direction != MARS_TASK_QUEUE_MPU_TO_HOST)
 		return MARS_ERROR_STATE;
 
-	mars_mutex_lock((struct mars_mutex *)queue);
+	mars_mutex_lock(queue_ea);
 
 	/* queue is empty so wait */
 	while (!queue->count) {
-		mars_mutex_unlock((struct mars_mutex *)queue);
+		mars_mutex_unlock(queue_ea);
 
 		/* only try so return busy */
 		if (try)
@@ -291,7 +308,7 @@ static int pop(struct mars_task_queue *q
 		while (!queue->count)
 			sched_yield();
 
-		mars_mutex_lock((struct mars_mutex *)queue);
+		mars_mutex_lock(queue_ea);
 	}
 
 	/* copy data from queue */
@@ -301,27 +318,27 @@ static int pop(struct mars_task_queue *q
 	if (!peek)
 		pop_update(queue);
 
-	mars_mutex_unlock((struct mars_mutex *)queue);
+	mars_mutex_unlock(queue_ea);
 
 	return MARS_SUCCESS;
 }
 
-int mars_task_queue_pop(struct mars_task_queue *queue, void *data)
+int mars_task_queue_pop(uint64_t queue_ea, void *data)
 {
-	return pop(queue, data, 0, 0);
+	return pop(queue_ea, data, 0, 0);
 }
 
-int mars_task_queue_try_pop(struct mars_task_queue *queue, void *data)
+int mars_task_queue_try_pop(uint64_t queue_ea, void *data)
 {
-	return pop(queue, data, 0, 1);
+	return pop(queue_ea, data, 0, 1);
 }
 
-int mars_task_queue_peek(struct mars_task_queue *queue, void *data)
+int mars_task_queue_peek(uint64_t queue_ea, void *data)
 {
-	return pop(queue, data, 1, 0);
+	return pop(queue_ea, data, 1, 0);
 }
 
-int mars_task_queue_try_peek(struct mars_task_queue *queue, void *data)
+int mars_task_queue_try_peek(uint64_t queue_ea, void *data)
 {
-	return pop(queue, data, 1, 1);
+	return pop(queue_ea, data, 1, 1);
 }
--- a/modules/task/src/host/lib/task_semaphore.c
+++ b/modules/task/src/host/lib/task_semaphore.c
@@ -48,15 +48,16 @@
 #include "task_semaphore_internal_types.h"
 
 int mars_task_semaphore_create(struct mars_context *mars,
-				struct mars_task_semaphore **semaphore_ret,
+				uint64_t *semaphore_ea_ret,
 				int32_t count)
 {
 	struct mars_task_semaphore *semaphore;
+	uint64_t semaphore_ea;
 
 	/* check function params */
 	if (!mars)
 		return MARS_ERROR_NULL;
-	if (!semaphore_ret)
+	if (!semaphore_ea_ret)
 		return MARS_ERROR_NULL;
 
 	/* allocate semaphore instance */
@@ -65,7 +66,9 @@ int mars_task_semaphore_create(struct ma
 	if (!semaphore)
 		return MARS_ERROR_MEMORY;
 
-	mars_mutex_reset((struct mars_mutex *)semaphore);
+	semaphore_ea = mars_ptr_to_ea(semaphore);
+
+	mars_mutex_reset(semaphore_ea);
 
 	/* initialize semaphore instance */
 	semaphore->mars_context_ea = mars_ptr_to_ea(mars);
@@ -73,18 +76,18 @@ int mars_task_semaphore_create(struct ma
 	semaphore->wait_count = 0;
 
 	/* return semaphore instance */
-	*semaphore_ret = semaphore;
+	*semaphore_ea_ret = semaphore_ea;
 
 	return MARS_SUCCESS;
 }
 
-int mars_task_semaphore_destroy(struct mars_task_semaphore *semaphore)
+int mars_task_semaphore_destroy(uint64_t semaphore_ea)
 {
 	/* check function params */
-	if (!semaphore)
+	if (!semaphore_ea)
 		return MARS_ERROR_NULL;
 
-	mars_ea_free(semaphore);
+	mars_ea_free(mars_ea_to_ptr(semaphore_ea));
 
 	return MARS_SUCCESS;
 }





More information about the cbe-oss-dev mailing list