Пример #1
0
/* Insert Action Into List */
static eEsifError AddAction (
	EsifActMgrPtr THIS,
	EsifActTypePtr actionPtr
	)
{
	esif_link_list_node_add(THIS->fActTypes, esif_link_list_create_node(actionPtr));
	ESIF_TRACE_DEBUG("%s: item %p", ESIF_FUNC, actionPtr);
	return ESIF_OK;
}
Пример #2
0
static eEsifError EsifEventMgr_AddEntry(
	EsifFpcEventPtr fpcEventPtr,
	UInt8 participantId,
	UInt16 domainId,
	EVENT_OBSERVER_CALLBACK eventCallback,
	void *contextPtr
	)
{
	eEsifError rc = ESIF_OK;
	EsifLinkListPtr listPtr = NULL;
	EsifLinkListNodePtr nodePtr = NULL;
	EventMgrEntryPtr curEntryPtr = NULL;
	EventMgrEntryPtr newEntryPtr = NULL;
	atomic_t refCount = 1;

	ESIF_ASSERT(eventCallback != NULL);

	esif_ccb_write_lock(&g_EsifEventMgr.listLock);

	listPtr = g_EsifEventMgr.observerLists[fpcEventPtr->esif_event % NUM_EVENT_LISTS];
	if(NULL == listPtr) {
		rc = ESIF_E_UNSPECIFIED;
		esif_ccb_write_unlock(&g_EsifEventMgr.listLock);
		goto exit;
	}

	/* 
	 * First verify we don't already have the same entry.
	 * If we do, just increment the reference count.
	 */
	nodePtr = listPtr->head_ptr;
	while (nodePtr != NULL) {
		curEntryPtr = (EventMgrEntryPtr) nodePtr->data_ptr;
		if ((curEntryPtr->fpcEvent.esif_event == fpcEventPtr->esif_event) &&
			(curEntryPtr->participantId == participantId) &&
			(curEntryPtr->domainId == domainId) &&
			(curEntryPtr->contextPtr == contextPtr) &&
			(curEntryPtr->callback == eventCallback)){
			break;
		}
		nodePtr = nodePtr->next_ptr;
	}
	/* If we found an existing entry, update the reference count */
	if (nodePtr != NULL) {
		atomic_inc(&curEntryPtr->refCount);
		esif_ccb_write_unlock(&g_EsifEventMgr.listLock);
		goto exit;
	}
	esif_ccb_write_unlock(&g_EsifEventMgr.listLock);

	/*
	 * If an matching observer entry was not present; create a new observer entry,
	 * enable the events, and then place it into the list
	 */
	newEntryPtr = esif_ccb_malloc(sizeof(*newEntryPtr));
	if (NULL == newEntryPtr) {
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}

	newEntryPtr->callback = eventCallback;
	newEntryPtr->contextPtr = contextPtr;
	newEntryPtr->domainId = domainId;
	newEntryPtr->participantId = participantId;
	newEntryPtr->refCount = refCount;
	esif_ccb_memcpy(&newEntryPtr->fpcEvent, fpcEventPtr, sizeof(newEntryPtr->fpcEvent));

	nodePtr = esif_link_list_create_node(newEntryPtr);
	if (NULL == nodePtr) {
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}
	
	esif_ccb_write_lock(&g_EsifEventMgr.listLock);
	esif_link_list_add_node_at_back(listPtr, nodePtr);
	esif_ccb_write_unlock(&g_EsifEventMgr.listLock);

	rc = EsifEventMgr_EnableEvent(newEntryPtr);
	if (ESIF_OK != rc)
	{
		esif_ccb_write_lock(&g_EsifEventMgr.listLock);
		esif_link_list_node_remove(listPtr, nodePtr);
		esif_ccb_write_unlock(&g_EsifEventMgr.listLock);
		goto exit;
	}

exit:
	ESIF_TRACE_DEBUG("  RefCount: " ATOMIC_FMT "\n", refCount);

	if (ESIF_OK != rc) {
		esif_ccb_free(newEntryPtr);
	}

	return rc;
}