 queue.
 * @param eventmanager is pointer to  event manager structure.
 * @return The RMF_OSAL error code on failure, otherwise RMF_SUCCESS
 *          is returned.
 */
static rmf_Error rmf_osal_eventqueue_dissociate_eventmanager (
		rmf_osal_eventqueue_handle_t eventqueue_handle,
		rmf_osal_eventmanager_t* eventmanager)
{
	rmf_Error ret = RMF_SUCCESS;
	int i;
	rmf_osal_eventqueue_t * eventqueue = (rmf_osal_eventqueue_t *)eventqueue_handle;
	RMF_OSAL_EVENT_VALIDATE_EVENT_PTR(eventqueue);
	RMF_OSAL_EVENT_LOCK(eventqueue);

	for (i = 0; i<MAX_EVENTMANAGER_PER_QUEUE; i++ )
	{
		if (eventqueue->eventmanager[i] == eventmanager )
		{
			eventqueue->eventmanager[i] = NULL;
			RDK_LOG( RDK_LOG_DEBUG, "LOG.RDK.EVENT",
						  "removing eventmanager 0x%x from eventqueue 0x%x\n", eventmanager, eventqueue_handle);
		}
	}

	RMF_OSAL_EVENT_UNLOCK(eventqueue);
	return ret;
}

/**
 * @brief This function is used used to add an event element to the queue.
 *
 * @param eventqueue is pointer to event queue structure.
 * @param event_el is pointer of element to be added to the queue.
 * @return The RMF_OSAL error code on failure, otherwise RMF_SUCCESS is returned.
 */
static rmf_Error rmf_osal_eventqueue_list_add_element(rmf_osal_eventqueue_t * eventqueue,
		rmf_osal_eventqueue_entry_t* event_el, int32_t timeout_usec)
{
	rmf_osal_eventqueue_entry_t* itr;
	rmf_osal_eventqueue_entry_t* event_el_prev;
	int ret;

	ret = rmf_osal_mutexAcquireTimed(eventqueue->mutex, timeout_usec);
	if( RMF_SUCCESS!= ret ) 
	{ 
		RDK_LOG(RDK_LOG_ERROR, "LOG.RDK.EVENT", 
									  "timed mutex take failed\n");
		return ret;
	}

	if( RMF_OSAL_EVENTQ_MAX_LIMIT == eventqueue->event_count )
	{
		RDK_LOG( RDK_LOG_ERROR, "LOG.RDK.EVENT",
			"Maximum limit for message queue [%s] reached\n", 
					eventqueue->name);
		RMF_OSAL_EVENT_UNLOCK(eventqueue);
		return RMF_OSAL_EBUSY;
	}
		
	event_el_prev = eventqueue->eventlist;
	if (NULL == event_el_prev)
	{
		event_el->next = NULL;
		eventqueue->eventlist = event_el;
	}
	else
	{
		if (event_el_prev->event->priority < event_el->event->priority)
		{
			event_el->next = event_el_prev;
			eventqueue->eventlist = event_el;
		}
		else
		{
			for (itr = event_el_prev ; itr ; itr = itr->next)
			{
				if (itr->event->priority < event_el->event->priority)
				{
					break;
				}
				event_el_prev = itr;
			}
			event_el->next = event_el_prev->next;
			event_el_prev->next = event_el;
		}
	}
	
	eventqueue->event_count++;
	ret = sem_post (&eventqueue->sem);
	if (ret)
	{
		RDK_LOG(RDK_LOG_ERROR, "LOG.RDK.EVENT",
						  "sem_post() failed\n");
	}
	RMF_OSAL_EVENT_UNLOCK(eventqueue);
	return RMF_SUCCESS;
}

/**
 * @brief This function is used to add an event to specified eventqueue.
 *
 * @param eventqueue_handle Handle of eventqueue.
 * @param event_handle Handle of event to be added to the queue.
 * @return Returns relevant RMF_OSAL error code on failure, otherwise RMF_SUCCESS is returned.
 */
rmf_Error rmf_osal_eventqueue_add(rmf_osal_eventqueue_handle_t eventqueue_handle,
		rmf_osal_event_handle_t event_handle)
{
	rmf_Error ret = RMF_SUCCESS;
	rmf_osal_eventqueue_entry_t* event_el;
	rmf_osal_Bool memory_managed = FALSE;
	rmf_osal_eventqueue_t * eventqueue = (rmf_osal_eventqueue_t *)eventqueue_handle;
	rmf_osal_event_t * event = (rmf_osal_event_t *)event_handle;
	RMF_OSAL_EVENT_VALIDATE_EVENT_PTR(eventqueue);
	RMF_OSAL_EVENT_VALIDATE_EVENT_PTR(event);

	RMF_OSAL_EVENT_LOCK(event);
	memory_managed = event->memory_managed;
	RMF_OSAL_EVENT_UNLOCK(event);

	if (TRUE == memory_managed )
	{
		/*Increment user count of the event*/
		RMF_OSAL_EVENT_LOCK(event);
		event->users++;
		RMF_OSAL_EVENT_UNLOCK(event);
	}

	ret = rmf_osal_memAllocP(RMF_OSAL_MEM_EVENT, sizeof(rmf_osal_eventqueue_entry_t), (void**)&event_el);
	if (RMF_SUCCESS!= ret)
	{
		RDK_LOG(RDK_LOG_ERROR, "LOG.RDK.EVENT",
							  "rmf_osal_memAllocP() failed\n");
		return ret;
	}
	event_el->event = event;
	ret = rmf_osal_eventqueue_list_add_element(eventqueue, event_el, -1);
	return ret;
}

/**
 * The <i>rmf_osal_eventqueue_addTimed()</i> function will add an event to specified eventqueue with in the time out.
 *
 * @param eventqueue_handle is handle of eventqueue.
 * @param event_handle is handle of event to be added to the queue.
 * @return The RMF_OSAL error code on failure, otherwise <i>RMF_SUCCESS<i/>
 *          is returned.
 */
rmf_Error rmf_osal_eventqueue_addTimed(rmf_osal_eventqueue_handle_t eventqueue_handle,
		rmf_osal_event_handle_t event_handle, int32_t timeout_usec)
{
	rmf_Error ret = RMF_SUCCESS;
	rmf_osal_eventqueue_entry_t* event_el;
	rmf_osal_Bool memory_managed = FALSE;
	rmf_osal_eventqueue_t * eventqueue = (rmf_osal_eventqueue_t *)eventqueue_handle;
	rmf_osal_event_t * event = (rmf_osal_event_t *)event_handle;
	RMF_OSAL_EVENT_VALIDATE_EVENT_PTR(eventqueue);
	RMF_OSAL_EVENT_VALIDATE_EVENT_PTR(event);

	RMF_OSAL_EVENT_LOCK(event);
	memory_managed = event->memory_managed;
	RMF_OSAL_EVENT_UNLOCK(event);

	if (TRUE == memory_managed )
	{
		/*Increment user count of the event*/
		RMF_OSAL_EVENT_LOCK(event);
		event->users++;
		RMF_OSAL_EVENT_UNLOCK(event);
	}

	ret = rmf_osal_memAllocP(RMF_OSAL_MEM_EVENT, sizeof(rmf_osal_eventqueue_entry_t), (void**)&event_el);
	if (RMF_SUCCESS!= ret)
	{
		RDK_LOG(RDK_LOG_ERROR, "LOG.RDK.EVENT",
							  "rmf_osal_memAllocP() failed\n");
		return ret;