[Cbe-oss-dev] [PATCH 04/10]MARS: Dynamic allocation api change

Yuji Mano yuji.mano at am.sony.com
Fri Oct 3 04:31:25 EST 2008


This changes all API so that objects instances are dynamically allocated
internally by the API calls. It replaces the *_initialize functions with
*_create and *_destroy functions.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>

---
 include/host/mars/mars_context.h         |    4 -
 include/host/mars/mars_mutex.h           |    6 ++
 include/host/mars/mars_task.h            |    4 -
 include/host/mars/mars_task_barrier.h    |    6 +-
 include/host/mars/mars_task_event_flag.h |    6 +-
 include/host/mars/mars_task_queue.h      |    7 +-
 include/host/mars/mars_task_semaphore.h  |   25 +++++++---
 include/host/mars/mars_workload_queue.h  |    4 -
 include/mpu/mars/mars_mutex.h            |   15 ------
 include/mpu/mars/mars_task_barrier.h     |   14 -----
 include/mpu/mars/mars_task_event_flag.h  |   17 ------
 include/mpu/mars/mars_task_queue.h       |   24 ---------
 include/mpu/mars/mars_task_semaphore.h   |   14 -----
 src/host/lib/mars_context.c              |   77 ++++++++++++++++---------------
 src/host/lib/mars_mutex.c                |   36 +++++++++++---
 src/host/lib/mars_task.c                 |   36 +++++++-------
 src/host/lib/mars_task_barrier.c         |   30 ++++++++----
 src/host/lib/mars_task_event_flag.c      |   37 ++++++++------
 src/host/lib/mars_task_queue.c           |   37 ++++++++++----
 src/host/lib/mars_task_semaphore.c       |   29 ++++++++---
 src/host/lib/mars_workload_queue.c       |   29 +++++++----
 src/mpu/lib/mars_mutex.c                 |   14 -----
 src/mpu/lib/mars_task_barrier.c          |   22 --------
 src/mpu/lib/mars_task_event_flag.c       |   29 -----------
 src/mpu/lib/mars_task_queue.c            |   39 ---------------
 src/mpu/lib/mars_task_semaphore.c        |   20 --------
 26 files changed, 237 insertions(+), 344 deletions(-)

--- a/include/host/mars/mars_context.h
+++ b/include/host/mars/mars_context.h
@@ -101,7 +101,7 @@ static inline uint64_t mars_ptr_to_ea(vo
  * \n	MARS_ERROR_MEMORY	- not enough memory
  * \n	MARS_ERROR_INTERNAL	- some internal error occurred
  */
-int mars_initialize(struct mars_context *ctx, uint32_t num_mpus);
+int mars_context_create(struct mars_context **mars, uint32_t num_mpus);
 
 /**
  * \ingroup group_mars_context
@@ -118,7 +118,7 @@ int mars_initialize(struct mars_context 
  * \n	MARS_ERROR_NULL		- null pointer specified
  * \n	MARS_ERROR_STATE	- workload queue is not empty
  */
-int mars_finalize(struct mars_context *ctx);
+int mars_context_destroy(struct mars_context *mars);
 
 #if defined(__cplusplus)
 }
--- a/include/host/mars/mars_mutex.h
+++ b/include/host/mars/mars_mutex.h
@@ -63,7 +63,11 @@ extern "C" {
  * \n	MARS_ERROR_NULL		- null pointer is specified
  * \n	MARS_ERROR_ALIGN	- instance not aligned properly
  */
-int mars_mutex_initialize(struct mars_mutex *mutex);
+int mars_mutex_create(struct mars_mutex **mutex);
+
+int mars_mutex_destroy(struct mars_mutex *mutex);
+
+int mars_mutex_reset(struct mars_mutex *mutex);
 
 /**
  * \ingroup group_mars_mutex
--- a/include/host/mars/mars_task.h
+++ b/include/host/mars/mars_task.h
@@ -98,7 +98,7 @@ extern "C" {
  * \n	MARS_ERROR_MEMORY	- not enough memory
  * \n	MARS_ERROR_LIMIT	- task queue is currently full
  */
-int mars_task_initialize(struct mars_context *mars,
+int mars_task_create(struct mars_context *mars,
 			struct mars_task_id *id,
 			const char *name,
 			const void *elf_image,
@@ -123,7 +123,7 @@ int mars_task_initialize(struct mars_con
  * \n	MARS_ERROR_PARAMS	- bad task id specified
  * \n	MARS_ERROR_STATE	- task is in an invalid state
  */
-int mars_task_finalize(struct mars_task_id *id);
+int mars_task_destroy(struct mars_task_id *id);
 
 /**
  * \ingroup group_mars_task
--- a/include/host/mars/mars_task_barrier.h
+++ b/include/host/mars/mars_task_barrier.h
@@ -65,10 +65,12 @@ extern "C" {
  * \n	MARS_ERROR_ALIGN	- instance not properly aligned
  * \n	MARS_ERROR_PARAMS	- total exceeds allowed limit
  */
-int mars_task_barrier_initialize(struct mars_context *mars,
-				struct mars_task_barrier *barrier,
+int mars_task_barrier_create(struct mars_context *mars,
+				struct mars_task_barrier **barrier,
 				uint32_t total);
 
+int mars_task_barrier_destroy(struct mars_task_barrier *barrier);
+
 #if defined(__cplusplus)
 }
 #endif
--- a/include/host/mars/mars_task_event_flag.h
+++ b/include/host/mars/mars_task_event_flag.h
@@ -66,11 +66,13 @@ extern "C" {
  * \n	MARS_ERROR_ALIGN	- instance not aligned properly
  * \n	MARS_ERROR_PARAMS	- invalid direction or clear mode specified
  */
-int mars_task_event_flag_initialize(struct mars_context *mars,
-				struct mars_task_event_flag *event_flag,
+int mars_task_event_flag_create(struct mars_context *mars,
+				struct mars_task_event_flag **event_flag,
 				uint8_t direction,
 				uint8_t clear_mode);
 
+int mars_task_event_flag_destroy(struct mars_task_event_flag *event_flag);
+
 /**
  * \ingroup group_mars_task_event_flag
  * \brief [host] Clears the bits specified in the task event flag.
--- a/include/host/mars/mars_task_queue.h
+++ b/include/host/mars/mars_task_queue.h
@@ -71,13 +71,14 @@ extern "C" {
  * \n	MARS_ERROR_PARAMS	- depth exceeds allowed limit
  * \n	MARS_ERROR_PARAMS	- invalid direction specified
  */
-int mars_task_queue_initialize(struct mars_context *mars,
-				struct mars_task_queue *queue,
-				void *buffer,
+int mars_task_queue_create(struct mars_context *mars,
+				struct mars_task_queue **queue,
 				uint32_t size,
 				uint32_t depth,
 				uint8_t direction);
 
+int mars_task_queue_destroy(struct mars_task_queue *queue);
+
 /**
  * \ingroup group_mars_task_queue
  * \brief [host] Returns the number of items in the task queue.
--- a/include/host/mars/mars_task_semaphore.h
+++ b/include/host/mars/mars_task_semaphore.h
@@ -54,21 +54,32 @@ extern "C" {
 
 /**
  * \ingroup group_mars_task_semaphore
- * \brief [host] Initializes a task semaphore.
+ * \brief [host] Creates a task semaphore.
  *
- * \param[in] mars		- pointer to initialized MARS context
- * \param[out] semaphore	- pointer to semaphore instance to initialize
+ * \param[in] mars		- pointer to MARS context
+ * \param[out] semaphore	- address of pointer to semaphore instance
  * \param[in] count		- initial number of task accesses allowed
  * \return
- *	MARS_SUCCESS		- successfully initialized semaphore
+ *	MARS_SUCCESS		- successfully created semaphore
  * \n	MARS_ERROR_NULL		- null pointer is specified
- * \n	MARS_ERROR_ALIGN	- instance not aligned properly
  * \n	MARS_ERROR_PARAMS	- count exceeds allowed limit
  */
-int mars_task_semaphore_initialize(struct mars_context *mars,
-				struct mars_task_semaphore *semaphore,
+int mars_task_semaphore_create(struct mars_context *mars,
+				struct mars_task_semaphore **semaphore,
 				int32_t count);
 
+/**
+ * \ingroup group_mars_task_semaphore
+ * \brief [host] Destroys a task semaphore.
+ *
+ * \param[in] semaphore		- pointer to 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);
+
 #if defined(__cplusplus)
 }
 #endif
--- a/include/host/mars/mars_workload_queue.h
+++ b/include/host/mars/mars_workload_queue.h
@@ -44,8 +44,8 @@
 extern "C" {
 #endif
 
-int workload_queue_initialize(struct mars_workload_queue *queue);
-int workload_queue_finalize(struct mars_workload_queue *queue);
+int workload_queue_create(struct mars_workload_queue **queue);
+int workload_queue_destroy(struct mars_workload_queue *queue);
 int workload_queue_exit(struct mars_workload_queue *queue);
 
 int workload_queue_add_begin(struct mars_workload_queue *queue, uint16_t *id,
--- a/include/mpu/mars/mars_mutex.h
+++ b/include/mpu/mars/mars_mutex.h
@@ -52,21 +52,6 @@ extern "C" {
 
 /**
  * \ingroup group_mars_mutex
- * \brief [MPU] Initializes a mutex.
- *
- * This function initializes a mutex instance that can be locked or unlocked
- * from both host and MPU to restrict concurrent accesses.
- *
- * \param[in] mutex_ea		-ea of mutex instance to initialize
- * \return
- *	MARS_SUCCESS		- successfully initialized mutex
- * \n	MARS_ERROR_NULL		- ea is 0
- * \n	MARS_ERROR_ALIGN	- ea not aligned properly
- */
-int mars_mutex_initialize(uint64_t mutex_ea);
-
-/**
- * \ingroup group_mars_mutex
  * \brief [MPU] Locks a mutex.
  *
  * This function locks a mutex and blocks other requests to lock it.
--- a/include/mpu/mars/mars_task_barrier.h
+++ b/include/mpu/mars/mars_task_barrier.h
@@ -52,20 +52,6 @@ extern "C" {
 
 /**
  * \ingroup group_mars_task_barrier
- * \brief [MPU] Initializes a task barrier.
- *
- * \param[out] barrier_ea	- ea of barrier instance to initialize
- * \param[in] total		- number of notifies before barrier released
- * \return
- *	MARS_SUCCESS		- successfully initialized barrier
- * \n	MARS_ERROR_NULL		- ea is 0
- * \n	MARS_ERROR_ALIGN	- ea not properly aligned
- * \n	MARS_ERROR_PARAMS	- total exceeds allowed limit
- */
-int mars_task_barrier_initialize(uint64_t barrier_ea, uint32_t total);
-
-/**
- * \ingroup group_mars_task_barrier
  * \brief [MPU] Notifies a task barrier. (Blocking)
  *
  * \param[in] barrier_ea	- ea of initialized barrier instance
--- a/include/mpu/mars/mars_task_event_flag.h
+++ b/include/mpu/mars/mars_task_event_flag.h
@@ -52,23 +52,6 @@ extern "C" {
 
 /**
  * \ingroup group_mars_task_event_flag
- * \brief [MPU] Initializes a task event flag.
- *
- * \param[out] event_flag_ea	- ea of event flag instance to initialize
- * \param[in] direction		- direction of the event flag
- * \param[in] clear_mode	- behavior of how the event flag is cleared
- * \return
- *	MARS_SUCCESS		- successfully initialized event flag
- * \n	MARS_ERROR_NULL		- ea is 0
- * \n	MARS_ERROR_ALIGN	- ea not aligned properly
- * \n	MARS_ERROR_PARAMS	- invalid direction or clear mode specified
- */
-int mars_task_event_flag_initialize(uint64_t event_flag_ea,
-				uint8_t direction,
-				uint8_t clear_mode);
-
-/**
- * \ingroup group_mars_task_event_flag
  * \brief [MPU] Clears the bits specified in the task event flag.
  *
  * \param[in] event_flag_ea	- ea of initialized event flag instance
--- a/include/mpu/mars/mars_task_queue.h
+++ b/include/mpu/mars/mars_task_queue.h
@@ -52,30 +52,6 @@ extern "C" {
 
 /**
  * \ingroup group_mars_task_queue
- * \brief [MPU] Initializes a task queue.
- *
- * \param[out] queue_ea		- ea of queue instance to initialize
- * \param[in] buffer_ea		- ea of data buffer
- * \param[in] size		- size of each data entry in data buffer
- * \param[in] depth		- maximum number of data entries in data buffer
- * \param[in] direction		- direction of the queue
- * \return
- *	MARS_SUCCESS		- successfully initialized queue
- * \n	MARS_ERROR_NULL		- ea is 0
- * \n	MARS_ERROR_ALIGN	- ea not aligned properly
- * \n	MARS_ERROR_PARAMS	- size is not multiple of 16 bytes or is greater
- *				  than 16KB maximum
- * \n	MARS_ERROR_PARAMS	- depth exceeds allowed limit
- * \n	MARS_ERROR_PARAMS	- invalid direction specified
- */
-int mars_task_queue_initialize(uint64_t queue_ea,
-				uint64_t buffer_ea,
-				uint32_t size,
-				uint32_t depth,
-				uint8_t direction);
-
-/**
- * \ingroup group_mars_task_queue
  * \brief [MPU] Returns the number of items in the task queue.
  *
  * \param[in] queue_ea		- ea of initialized queue instance
--- a/include/mpu/mars/mars_task_semaphore.h
+++ b/include/mpu/mars/mars_task_semaphore.h
@@ -52,20 +52,6 @@ extern "C" {
 
 /**
  * \ingroup group_mars_task_semaphore
- * \brief [MPU] Initializes a task semaphore.
- *
- * \param[out] semaphore_ea	- ea of semaphore instance to initialize
- * \param[in] count		- initial number of task accesses allowed
- * \return
- *	MARS_SUCCESS		- successfully initialized semaphore
- * \n	MARS_ERROR_NULL		- ea is 0
- * \n	MARS_ERROR_ALIGN	- ea not aligned properly
- * \n	MARS_ERROR_PARAMS	- count exceeds allowed limit
- */
-int mars_task_semaphore_initialize(uint64_t semaphore_ea, int32_t count);
-
-/**
- * \ingroup group_mars_task_semaphore
  * \brief [MPU] Acquires a task semaphore. (Blocking)
  *
  * \param[in] semaphore_ea	- ea of initialized semaphore instance
--- a/src/host/lib/mars_context.c
+++ b/src/host/lib/mars_context.c
@@ -72,16 +72,22 @@ static void *mpu_context_thread(void *ar
 	return (void *)MARS_SUCCESS;
 }
 
-static int create_mpu_contexts(struct mars_context *mars, uint32_t num_mpus)
+static int mpu_contexts_create(struct mars_context *mars, uint32_t num_mpus)
 {
 	MARS_ASSERT(mars);
 
 	int ret;
 	unsigned int i;
 
+	/* allocate mpu context thread array */
+	mars->mpu_context_threads = (pthread_t *)
+		malloc(sizeof(pthread_t) * num_mpus);
+	MARS_CHECK_RET(mars->mpu_context_threads, MARS_ERROR_MEMORY);
+
 	/* create threads for each mpu context */
 	for (i = 0; i < num_mpus; i++) {
 		struct mars_kernel_params *params = &mars->kernel_params[i];
+
 		params->id = i;
 		params->mars_context_ea =
 				mars_ptr_to_ea(mars);
@@ -98,7 +104,7 @@ static int create_mpu_contexts(struct ma
 	return MARS_SUCCESS;
 }
 
-static int destroy_mpu_contexts(struct mars_context *mars)
+static int mpu_contexts_destroy(struct mars_context *mars)
 {
 	MARS_ASSERT(mars);
 
@@ -116,17 +122,21 @@ static int destroy_mpu_contexts(struct m
 		MARS_CHECK_RET(!ret && !p_ret, MARS_ERROR_INTERNAL);
 	}
 
+	/* free mpu context thread array */
+	free(mars->mpu_context_threads);
+
 	return MARS_SUCCESS;
 }
 
-int mars_initialize(struct mars_context *mars, uint32_t num_mpus)
+int mars_context_create(struct mars_context **mars_ret, uint32_t num_mpus)
 {
-	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
+	MARS_CHECK_RET(mars_ret, MARS_ERROR_NULL);
 
-	MARS_PRINT("Initialize MARS Context (%p)\n", mars);
+	MARS_PRINT("Created MARS Context (%p)\n", mars);
 
 	int ret;
 	int num_mpus_max;
+	struct mars_context *mars;
 
 	/* check max available mpus */
 	num_mpus_max = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);
@@ -137,6 +147,10 @@ int mars_initialize(struct mars_context 
 	if (!num_mpus)
 		num_mpus = num_mpus_max;
 
+	/* allocate */
+	mars = malloc(sizeof(struct mars_context));
+	MARS_CHECK_RET(mars, MARS_ERROR_MEMORY);
+
 	/* zero context */
 	memset(mars, 0, sizeof(struct mars_context));
 
@@ -144,60 +158,51 @@ int mars_initialize(struct mars_context 
 	mars->kernel_params = (struct mars_kernel_params *)
 		memalign(MARS_KERNEL_PARAMS_ALIGN,
 			sizeof(struct mars_kernel_params) * num_mpus);
-	MARS_CHECK_CLEANUP_RET(mars->kernel_params, mars_finalize(mars),
+	MARS_CHECK_CLEANUP_RET(mars->kernel_params,
+				mars_context_destroy(mars),
 				MARS_ERROR_MEMORY);
 
-	/* allocate workload queue */
-	mars->workload_queue = (struct mars_workload_queue *)
-		memalign(MARS_WORKLOAD_QUEUE_ALIGN,
-			sizeof(struct mars_workload_queue));
-	MARS_CHECK_CLEANUP_RET(mars->workload_queue, mars_finalize(mars),
-				MARS_ERROR_MEMORY);
+	/* create workload queue */
+	ret = workload_queue_create(&mars->workload_queue);
+	MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS,
+				mars_context_destroy(mars),
+				ret);
+
+	/* create mpu contexts */
+	ret = mpu_contexts_create(mars, num_mpus);
+	MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS,
+				mars_context_destroy(mars),
+				ret);
 
-	/* allocate mpu context thread array */
-	mars->mpu_context_threads = (pthread_t *)
-		malloc(sizeof(pthread_t) * num_mpus);
-	MARS_CHECK_CLEANUP_RET(mars->mpu_context_threads, mars_finalize(mars),
-				MARS_ERROR_MEMORY);
-
-	/* initialize workload queue */
-	ret = workload_queue_initialize(mars->workload_queue);
-	MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret);
-
-	/* create contexts */
-	ret = create_mpu_contexts(mars, num_mpus);
-	MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret);
+	/* return mars context pointer */
+	*mars_ret = mars;
 
 	return MARS_SUCCESS;
 }
 
-int mars_finalize(struct mars_context *mars)
+int mars_context_destroy(struct mars_context *mars)
 {
 	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
 
 	int ret;
 
-	/* destroy contexts */
+	/* destroy mpu contexts */
 	if (mars->mpu_context_count) {
-		ret = destroy_mpu_contexts(mars);
+		ret = mpu_contexts_destroy(mars);
 		MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
 	}
 
-	/* finalize workload queue */
+	/* destroy workload queue */
 	if (mars->workload_queue) {
-		ret = workload_queue_finalize(mars->workload_queue);
+		ret = workload_queue_destroy(mars->workload_queue);
 		MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
 	}
 
 	/* free allocated memory */
-	free(mars->mpu_context_threads);
-	free(mars->workload_queue);
 	free(mars->kernel_params);
+	free(mars);
 
-	/* zero context */
-	memset(mars, 0, sizeof(struct mars_context));
-
-	MARS_PRINT("Finalize MARS Context (%p)\n", mars);
+	MARS_PRINT("Destroyed MARS Context (%p)\n", mars);
 
 	return MARS_SUCCESS;
 }
--- a/src/host/lib/mars_mutex.c
+++ b/src/host/lib/mars_mutex.c
@@ -35,17 +35,43 @@
  * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
  */
 
+#include <malloc.h>
 #include <ppu_intrinsics.h>
 
 #include "mars/mars_mutex.h"
 #include "mars/mars_error.h"
 #include "mars/mars_debug.h"
 
-int mars_mutex_initialize(struct mars_mutex *mutex)
+int mars_mutex_create(struct mars_mutex **mutex_ret)
+{
+	MARS_CHECK_RET(mutex_ret, MARS_ERROR_NULL);
+
+	struct mars_mutex *mutex;
+
+	mutex = (struct mars_mutex *)
+		memalign(MARS_MUTEX_ALIGN, sizeof(struct mars_mutex));
+	MARS_CHECK_RET(mutex, MARS_ERROR_MEMORY);
+
+	mutex->lock = MARS_MUTEX_UNLOCKED;
+	__lwsync();
+
+	*mutex_ret = mutex;
+
+	return MARS_SUCCESS;
+}
+
+int mars_mutex_destroy(struct mars_mutex *mutex)
+{
+	MARS_CHECK_RET(mutex, MARS_ERROR_NULL);
+
+	free(mutex);
+
+	return MARS_SUCCESS;
+}
+
+int mars_mutex_reset(struct mars_mutex *mutex)
 {
 	MARS_CHECK_RET(mutex, MARS_ERROR_NULL);
-	MARS_CHECK_RET(((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
 
 	mutex->lock = MARS_MUTEX_UNLOCKED;
 	__lwsync();
@@ -56,8 +82,6 @@ int mars_mutex_initialize(struct mars_mu
 int mars_mutex_lock(struct mars_mutex *mutex)
 {
 	MARS_CHECK_RET(mutex, MARS_ERROR_NULL);
-	MARS_CHECK_RET(((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
 
 	do {
 		do {
@@ -72,8 +96,6 @@ int mars_mutex_lock(struct mars_mutex *m
 int mars_mutex_unlock(struct mars_mutex *mutex)
 {
 	MARS_CHECK_RET(mutex, MARS_ERROR_NULL);
-	MARS_CHECK_RET(((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
 	MARS_CHECK_RET(mutex->lock == MARS_MUTEX_LOCKED, MARS_ERROR_STATE);
 
 	__lwsync();
--- a/src/host/lib/mars_task.c
+++ b/src/host/lib/mars_task.c
@@ -45,14 +45,14 @@
 #include "mars/mars_error.h"
 #include "mars/mars_debug.h"
 
-int mars_task_initialize(struct mars_context *mars,
-			struct mars_task_id *id,
+int mars_task_create(struct mars_context *mars,
+			struct mars_task_id *id_ret,
 			const char *name,
 			const void *elf_image,
 			uint32_t context_save_size)
 {
 	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
-	MARS_CHECK_RET(id, MARS_ERROR_NULL);
+	MARS_CHECK_RET(id_ret, MARS_ERROR_NULL);
 	MARS_CHECK_RET(elf_image, MARS_ERROR_NULL);
 	MARS_CHECK_RET(!name || strlen(name) < MARS_TASK_NAME_LEN_MAX,
 			MARS_ERROR_PARAMS);
@@ -60,6 +60,7 @@ int mars_task_initialize(struct mars_con
 			MARS_ERROR_PARAMS);
 
 	int ret;
+	uint16_t workload_id;
 	struct mars_task_context *task;
 	struct mars_workload_context *workload;
 	Elf32_Ehdr *ehdr = (Elf32_Ehdr *)elf_image;
@@ -70,23 +71,19 @@ int mars_task_initialize(struct mars_con
 	MARS_CHECK_RET(phdr->p_vaddr == MARS_TASK_ELF_VADDR,
 			MARS_ERROR_FORMAT);
 
-	/* initialize task context */
-	id->mars_context_ea = mars_ptr_to_ea(mars);
-
-	/* copy the task name into task id */
-	if (name)
-		strcpy((char *)&id->name, name);
-
 	/* begin process to add the task to the workload queue */
-	ret = workload_queue_add_begin(mars->workload_queue, &id->workload_id,
+	ret = workload_queue_add_begin(mars->workload_queue, &workload_id,
 				MARS_WORKLOAD_TYPE_TASK, &workload);
 	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
 
 	/* cast workload context to task context */
 	task = (struct mars_task_context *)workload;
 
-	/* initialize task specific id */
-	memcpy(&task->id, id, sizeof(struct mars_task_id));
+	/* initialize task id */
+	task->id.mars_context_ea = mars_ptr_to_ea(mars);
+	task->id.workload_id = workload_id;
+	if (name)
+		strcpy((char *)task->id.name, name);
 
 	/* initialize the elf parameters */
 	task->exec_ea = mars_ptr_to_ea((void *)ehdr + phdr->p_offset);
@@ -103,7 +100,7 @@ int mars_task_initialize(struct mars_con
 
 		MARS_CHECK_CLEANUP_RET(task->context_save_ea,
 			workload_queue_add_cancel(mars->workload_queue,
-				id->workload_id),
+				workload_id),
 			MARS_ERROR_MEMORY);
 	} else {
 		task->context_save_size = 0;
@@ -111,19 +108,22 @@ int mars_task_initialize(struct mars_con
 	}
 
 	/* end process to add the task to the workload queue */
-	ret = workload_queue_add_end(mars->workload_queue, id->workload_id);
+	ret = workload_queue_add_end(mars->workload_queue, workload_id);
 	MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS,
 			workload_queue_add_cancel(mars->workload_queue,
-				id->workload_id),
+				workload_id),
 			ret);
 
-	MARS_PRINT("Initialize Task Context %d\n", task->id.workload_id);
+	/* return id to caller */
+	*id_ret = task->id;
+
+	MARS_PRINT("Initialize Task Context %d\n", workload_id);
 	MARS_PRINT_TASK_CONTEXT(&task);
 
 	return MARS_SUCCESS;
 }
 
-int mars_task_finalize(struct mars_task_id *id)
+int mars_task_destroy(struct mars_task_id *id)
 {
 	MARS_CHECK_RET(id, MARS_ERROR_NULL);
 	MARS_CHECK_RET(id->mars_context_ea, MARS_ERROR_PARAMS);
--- a/src/host/lib/mars_task_barrier.c
+++ b/src/host/lib/mars_task_barrier.c
@@ -35,24 +35,29 @@
  * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
  */
 
+#include <malloc.h>
+
 #include "mars/mars_task_barrier.h"
 #include "mars/mars_context.h"
 #include "mars/mars_mutex.h"
 #include "mars/mars_error.h"
 #include "mars/mars_debug.h"
 
-int mars_task_barrier_initialize(struct mars_context *mars,
-				struct mars_task_barrier *barrier,
+int mars_task_barrier_create(struct mars_context *mars,
+				struct mars_task_barrier **barrier_ret,
 				uint32_t total)
 {
 	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
-	MARS_CHECK_RET(barrier, MARS_ERROR_NULL);
-	MARS_CHECK_RET(((uintptr_t)barrier & MARS_TASK_BARRIER_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
+	MARS_CHECK_RET(barrier_ret, MARS_ERROR_NULL);
 	MARS_CHECK_RET(total <= MARS_TASK_BARRIER_WAIT_MAX, MARS_ERROR_PARAMS);
 
-	mars_mutex_initialize((struct mars_mutex *)barrier);
-	mars_mutex_lock((struct mars_mutex *)barrier);
+	struct mars_task_barrier *barrier;
+
+	barrier = (struct mars_task_barrier *)
+		memalign(MARS_TASK_BARRIER_ALIGN, MARS_TASK_BARRIER_SIZE);
+	MARS_CHECK_RET(barrier, MARS_ERROR_MEMORY);
+
+	mars_mutex_reset((struct mars_mutex *)barrier);
 
 	barrier->mars_context_ea = mars_ptr_to_ea(mars);
 	barrier->total = total;
@@ -61,7 +66,16 @@ int mars_task_barrier_initialize(struct 
 	barrier->notify_wait_count = 0;
 	barrier->wait_count = 0;
 
-	mars_mutex_unlock((struct mars_mutex *)barrier);
+	*barrier_ret = barrier;
+
+	return MARS_SUCCESS;
+}
+
+int mars_task_barrier_destroy(struct mars_task_barrier *barrier)
+{
+	MARS_CHECK_RET(barrier, MARS_ERROR_NULL);
+
+	free(barrier);
 
 	return MARS_SUCCESS;
 }
--- a/src/host/lib/mars_task_event_flag.c
+++ b/src/host/lib/mars_task_event_flag.c
@@ -37,6 +37,7 @@
 
 #include <sched.h>
 #include <string.h>
+#include <malloc.h>
 
 #include "mars/mars_task_event_flag.h"
 #include "mars/mars_workload_queue.h"
@@ -45,15 +46,13 @@
 #include "mars/mars_error.h"
 #include "mars/mars_debug.h"
 
-int mars_task_event_flag_initialize(struct mars_context *mars,
-				struct mars_task_event_flag *event_flag,
+int mars_task_event_flag_create(struct mars_context *mars,
+				struct mars_task_event_flag **event_flag_ret,
 				uint8_t direction,
 				uint8_t clear_mode)
 {
 	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
-	MARS_CHECK_RET(event_flag, MARS_ERROR_NULL);
-	MARS_CHECK_RET(((uintptr_t)event_flag & MARS_TASK_EVENT_FLAG_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
+	MARS_CHECK_RET(event_flag_ret, MARS_ERROR_NULL);
 	MARS_CHECK_RET(direction == MARS_TASK_EVENT_FLAG_HOST_TO_MPU ||
 			direction == MARS_TASK_EVENT_FLAG_MPU_TO_HOST ||
 			direction == MARS_TASK_EVENT_FLAG_MPU_TO_MPU,
@@ -62,8 +61,13 @@ int mars_task_event_flag_initialize(stru
 			clear_mode == MARS_TASK_EVENT_FLAG_CLEAR_MANUAL,
 			MARS_ERROR_PARAMS);
 
-	mars_mutex_initialize((struct mars_mutex *)event_flag);
-	mars_mutex_lock((struct mars_mutex *)event_flag);
+	struct mars_task_event_flag *event_flag;
+
+	event_flag = (struct mars_task_event_flag *)
+		memalign(MARS_TASK_EVENT_FLAG_ALIGN, MARS_TASK_EVENT_FLAG_SIZE);
+	MARS_CHECK_RET(event_flag, MARS_ERROR_MEMORY);
+
+	mars_mutex_reset((struct mars_mutex *)event_flag);
 
 	event_flag->mars_context_ea = mars_ptr_to_ea(mars);
 	event_flag->bits = 0;
@@ -71,7 +75,16 @@ int mars_task_event_flag_initialize(stru
 	event_flag->clear_mode = clear_mode;
 	event_flag->wait_count = 0;
 
-	mars_mutex_unlock((struct mars_mutex *)event_flag);
+	*event_flag_ret = event_flag;
+
+	return MARS_SUCCESS;
+}
+
+int mars_task_event_flag_destroy(struct mars_task_event_flag *event_flag)
+{
+	MARS_CHECK_RET(event_flag, MARS_ERROR_NULL);
+
+	free(event_flag);
 
 	return MARS_SUCCESS;
 }
@@ -80,8 +93,6 @@ int mars_task_event_flag_clear(struct ma
 				uint32_t bits)
 {
 	MARS_CHECK_RET(event_flag, MARS_ERROR_NULL);
-	MARS_CHECK_RET(((uintptr_t)event_flag & MARS_TASK_EVENT_FLAG_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
 
 	mars_mutex_lock((struct mars_mutex *)event_flag);
 
@@ -100,8 +111,6 @@ int mars_task_event_flag_set(struct mars
 	MARS_CHECK_RET(event_flag->mars_context_ea, MARS_ERROR_NULL);
 	MARS_CHECK_RET(event_flag->direction ==
 			MARS_TASK_EVENT_FLAG_HOST_TO_MPU, MARS_ERROR_STATE);
-	MARS_CHECK_RET(((uintptr_t)event_flag & MARS_TASK_EVENT_FLAG_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
 
 	int ret;
 	int i;
@@ -164,8 +173,6 @@ int mars_task_event_flag_wait(struct mar
 	MARS_CHECK_RET(mask_mode == MARS_TASK_EVENT_FLAG_MASK_OR ||
 			mask_mode == MARS_TASK_EVENT_FLAG_MASK_AND,
 			MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(((uintptr_t)event_flag & MARS_TASK_EVENT_FLAG_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
 
 	mars_mutex_lock((struct mars_mutex *)event_flag);
 
@@ -212,8 +219,6 @@ int mars_task_event_flag_try_wait(struct
 	MARS_CHECK_RET(mask_mode == MARS_TASK_EVENT_FLAG_MASK_OR ||
 			mask_mode == MARS_TASK_EVENT_FLAG_MASK_AND,
 			MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(((uintptr_t)event_flag & MARS_TASK_EVENT_FLAG_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
 
 	mars_mutex_lock((struct mars_mutex *)event_flag);
 
--- a/src/host/lib/mars_task_queue.c
+++ b/src/host/lib/mars_task_queue.c
@@ -37,6 +37,7 @@
 
 #include <sched.h>
 #include <string.h>
+#include <malloc.h>
 
 #include "mars/mars_task_queue.h"
 #include "mars/mars_workload_queue.h"
@@ -45,20 +46,14 @@
 #include "mars/mars_error.h"
 #include "mars/mars_debug.h"
 
-int mars_task_queue_initialize(struct mars_context *mars,
-				struct mars_task_queue *queue,
-				void *buffer,
+int mars_task_queue_create(struct mars_context *mars,
+				struct mars_task_queue **queue_ret,
 				uint32_t size,
 				uint32_t depth,
 				uint8_t direction)
 {
 	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
-	MARS_CHECK_RET(buffer, MARS_ERROR_NULL);
-	MARS_CHECK_RET(((uintptr_t)queue & MARS_TASK_QUEUE_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(((uintptr_t)buffer & MARS_TASK_QUEUE_BUFFER_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
+	MARS_CHECK_RET(queue_ret, MARS_ERROR_NULL);
 	MARS_CHECK_RET((size & MARS_TASK_QUEUE_ENTRY_SIZE_MASK) == 0 &&
 			size <= MARS_TASK_QUEUE_ENTRY_SIZE_MAX,
 			MARS_ERROR_PARAMS);
@@ -67,8 +62,17 @@ int mars_task_queue_initialize(struct ma
 			direction == MARS_TASK_QUEUE_MPU_TO_MPU,
 			MARS_ERROR_PARAMS);
 
-	mars_mutex_initialize((struct mars_mutex *)queue);
-	mars_mutex_lock((struct mars_mutex *)queue);
+	struct mars_task_queue *queue;
+	void *buffer;
+
+	queue = (struct mars_task_queue *)
+		memalign(MARS_TASK_QUEUE_ALIGN, MARS_TASK_QUEUE_SIZE);
+	MARS_CHECK_RET(queue, MARS_ERROR_MEMORY);
+
+	buffer = memalign(MARS_TASK_QUEUE_BUFFER_ALIGN, size * depth);
+	MARS_CHECK_CLEANUP_RET(buffer, free(queue), MARS_ERROR_MEMORY);
+
+	mars_mutex_reset((struct mars_mutex *)queue);
 
 	queue->mars_context_ea = mars_ptr_to_ea(mars);
 	queue->buffer_ea = mars_ptr_to_ea(buffer);
@@ -81,7 +85,16 @@ int mars_task_queue_initialize(struct ma
 	queue->push_wait_count = 0;
 	queue->pop_wait_count = 0;
 
-	mars_mutex_unlock((struct mars_mutex *)queue);
+	*queue_ret = queue;
+
+	return MARS_SUCCESS;
+}
+
+int mars_task_queue_destroy(struct mars_task_queue *queue)
+{
+	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
+
+	free(queue);
 
 	return MARS_SUCCESS;
 }
--- a/src/host/lib/mars_task_semaphore.c
+++ b/src/host/lib/mars_task_semaphore.c
@@ -36,6 +36,7 @@
  */
 
 #include <stdlib.h>
+#include <malloc.h>
 
 #include "mars/mars_task_semaphore.h"
 #include "mars/mars_context.h"
@@ -43,25 +44,37 @@
 #include "mars/mars_error.h"
 #include "mars/mars_debug.h"
 
-int mars_task_semaphore_initialize(struct mars_context *mars,
-				struct mars_task_semaphore *semaphore,
+int mars_task_semaphore_create(struct mars_context *mars,
+				struct mars_task_semaphore **semaphore_ret,
 				int32_t count)
 {
 	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
-	MARS_CHECK_RET(semaphore, MARS_ERROR_NULL);
-	MARS_CHECK_RET(((uintptr_t)semaphore & MARS_TASK_SEMAPHORE_ALIGN_MASK)
-			== 0, MARS_ERROR_ALIGN);
+	MARS_CHECK_RET(semaphore_ret, MARS_ERROR_NULL);
 	MARS_CHECK_RET(abs(count) < MARS_TASK_SEMAPHORE_WAIT_MAX,
 			MARS_ERROR_PARAMS);
 
-	mars_mutex_initialize((struct mars_mutex *)semaphore);
-	mars_mutex_lock((struct mars_mutex *)semaphore);
+	struct mars_task_semaphore *semaphore;
+
+	semaphore = (struct mars_task_semaphore *)
+		memalign(MARS_TASK_SEMAPHORE_ALIGN, MARS_TASK_SEMAPHORE_SIZE);
+	MARS_CHECK_RET(semaphore, MARS_ERROR_MEMORY);
+
+	mars_mutex_reset((struct mars_mutex *)semaphore);
 
 	semaphore->mars_context_ea = mars_ptr_to_ea(mars);
 	semaphore->count = count;
 	semaphore->wait_count = 0;
 
-	mars_mutex_unlock((struct mars_mutex *)semaphore);
+	*semaphore_ret = semaphore;
+
+	return MARS_SUCCESS;
+}
+
+int mars_task_semaphore_destroy(struct mars_task_semaphore *semaphore)
+{
+	MARS_CHECK_RET(semaphore, MARS_ERROR_NULL);
+
+	free(semaphore);
 
 	return MARS_SUCCESS;
 }
--- a/src/host/lib/mars_workload_queue.c
+++ b/src/host/lib/mars_workload_queue.c
@@ -38,6 +38,7 @@
 #include <sched.h>
 #include <unistd.h>
 #include <string.h>
+#include <malloc.h>
 
 #include "mars/mars_workload_queue.h"
 #include "mars/mars_kernel_types.h"
@@ -46,26 +47,31 @@
 #include "mars/mars_error.h"
 #include "mars/mars_debug.h"
 
-int workload_queue_initialize(struct mars_workload_queue *queue)
+int workload_queue_create(struct mars_workload_queue **queue_ret)
 {
-	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
+	MARS_CHECK_RET(queue_ret, MARS_ERROR_NULL);
 
 	int block;
 	int index;
 
+	struct mars_workload_queue *queue;
+
+	/* allocate */
+	queue = (struct mars_workload_queue *)memalign(
+		MARS_WORKLOAD_QUEUE_ALIGN, sizeof(struct mars_workload_queue));
+	MARS_CHECK_RET(queue, MARS_ERROR_MEMORY);
+
+	/* initialize workload queue header */
 	queue->header.flag = MARS_WORKLOAD_QUEUE_FLAG_NONE;
 	queue->header.queue_ea = mars_ptr_to_ea(queue);
 	queue->header.context_ea = mars_ptr_to_ea(&queue->context);
 
 	/* initialize workload queue blocks */
 	for (block = 0; block < MARS_WORKLOAD_NUM_BLOCKS; block++) {
-		struct mars_workload_queue_block *p = &queue->block[block];
-
-		mars_mutex_initialize((struct mars_mutex *)p);
-		mars_mutex_lock((struct mars_mutex *)p);
+		mars_mutex_reset((struct mars_mutex *)&queue->block[block]);
 
 		for (index = 0; index < MARS_WORKLOAD_PER_BLOCK; index++) {
-			uint64_t *bits = &p->bits[index];
+			uint64_t *bits = &queue->block[block].bits[index];
 
 			MARS_BITS_SET(bits, TYPE,
 				MARS_WORKLOAD_TYPE_NONE);
@@ -80,14 +86,14 @@ int workload_queue_initialize(struct mar
 			MARS_BITS_SET(bits, WAIT_ID,
 				MARS_WORKLOAD_ID_NONE);
 		}
-
-		mars_mutex_unlock((struct mars_mutex *)p);
 	}
 
+	*queue_ret = queue;
+
 	return MARS_SUCCESS;
 }
 
-int workload_queue_finalize(struct mars_workload_queue *queue)
+int workload_queue_destroy(struct mars_workload_queue *queue)
 {
 	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
 
@@ -111,6 +117,9 @@ int workload_queue_finalize(struct mars_
 	/* found some task left in workload queue */
 	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_STATE);
 
+	/* free allocated memory */
+	free(queue);
+
 	return MARS_SUCCESS;
 }
 
--- a/src/mpu/lib/mars_mutex.c
+++ b/src/mpu/lib/mars_mutex.c
@@ -44,20 +44,6 @@
 
 static struct mars_mutex mutex;
 
-int mars_mutex_initialize(uint64_t mutex_ea)
-{
-	MARS_CHECK_RET(mutex_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((mutex_ea & MARS_MUTEX_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-
-	mutex.lock = MARS_MUTEX_UNLOCKED;
-
-	mars_dma_put_and_wait(&mutex, mutex_ea, sizeof(struct mars_mutex),
-		MARS_DMA_TAG);
-
-	return MARS_SUCCESS;
-}
-
 int mars_mutex_lock(uint64_t mutex_ea)
 {
 	return mars_mutex_lock_get(mutex_ea, &mutex);
--- a/src/mpu/lib/mars_task_barrier.c
+++ b/src/mpu/lib/mars_task_barrier.c
@@ -44,28 +44,6 @@
 
 static struct mars_task_barrier barrier;
 
-int mars_task_barrier_initialize(uint64_t barrier_ea, uint32_t total)
-{
-	MARS_CHECK_RET(barrier_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((barrier_ea & MARS_TASK_BARRIER_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(total <= MARS_TASK_BARRIER_WAIT_MAX, MARS_ERROR_PARAMS);
-
-	mars_mutex_initialize(barrier_ea);
-	mars_mutex_lock_get(barrier_ea, (struct mars_mutex *)&barrier);
-
-	barrier.mars_context_ea = mars_get_mars_context_ea();
-	barrier.total = total;
-	barrier.notified_count = 0;
-	barrier.waited_count = 0;
-	barrier.notify_wait_count = 0;
-	barrier.wait_count = 0;
-
-	mars_mutex_unlock_put(barrier_ea, (struct mars_mutex *)&barrier);
-
-	return MARS_SUCCESS;
-}
-
 int mars_task_barrier_notify(uint64_t barrier_ea)
 {
 	MARS_CHECK_RET(barrier_ea, MARS_ERROR_NULL);
--- a/src/mpu/lib/mars_task_event_flag.c
+++ b/src/mpu/lib/mars_task_event_flag.c
@@ -46,35 +46,6 @@
 
 static struct mars_task_event_flag event_flag;
 
-int mars_task_event_flag_initialize(uint64_t event_flag_ea,
-				uint8_t direction,
-				uint8_t clear_mode)
-{
-	MARS_CHECK_RET(event_flag_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((event_flag_ea & MARS_TASK_EVENT_FLAG_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(direction == MARS_TASK_EVENT_FLAG_HOST_TO_MPU ||
-			direction == MARS_TASK_EVENT_FLAG_MPU_TO_HOST ||
-			direction == MARS_TASK_EVENT_FLAG_MPU_TO_MPU,
-			MARS_ERROR_PARAMS);
-	MARS_CHECK_RET (clear_mode == MARS_TASK_EVENT_FLAG_CLEAR_AUTO ||
-			clear_mode == MARS_TASK_EVENT_FLAG_CLEAR_MANUAL,
-			MARS_ERROR_PARAMS);
-
-	mars_mutex_initialize(event_flag_ea);
-	mars_mutex_lock_get(event_flag_ea, (struct mars_mutex *)&event_flag);
-
-	event_flag.mars_context_ea = mars_get_mars_context_ea();
-	event_flag.bits = 0;
-	event_flag.direction = direction;
-	event_flag.clear_mode = clear_mode;
-	event_flag.wait_count = 0;
-
-	mars_mutex_unlock_put(event_flag_ea, (struct mars_mutex *)&event_flag);
-
-	return MARS_SUCCESS;
-}
-
 int mars_task_event_flag_clear(uint64_t event_flag_ea, uint32_t bits)
 {
 	MARS_CHECK_RET(event_flag_ea, MARS_ERROR_NULL);
--- a/src/mpu/lib/mars_task_queue.c
+++ b/src/mpu/lib/mars_task_queue.c
@@ -47,45 +47,6 @@
 
 static struct mars_task_queue queue;
 
-int mars_task_queue_initialize(uint64_t queue_ea,
-				uint64_t buffer_ea,
-				uint32_t size,
-				uint32_t depth,
-				uint8_t direction)
-{
-	MARS_CHECK_RET(queue_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET(buffer_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((queue_ea & MARS_TASK_QUEUE_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-	MARS_CHECK_RET((buffer_ea & MARS_TASK_QUEUE_BUFFER_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-	MARS_CHECK_RET((size & MARS_TASK_QUEUE_ENTRY_SIZE_MASK) == 0 &&
-			size <= MARS_TASK_QUEUE_ENTRY_SIZE_MAX,
-			MARS_ERROR_PARAMS);
-	MARS_CHECK_RET(direction == MARS_TASK_QUEUE_HOST_TO_MPU ||
-			direction == MARS_TASK_QUEUE_MPU_TO_HOST ||
-			direction == MARS_TASK_QUEUE_MPU_TO_MPU,
-			MARS_ERROR_PARAMS);
-
-	mars_mutex_initialize(queue_ea);
-	mars_mutex_lock_get(queue_ea, (struct mars_mutex *)&queue);
-
-	queue.mars_context_ea = mars_get_mars_context_ea();
-	queue.buffer_ea = buffer_ea;
-	queue.push_ea = queue.buffer_ea;
-	queue.pop_ea = queue.buffer_ea;
-	queue.size = size;
-	queue.depth = depth;
-	queue.direction = direction;
-	queue.count = 0;
-	queue.push_wait_count = 0;
-	queue.pop_wait_count = 0;
-
-	mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue);
-
-	return MARS_SUCCESS;
-}
-
 int mars_task_queue_count(uint64_t queue_ea, uint32_t *count)
 {
 	MARS_CHECK_RET(queue_ea, MARS_ERROR_NULL);
--- a/src/mpu/lib/mars_task_semaphore.c
+++ b/src/mpu/lib/mars_task_semaphore.c
@@ -47,26 +47,6 @@
 
 static struct mars_task_semaphore semaphore;
 
-int mars_task_semaphore_initialize(uint64_t semaphore_ea, int32_t count)
-{
-	MARS_CHECK_RET(semaphore_ea, MARS_ERROR_NULL);
-	MARS_CHECK_RET((semaphore_ea & MARS_TASK_SEMAPHORE_ALIGN_MASK) == 0,
-			MARS_ERROR_ALIGN);
-	MARS_CHECK_RET(abs(count) <= MARS_TASK_SEMAPHORE_WAIT_MAX,
-			MARS_ERROR_PARAMS);
-
-	mars_mutex_initialize(semaphore_ea);
-	mars_mutex_lock_get(semaphore_ea, (struct mars_mutex *)&semaphore);
-
-	semaphore.mars_context_ea = mars_get_mars_context_ea();
-	semaphore.count = count;
-	semaphore.wait_count = 0;
-
-	mars_mutex_unlock_put(semaphore_ea, (struct mars_mutex *)&semaphore);
-
-	return MARS_SUCCESS;
-}
-
 int mars_task_semaphore_acquire(uint64_t semaphore_ea)
 {
 	MARS_CHECK_RET(semaphore_ea, MARS_ERROR_NULL);






More information about the cbe-oss-dev mailing list