McuMessageHandler::~McuMessageHandler() { DestroyTimer(m_retryTimer); if(m_passengerRecord) { for(int i = 0; i < m_pos_num; i ++) { DestroyTimer(m_passengerRecord[i].posPassengerRecordTimer); } } delete []m_passengerRecord; ClearQueue(); ClearRxPacket(); pthread_mutex_lock(&m_dealRecordMutex); if(m_record_fd >= 0) { close(m_record_fd); m_record_fd = -1; } pthread_mutex_unlock(&m_dealRecordMutex); pthread_mutex_lock(&m_candataMutex); if(m_can_fd >= 0) { close(m_can_fd); m_can_fd = -1; } pthread_mutex_unlock(&m_candataMutex); pthread_mutex_destroy(&m_queueMutex); pthread_mutex_destroy(&m_packetMutex); pthread_mutex_destroy(&m_dealRecordMutex); pthread_mutex_destroy(&m_candataMutex); }
//------------------------------------------------------------------------- // // //------------------------------------------------------------------------- MouseTrailer::~MouseTrailer() { DestroyTimer(); }
static cell SetTimer_(AMX * amx, cell func, cell delay, cell interval, cell count, cell format, cell * params) { // Advanced version of SetTimer. Takes four main parameters so that we can // have offsets on timers (so they may start after 10ms, then run once every // 5ms say), and a COUNT for how many times to run the function! // First, find the given function. //logprintf("Adding"); if (delay >= -1 && interval >= 0 && count >= -1) { char * fname; STR_PARAM(amx, func, fname); int idx; if (amx_FindPublic(amx, fname, &idx)) { logprintf("fixes.plugin: Could not find function %s.", fname); } else { struct timer_s * timer; try { timer = new struct timer_s; } catch (...) { logprintf("fixes.plugin: Unable to allocate memory."); return 0; } timer->id = ++gCurrentTimer; timer->amx = amx; timer->func = idx; timer->interval = interval * 1000; // Need to somehow get the current time. There is a handy trick here // with negative numbers (i.e -1 being "almost straight away"). timer->trigger = MicrosecondTime() + delay * 1000; timer->params = 0; timer->repeat = count; gTimers.push(timer); // Add this timer to the map of timers. gHandles[gCurrentTimer] = timer; //logprintf("Added %d", timer->trigger); if (format) { char * fmat; STR_PARAM(amx, format, fmat); idx = 0; for ( ; ; ) { switch (*fmat++) { case '\0': { if (gCurrentTimer == 0xFFFFFFFF) { logprintf("fixes.plugin: 4294967295 timers created."); } return (cell)gCurrentTimer; } case 'i': case 'f': case 'x': case 'h': case 'b': case 'c': case 'l': case 'I': case 'F': case 'X': case 'H': case 'B': case 'C': case 'L': { struct params_s * p0 = (struct params_s *)malloc(sizeof (struct params_s)); if (p0) { cell * cstr; amx_GetAddr(amx, params[idx++], &cstr); p0->free = 0; p0->type = PARAM_TYPE_CELL; p0->numData = *cstr; //params[idx++]; // Construct the list backwards. Means we don't // need to worry about finding the latest one OR // the push order, so serves two purposes. p0->next = timer->params; timer->params = p0; } else { DestroyTimer(timer); logprintf("fixes.plugin: Unable to allocate memory."); return 0; } break; } case 's': case 'S': { cell * cstr; int len; amx_GetAddr(amx, params[idx++], &cstr); amx_StrLen(cstr, &len); struct params_s * p0 = (struct params_s *)malloc(sizeof (struct params_s) + len * sizeof (cell) + sizeof (cell)); if (p0) { p0->free = 0; p0->type = PARAM_TYPE_STRING; p0->numData = len + 1; memcpy(p0->arrayData, cstr, len * sizeof (cell) + sizeof (cell)); p0->next = timer->params; timer->params = p0; } else { DestroyTimer(timer); logprintf("fixes.plugin: Unable to allocate memory."); return 0; } break; } case 'a': case 'A': { switch (*fmat) { case 'i': case 'x': case 'h': case 'b': case 'I': case 'X': case 'H': case 'B': { cell * cstr; amx_GetAddr(amx, params[idx++], &cstr); int len = params[idx]; struct params_s * p0 = (struct params_s *)malloc(sizeof (struct params_s) + len * sizeof (cell)); if (p0) { p0->free = 0; p0->type = PARAM_TYPE_ARRAY; p0->numData = len; memcpy(p0->arrayData, cstr, len * sizeof (cell)); p0->next = timer->params; timer->params = p0; } else { DestroyTimer(timer); logprintf("fixes.plugin: Unable to allocate memory."); return 0; } break; } default: { logprintf("fixes.plugin: Array with no length."); } } break; } } } } else { if (gCurrentTimer == 0xFFFFFFFF) { logprintf("fixes.plugin: 4294967295 timers created."); } return (cell)gCurrentTimer; } } } else { logprintf("fixes.plugin: Invalid timer parameter."); } return 0; }
PLUGIN_EXPORT int PLUGIN_CALL ProcessTick() { long long unsigned int time = MicrosecondTime(); //logprintf("Process %d", time); while (!gTimers.empty()) { struct timer_s * next = gTimers.top(); if (next->trigger > time) { return 1; } else { gTimers.pop(); //logprintf("Triggered: %d %d", next->func, next->interval); if (next->repeat) { struct params_s * p0 = next->params; while (p0) { switch (p0->type) { case PARAM_TYPE_CELL: { amx_Push(next->amx, p0->numData); break; } case PARAM_TYPE_ARRAY: case PARAM_TYPE_STRING: { // These are actually done the same way because we // just store the AMX string representation, not the // C char* representation. Just remember the NULL! amx_PushArray(next->amx, &p0->free, 0, p0->arrayData, p0->numData); break; } } p0 = p0->next; } cell ret; amx_Exec(next->amx, &ret, next->func); // Free things. p0 = next->params; while (p0) { switch (p0->type) { case PARAM_TYPE_ARRAY: case PARAM_TYPE_STRING: { amx_Release(next->amx, p0->free); p0->free = 0; break; } } p0 = p0->next; } switch (next->repeat) { case 1: DestroyTimer(next); break; default: --next->repeat; case -1: // Don't rely on the current time or we'll get errors // compounded. next->trigger += next->interval; gTimers.push(next); break; } } else { // Used by "KillTimer". DestroyTimer(next); } } } return 1; }
void RemoveComponent_Timer(Timer* pTimerLocation) { DestroyTimer(pTimerLocation); }