void EsifEventMgr_Exit(void) { UInt8 i; EsifLinkListPtr listPtr = NULL; ESIF_TRACE_ENTRY_INFO(); /* Remove all listeners */ esif_ccb_write_lock(&g_EsifEventMgr.listLock); for (i = 0; i < NUM_EVENT_LISTS; i++) { listPtr = g_EsifEventMgr.observerLists[i]; esif_link_list_free_data_and_destroy(listPtr, EsifEventMgr_LLEntryDestroyCallback); g_EsifEventMgr.observerLists[i] = NULL; } esif_ccb_write_unlock(&g_EsifEventMgr.listLock); /* Destroy the event thread */ /* Event thread should already be destroyed in the disable func. Destroy the queue */ esif_queue_destroy(g_EsifEventMgr.eventQueuePtr, EsifEventMgr_QueueDestroyCallback); g_EsifEventMgr.eventQueuePtr = NULL; /* Destroy the garbage list */ esif_ccb_write_lock(&g_EsifEventMgr.listLock); esif_link_list_free_data_and_destroy(g_EsifEventMgr.garbageList, EsifEventMgr_LLEntryDestroyCallback); g_EsifEventMgr.garbageList = NULL; esif_ccb_write_unlock(&g_EsifEventMgr.listLock); esif_ccb_lock_uninit(&g_EsifEventMgr.listLock); ESIF_TRACE_EXIT_INFO(); }
static eEsifError EsifEventMgr_DumpGarbage() { eEsifError rc = ESIF_OK; EsifLinkListPtr listPtr = g_EsifEventMgr.garbageList; EsifLinkListNodePtr nodePtr = NULL; EventMgrEntryPtr entryPtr = NULL; if (NULL == listPtr) { rc = ESIF_E_UNSPECIFIED; goto exit; } esif_ccb_write_lock(&g_EsifEventMgr.listLock); nodePtr = listPtr->head_ptr; while(nodePtr) { entryPtr = nodePtr->data_ptr; /* remove the node first so that it isn't considered active while we disable events */ esif_link_list_node_remove(listPtr, nodePtr); esif_ccb_write_unlock(&g_EsifEventMgr.listLock); EsifEventMgr_DisableEvent(entryPtr); esif_ccb_free(entryPtr); esif_ccb_write_lock(&g_EsifEventMgr.listLock); nodePtr = listPtr->head_ptr; } esif_ccb_write_unlock(&g_EsifEventMgr.listLock); exit: return rc; }
/* Unloads a pluggable UPE action by library name */ eEsifError EsifActMgr_StopUpe(EsifString upeName) { eEsifError rc = ESIF_OK; EsifActMgrEntryPtr entryPtr = NULL; struct esif_link_list_node *nodePtr = NULL; if (NULL == upeName) { rc = ESIF_E_PARAMETER_IS_NULL; goto exit; } esif_ccb_write_lock(&g_actMgr.mgrLock); entryPtr = EsifActMgr_GetActEntryByLibname_Locked(upeName); if (NULL == entryPtr) { esif_ccb_write_unlock(&g_actMgr.mgrLock); rc = ESIF_E_ACTION_NOT_IMPLEMENTED; ESIF_TRACE_WARN("Failed To Find Action: %s\n", upeName); goto exit; } nodePtr = EsifActMgr_GetNodeFromEntry_Locked(entryPtr); esif_link_list_node_remove(g_actMgr.actions, nodePtr); g_actMgr.numActions--; esif_ccb_write_unlock(&g_actMgr.mgrLock); EsifActMgr_DestroyEntry(entryPtr); ESIF_TRACE_DEBUG("Stopped Action: %s\n", upeName); exit: return rc; }
// backwards compatibility eEsifError EsifConfigSet( EsifDataPtr nameSpace, EsifDataPtr path, esif_flags_t flags, EsifDataPtr value ) { eEsifError rc = ESIF_OK; // Get the NameSpace or create it if it does not exist DataVaultPtr DB = DataBank_GetNameSpace(g_DataBankMgr, (StringPtr)(nameSpace->buf_ptr)); if (!DB) { struct esif_ccb_file dv_file = {0}; DB = DataBank_OpenNameSpace(g_DataBankMgr, (StringPtr)nameSpace->buf_ptr); if (!DB) { return ESIF_E_NOT_FOUND; } esif_build_path(dv_file.filename, sizeof(dv_file.filename), ESIF_PATHTYPE_DV, DB->name, ESIFDV_FILEEXT); IOStream_SetFile(DB->stream, dv_file.filename, "rb"); rc = DataVault_ReadVault(DB); if (rc == ESIF_E_NOT_FOUND) { rc = ESIF_OK; } } if (rc == ESIF_OK) { esif_ccb_write_lock(&DB->lock); rc = DataVault_SetValue(DB, path, value, flags); esif_ccb_write_unlock(&DB->lock); } return rc; }
static enum esif_rc esif_ccb_tmrm_get_next_handle( esif_ccb_timer_handle_t *handle_ptr ) { enum esif_rc rc = ESIF_OK; struct esif_link_list_node *node_ptr = NULL; esif_ccb_timer_t timer = {0}; u32 try_count = 0; /* * Our use case is that we will have a small number of timers ever * active; however the handle counter may eventually roll over to a * counter that has been there the whole time. So, we make sure that * the handle doesn't overlap. We also protect against an infinite loop. */ esif_ccb_write_lock(&g_tmrm.mgr_lock); do { try_count++; timer.timer_handle = (esif_ccb_timer_handle_t)(size_t)++g_next_timer_handle; node_ptr = esif_ccb_tmrm_find_timer_node_wlock(timer.timer_handle); } while ((node_ptr != NULL) && (try_count < ESIF_CNT_HNDL_RETRIES_MAX)); esif_ccb_write_unlock(&g_tmrm.mgr_lock); if(node_ptr != NULL) { rc = ESIF_E_UNSPECIFIED; goto exit; } *handle_ptr = timer.timer_handle; exit: return rc; }
/* This should only be called when shutting down */ static eEsifError EsifUpManagerDestroyParticipants(void) { eEsifError rc = ESIF_OK; EsifUpManagerEntryPtr entry_ptr = NULL; UInt8 i = 0; esif_ccb_write_lock(&g_uppMgr.fLock); for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) { entry_ptr = &g_uppMgr.fEntries[i]; if (entry_ptr->fState > ESIF_PM_PARTICIPANT_REMOVED) { g_uppMgr.fEntryCount--; } entry_ptr->fState = ESIF_PM_PARTICIPANT_STATE_AVAILABLE; if (NULL != entry_ptr->fUpPtr) { esif_ccb_free(entry_ptr->fUpPtr); entry_ptr->fUpPtr = NULL; } } esif_ccb_write_unlock(&g_uppMgr.fLock); ESIF_TRACE_INFO("The participants are destroyed in ESIF UF participant manager\n"); return rc; }
void DataBank_CloseNameSpace ( DataBankPtr self, esif_string nameSpace ) { UInt32 ns; esif_ccb_write_lock(&self->lock); // Find Existing NameSpace for (ns = 0; ns < self->size; ns++) { if (esif_ccb_stricmp(nameSpace, self->elements[ns].name) == 0) { DataVault_dtor(&self->elements[ns]); // Move Array Items down one and wipe the final item for ( ; ns + 1 < self->size; ns++) esif_ccb_memcpy(&self->elements[ns], &self->elements[ns + 1], sizeof(self->elements[ns])); if (ns < ESIF_MAX_NAME_SPACES) { WIPEPTR(&self->elements[ns]); } self->size--; } } esif_ccb_write_unlock(&self->lock); }
int EsifLogFile_Open(EsifLogType type, const char *filename, int append) { int rc=0; char fullpath[MAX_PATH]={0}; char mode[3] = {(append ? 'a' : 'w'), 0, 0}; esif_ccb_write_lock(&g_EsifLogFile[type].lock); if (g_EsifLogFile[type].handle != NULL) esif_ccb_fclose(g_EsifLogFile[type].handle); EsifLogFile_GetFullPath(fullpath, sizeof(fullpath), filename); #ifdef ESIF_ATTR_OS_WINDOWS mode[1] = 'c'; g_EsifLogFile[type].handle = _fsopen(fullpath, mode, _SH_DENYWR); if (g_EsifLogFile[type].handle == NULL) rc = errno; #else rc = esif_ccb_fopen(&g_EsifLogFile[type].handle, fullpath, mode); #endif if (rc == 0) { esif_ccb_free(g_EsifLogFile[type].filename); g_EsifLogFile[type].filename = esif_ccb_strdup((char *)fullpath); } esif_ccb_write_unlock(&g_EsifLogFile[type].lock); return rc; }
static enum esif_rc esif_ccb_tmrm_get_first_timer( esif_ccb_timer_t *timer_ptr ) { enum esif_rc rc = ESIF_E_UNSPECIFIED; struct esif_link_list_node *node_ptr = NULL; struct esif_tmrm_item *tmrm_item_ptr = NULL; esif_ccb_write_lock(&g_tmrm.mgr_lock); if (NULL == g_tmrm.timer_list_ptr) goto exit; node_ptr = g_tmrm.timer_list_ptr->head_ptr; if (NULL == node_ptr) goto exit; tmrm_item_ptr = (struct esif_tmrm_item *)node_ptr->data_ptr; if (NULL == tmrm_item_ptr) /* Should never happen */ goto exit; timer_ptr->timer_handle = tmrm_item_ptr->timer_handle; rc = ESIF_OK; exit: esif_ccb_write_unlock(&g_tmrm.mgr_lock); return rc; }
void esif_memtrace_free(void *mem_ptr) { struct memalloc_s *mem = NULL; struct memalloc_s **last = NULL; esif_ccb_write_lock(&g_memtrace.lock); mem = g_memtrace.allocated; last = &g_memtrace.allocated; while (mem) { if (mem_ptr == mem->mem_ptr) { *last = mem->next; native_free(mem); goto exit; } last = &mem->next; mem = mem->next; } exit: esif_ccb_write_unlock(&g_memtrace.lock); if (mem_ptr) { native_free(mem_ptr); atomic_inc(&g_memtrace.frees); } }
DataVaultPtr DataBank_OpenNameSpace ( DataBankPtr self, esif_string nameSpace ) { DataVaultPtr DB = NULL; UInt32 ns; // Exit if NameSpace already exists // TODO: Change this to a linked list or array of pointers so each DataVaultPtr is static esif_ccb_read_lock(&self->lock); for (ns = 0; ns < self->size; ns++) { if (esif_ccb_stricmp(nameSpace, self->elements[ns].name) == 0) { DB = &self->elements[ns]; break; } } esif_ccb_read_unlock(&self->lock); if (DB != NULL || ns >= ESIF_MAX_NAME_SPACES) { return DB; } // Not Found. Create NameSpace esif_ccb_write_lock(&self->lock); DB = &self->elements[self->size++]; DataVault_ctor(DB); esif_ccb_strcpy(DB->name, nameSpace, ESIF_NAME_LEN); esif_ccb_strlwr(DB->name, sizeof(DB->name)); esif_ccb_write_unlock(&self->lock); return DB; }
void esif_ccb_tmrm_callback( esif_ccb_timer_handle_t cb_handle ) { struct esif_link_list_node *node_ptr = NULL; struct esif_tmrm_item *tmrm_item_ptr = NULL; struct esif_timer_obj *timer_obj_ptr = NULL; esif_ccb_write_lock(&g_tmrm.mgr_lock); node_ptr = esif_ccb_tmrm_find_timer_node_by_cb_wlock(cb_handle); if ((NULL == node_ptr) || (NULL == node_ptr->data_ptr)) { goto lock_exit; } tmrm_item_ptr = (struct esif_tmrm_item *)node_ptr->data_ptr; /* Clear the CB handle to lower probability of hitting same handle */ tmrm_item_ptr->timer_cb_handle = 0; tmrm_item_ptr->is_in_cb = ESIF_TRUE; esif_ccb_write_unlock(&g_tmrm.mgr_lock); /* Call the timer callback function */ timer_obj_ptr = tmrm_item_ptr->timer_obj_ptr; esif_ccb_timer_obj_call_cb(timer_obj_ptr); /* * Upon return, perform post processing * Note: The item and node pointers will still be valid as the node * will not be removed while in the callback function */ esif_ccb_write_lock(&g_tmrm.mgr_lock); tmrm_item_ptr->is_in_cb = ESIF_FALSE; if (tmrm_item_ptr->marked_for_delete) { esif_ccb_tmrm_destroy_timer_node_wlock(node_ptr); goto lock_exit; } esif_ccb_timer_obj_set_pending_timeout(timer_obj_ptr); lock_exit: esif_ccb_write_unlock(&g_tmrm.mgr_lock); return; }
int EsifConsole_WriteLogFile(const char *format, va_list args) { int rc=0; esif_ccb_write_lock(&g_EsifLogFile[ESIF_LOG_SHELL].lock); rc = esif_ccb_vfprintf(g_EsifLogFile[ESIF_LOG_SHELL].handle, format, args); esif_ccb_write_unlock(&g_EsifLogFile[ESIF_LOG_SHELL].lock); return rc; }
/* * Sets a timer timeout in ms * Notes: 0 is an invalid timeout * The code will cancel any current timeout if possible before setting the new * timeout. If in the callback, the timeout will not be set until the function * exits. */ enum esif_rc esif_ccb_timer_set_msec( esif_ccb_timer_t *timer_ptr, const esif_ccb_time_t timeout /* Timeout in msec */ ) { enum esif_rc rc = ESIF_E_UNSPECIFIED; struct esif_link_list_node *node_ptr = NULL; struct esif_tmrm_item *tmrm_item_ptr = NULL; struct esif_timer_obj *timer_obj_ptr = NULL; esif_ccb_timer_handle_t timer_cb_handle = {0}; if (NULL == timer_ptr) { rc = ESIF_E_PARAMETER_IS_NULL; goto exit; } if (0 == timeout) { rc = ESIF_E_REQUEST_DATA_OUT_OF_BOUNDS; goto exit; } /* Order issue check */ if (!g_tmrm.enabled) goto exit; esif_ccb_write_lock(&g_tmrm.mgr_lock); node_ptr = esif_ccb_tmrm_find_timer_node_wlock(timer_ptr->timer_handle); if ((NULL == node_ptr) || (NULL == node_ptr->data_ptr)) { rc = ESIF_E_INVALID_HANDLE; goto lock_exit; } tmrm_item_ptr = (struct esif_tmrm_item *)node_ptr->data_ptr; if (tmrm_item_ptr->marked_for_delete) { rc = ESIF_E_INVALID_HANDLE; goto lock_exit; } esif_ccb_tmrm_get_next_cb_handle_wlock(&timer_cb_handle); tmrm_item_ptr->timer_cb_handle = timer_cb_handle; timer_obj_ptr = tmrm_item_ptr->timer_obj_ptr; esif_ccb_timer_obj_save_pending_timeout(timer_obj_ptr, timeout, timer_cb_handle); if (!tmrm_item_ptr->is_in_cb) { rc = esif_ccb_timer_obj_set_pending_timeout(timer_obj_ptr); } else { rc = ESIF_OK; } lock_exit: esif_ccb_write_unlock(&g_tmrm.mgr_lock); exit: return rc; }
static void EsifEventMgr_LLEntryDestroyCallback( void *dataPtr ) { esif_ccb_write_unlock(&g_EsifEventMgr.listLock); EsifEventMgr_DisableEvent((EventMgrEntryPtr)dataPtr); esif_ccb_free(dataPtr); esif_ccb_write_lock(&g_EsifEventMgr.listLock); }
static void EsifActMgr_LLEntryDestroyCallback( void *dataPtr ) { esif_ccb_write_unlock(&g_actMgr.mgrLock); EsifActMgr_DestroyEntry((EsifActMgrEntryPtr)dataPtr); esif_ccb_write_lock(&g_actMgr.mgrLock); }
int EsifLogFile_Close(EsifLogType type) { int rc = EOF; esif_ccb_write_lock(&g_EsifLogFile[type].lock); if (g_EsifLogFile[type].handle != NULL) rc = esif_ccb_fclose(g_EsifLogFile[type].handle); g_EsifLogFile[type].handle = NULL; esif_ccb_write_unlock(&g_EsifLogFile[type].lock); return rc; }
int EsifLogFile_WriteArgs(EsifLogType type, const char *fmt, va_list args) { int rc = 0; esif_ccb_write_lock(&g_EsifLogFile[type].lock); if (g_EsifLogFile[type].handle != NULL) { rc = esif_ccb_vfprintf(g_EsifLogFile[type].handle, fmt, args); fflush(g_EsifLogFile[type].handle); } esif_ccb_write_unlock(&g_EsifLogFile[type].lock); return rc; }
static eEsifError EsifEventMgr_ReleaseEntry( 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; atomic_t refCount = -1; ESIF_ASSERT(eventCallback != NULL); ESIF_ASSERT(fpcEventPtr != 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; goto exit; } /* Find the matching entry */ 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 (nodePtr != NULL) { refCount = atomic_dec(&curEntryPtr->refCount); if (refCount <= 0) { EsifEventMgr_MoveEntryToGarbage(curEntryPtr); esif_link_list_node_remove(listPtr, nodePtr); } goto exit; } exit: esif_ccb_write_unlock(&g_EsifEventMgr.listLock); EsifEventMgr_DumpGarbage(); return rc; }
EsifActPtr EsifActMgr_GetAction( enum esif_action_type type, const UInt8 instance ) { eEsifError rc = ESIF_OK; EsifActPtr actPtr = NULL; EsifActMgrEntryPtr entryPtr = NULL; struct esif_link_list_node *nodePtr = NULL; esif_ccb_write_lock(&g_actMgr.mgrLock); /* First see if the action is available, else see if it can be loaded */ entryPtr = EsifActMgr_GetActionEntry_Locked(type); if (NULL == entryPtr) { esif_ccb_write_unlock(&g_actMgr.mgrLock); goto exit; } if (entryPtr->loadDelayed != ESIF_TRUE) { actPtr = entryPtr->actPtr; rc = EsifAct_GetRef(actPtr); if (rc != ESIF_OK) { actPtr = NULL; } esif_ccb_write_unlock(&g_actMgr.mgrLock); } else { nodePtr = EsifActMgr_GetNodeFromEntry_Locked(entryPtr); esif_link_list_node_remove(g_actMgr.actions, nodePtr); g_actMgr.numActions--; esif_ccb_write_unlock(&g_actMgr.mgrLock); EsifActMgr_DestroyEntry(entryPtr); EsifActMgr_LoadDelayLoadAction(type, instance); actPtr = EsifActMgr_GetAction(type, instance); } exit: return actPtr; }
/* * Takes an additional reference on an action object. (The function is * called for you by the Action Manager when one of the functions are * called which returns a pointer to an action.) After using the * action, EsifAct_PutRef must be called to release the reference. */ eEsifError EsifAct_GetRef(EsifActPtr self) { eEsifError rc = ESIF_OK; if (self == NULL) { rc = ESIF_E_PARAMETER_IS_NULL; goto exit; } esif_ccb_write_lock(&self->objLock); if (self->markedForDelete == ESIF_TRUE) { esif_ccb_write_unlock(&self->objLock); ESIF_TRACE_DEBUG("Action marked for delete\n"); rc = ESIF_E_UNSPECIFIED; goto exit; } self->refCount++; esif_ccb_write_unlock(&self->objLock); exit: return rc; }
eEsifError EsifActMgr_UnregisterAction( EsifActIfacePtr actIfacePtr ) { eEsifError rc = ESIF_OK; enum esif_action_type actType = 0; struct esif_link_list_node *nodePtr = NULL; EsifActMgrEntryPtr entryPtr = NULL; if (NULL == actIfacePtr) { rc = ESIF_E_PARAMETER_IS_NULL; goto exit; } rc = EsifActIface_GetType(actIfacePtr, &actType); if (rc != ESIF_OK) { goto exit; } esif_ccb_write_lock(&g_actMgr.mgrLock); entryPtr = EsifActMgr_GetActionEntry_Locked(actType); if (NULL == entryPtr) { esif_ccb_write_unlock(&g_actMgr.mgrLock); rc = ESIF_E_NOT_FOUND; goto exit; } nodePtr = EsifActMgr_GetNodeFromEntry_Locked(entryPtr); esif_link_list_node_remove(g_actMgr.actions, nodePtr); g_actMgr.numActions++; esif_ccb_write_unlock(&g_actMgr.mgrLock); EsifActMgr_DestroyEntry(entryPtr); exit: return rc; }
/* Every init should have a matching kill */ enum esif_rc esif_ccb_timer_init( esif_ccb_timer_t *timer_ptr, esif_ccb_timer_cb function_ptr, /* Callback when timer fires */ void *context_ptr /* Callback context if any */ ) { enum esif_rc rc = ESIF_OK; struct esif_tmrm_item *tmrm_item_ptr = NULL; if ((NULL == timer_ptr) || (NULL == function_ptr)) { rc = ESIF_E_PARAMETER_IS_NULL; goto exit; } rc = esif_ccb_tmrm_is_ready(); if (rc != ESIF_OK) goto exit; rc = esif_ccb_tmrm_create_tmrm_item(function_ptr, context_ptr, &tmrm_item_ptr); if (rc != ESIF_OK) goto exit; /* Place the handle into the timer being initialized*/ timer_ptr->timer_handle = tmrm_item_ptr->timer_handle; /* * We create the manager list dynamically so that we don't have to call * init/exit functions and can destroy the linked list */ esif_ccb_write_lock(&g_tmrm.mgr_lock); if (NULL == g_tmrm.timer_list_ptr) { g_tmrm.timer_list_ptr = esif_link_list_create(); if(NULL == g_tmrm.timer_list_ptr) { rc = ESIF_E_NO_MEMORY; goto lock_exit; } } rc = esif_link_list_add_at_back(g_tmrm.timer_list_ptr, tmrm_item_ptr); lock_exit: esif_ccb_write_unlock(&g_tmrm.mgr_lock); exit: if (rc != ESIF_OK) esif_ccb_tmrm_destroy_tmrm_item(tmrm_item_ptr); return rc; }
/* Unregister Upper Participant Instance */ eEsifError EsifUpManagerUnregisterParticipant( const eEsifParticipantOrigin origin, const void *participantHandle ) { eEsifError rc = ESIF_OK; EsifUpManagerEntryPtr entry_ptr = NULL; EsifUpPtr up_ptr = NULL; UInt8 instance; UNREFERENCED_PARAMETER(origin); /* Validate parameters */ if (NULL == participantHandle) { ESIF_TRACE_ERROR("The participant handle pointer is NULL\n"); ESIF_ASSERT(participantHandle != NULL); rc = ESIF_E_PARAMETER_IS_NULL; goto exit; } instance = *(UInt8 *)participantHandle; if (instance >= MAX_PARTICIPANT_ENTRY) { ESIF_TRACE_ERROR("Instance id %d is out of range\n", instance); rc = ESIF_E_PARAMETER_IS_OUT_OF_BOUNDS; goto exit; } esif_ccb_write_lock(&g_uppMgr.fLock); entry_ptr = &g_uppMgr.fEntries[instance]; if (NULL != entry_ptr) { up_ptr = entry_ptr->fUpPtr; if (NULL != up_ptr) { entry_ptr->fState = ESIF_PM_PARTICIPANT_REMOVED; g_uppMgr.fEntryCount--; } } esif_ccb_write_unlock(&g_uppMgr.fLock); if (NULL != up_ptr) { rc = EsifAppMgrDestroyParticipantInAllApps(up_ptr); } ESIF_TRACE_INFO("Unregister participant, instant id = %d\n", instance); exit: return rc; }
static enum esif_rc esif_ccb_timer_kill_w_event( esif_ccb_timer_t *timer_ptr, esif_ccb_event_t *event_ptr ) { enum esif_rc rc = ESIF_E_UNSPECIFIED; struct esif_tmrm_item *tmrm_item_ptr = NULL; struct esif_link_list_node *node_ptr = NULL; if (NULL == timer_ptr) { rc = ESIF_E_PARAMETER_IS_NULL; goto exit; } if (!g_tmrm.enabled) goto exit; esif_ccb_write_lock(&g_tmrm.mgr_lock); node_ptr = esif_ccb_tmrm_find_timer_node_wlock(timer_ptr->timer_handle); if ((NULL == node_ptr) || (NULL == node_ptr->data_ptr)) { rc = ESIF_E_INVALID_HANDLE; goto lock_exit; } tmrm_item_ptr = (struct esif_tmrm_item *)node_ptr->data_ptr; /* Mark for delete in case it is in the callback */ tmrm_item_ptr->marked_for_delete = ESIF_TRUE; esif_ccb_tmrm_add_destroy_event(tmrm_item_ptr, event_ptr); /* If not in callback, the timer can be destroyed now */ if (!tmrm_item_ptr->is_in_cb) { esif_ccb_tmrm_destroy_timer_node_wlock(node_ptr); } rc = ESIF_OK; lock_exit: esif_ccb_write_unlock(&g_tmrm.mgr_lock); exit: if ((rc != ESIF_OK) && (event_ptr != NULL)) { esif_ccb_event_set(event_ptr); } return rc; }
void esif_memtrace_init() { struct memalloc_s *mem = NULL; esif_ccb_lock_init(&g_memtrace.lock); esif_ccb_write_lock(&g_memtrace.lock); mem = g_memtrace.allocated; // Ignore any allocations made before this function was called while (mem) { struct memalloc_s *node = mem; mem = mem->next; native_free(node); } g_memtrace.allocated = NULL; esif_ccb_write_unlock(&g_memtrace.lock); ESIF_TRACE_EXIT_INFO(); }
static eEsifError EsifActMgr_AddEntry( EsifActMgrEntryPtr entryPtr ) { eEsifError rc = ESIF_OK; ESIF_ASSERT(entryPtr != NULL); esif_ccb_write_lock(&g_actMgr.mgrLock); rc = esif_link_list_add_at_back(g_actMgr.actions, (void *)entryPtr); if (rc != ESIF_OK) { goto exit; } g_actMgr.numActions++; exit: esif_ccb_write_unlock(&g_actMgr.mgrLock); return rc; }
void esif_memtrace_exit() { struct memalloc_s *mem = NULL; char tracefile[MAX_PATH] = {0}; FILE *tracelog = NULL; esif_build_path(tracefile, sizeof(tracefile), ESIF_PATHTYPE_LOG, "memtrace.txt", NULL); esif_pathlist_exit(); esif_ccb_write_lock(&g_memtrace.lock); mem = g_memtrace.allocated; g_memtrace.allocated = NULL; esif_ccb_write_unlock(&g_memtrace.lock); CMD_OUT("MemTrace: Allocs=" ATOMIC_FMT " Frees=" ATOMIC_FMT "\n", atomic_read(&g_memtrace.allocs), atomic_read(&g_memtrace.frees)); if (!mem) { goto exit; } CMD_OUT("\n*** MEMORY LEAKS DETECTED ***\nFor details see %s\n", tracefile); esif_ccb_fopen(&tracelog, tracefile, "a"); if (tracelog) { time_t now = time(NULL); char timestamp[MAX_CTIME_LEN] = {0}; esif_ccb_ctime(timestamp, sizeof(timestamp), &now); fprintf(tracelog, "\n*** %.24s: MEMORY LEAKS DETECTED (%s) ***\n", timestamp, ESIF_UF_VERSION); } while (mem) { struct memalloc_s *node = mem; if (tracelog) { fprintf(tracelog, "[%s @%s:%d]: (%lld bytes) %p\n", mem->func, mem->file, mem->line, (long long)mem->size, mem->mem_ptr); } mem = mem->next; native_free(node->mem_ptr); native_free(node); } if (tracelog) { esif_ccb_fclose(tracelog); } exit: esif_ccb_lock_uninit(&g_memtrace.lock); }
int EsifConsole_WriteTo(u32 writeto, const char *format, ...) { int rc=0; if (writeto & CMD_WRITETO_CONSOLE) { va_list args; va_start(args, format); rc = EsifConsole_vprintf(format, args); va_end(args); } if ((writeto & CMD_WRITETO_LOGFILE) && (g_EsifLogFile[ESIF_LOG_SHELL].handle != NULL)) { va_list args; va_start(args, format); esif_ccb_write_lock(&g_EsifLogFile[ESIF_LOG_SHELL].lock); rc = esif_ccb_vfprintf(g_EsifLogFile[ESIF_LOG_SHELL].handle, format, args); esif_ccb_write_unlock(&g_EsifLogFile[ESIF_LOG_SHELL].lock); va_end(args); } return rc; }
/* * Releases a reference on an action object. This function should be * called when done using an action pointer obtained through any of the * Action Manager interfaces. */ void EsifAct_PutRef(EsifActPtr self) { UInt8 needRelease = ESIF_FALSE; if (self != NULL) { esif_ccb_write_lock(&self->objLock); self->refCount--; if ((self->refCount == 0) && (self->markedForDelete)) { needRelease = ESIF_TRUE; } esif_ccb_write_unlock(&self->objLock); if (needRelease == ESIF_TRUE) { ESIF_TRACE_DEBUG("Signal delete event\n"); esif_ccb_event_set(&self->deleteEvent); } } }