DWORD WINAPI SB_PingTree_SendQueryThread(void *thread_arg) { proxy_request_queue *queue = (proxy_request_queue *) thread_arg; int i, ret; double interval_ms = (1.0 / sb_proxinfopersec.value) * 1000.0; timerresolution_session_t timersession = {0, 0}; Sys_TimerResolution_InitSession(&timersession); Sys_TimerResolution_RequestMinimum(&timersession); for (i = 0; i < queue->items; i++) { if (!queue->data[i].done) { struct sockaddr_storage addr_to; netadr_t netadr = SB_NodeNetadr_Get(queue->data[i].nodeid); NetadrToSockadr(&netadr, &addr_to); ret = sendto(queue->data[i].sock, PROXY_PINGLIST_QUERY, PROXY_PINGLIST_QUERY_LEN, 0, (struct sockaddr *) &addr_to, sizeof (struct sockaddr)); if (ret < 0) { Com_DPrintf("SB_PingTree_SendQueryThread sendto returned %d\n", ret); } Sys_MSleep(interval_ms); } if (queue->allrecved) break; } Sys_TimerResolution_Clear(&timersession); queue->sending_done = true; return 0; }
DWORD WINAPI AutoupdateProc(void * lpParameter) { double lastupdatetime = -1; while (autoupdate_serverinfo) { double time = Sys_DoubleTime(); if ((sb_liveupdate.integer > 0) && time >= lastupdatetime + sb_liveupdate.integer && key_dest == key_menu /* todo: add "on server list tab" condition here */) { server_data *serv; Sys_SemWait(&serverinfo_semaphore); serv = autoupdate_server; if (serv != NULL) { GetServerInfo(serv); lastupdatetime = time; } Sys_SemPost(&serverinfo_semaphore); } Sys_MSleep(1000); // we don't need nor allow updates faster than 1 second anyway } return 0; }
void MP3_Execute_f(void) { char path[MAX_OSPATH], *argv[2] = {"xmms", NULL}; int i, length; if (MP3_IsPlayerRunning()) { Com_Printf("XMMS is already running\n"); return; } Q_strncpyz(path, xmms_dir->string, sizeof(path) - strlen("/xmms")); length = strlen(path); for (i = 0; i < length; i++) { if (path[i] == '\\') path[i] = '/'; } if (length && path[length - 1] == '/') path[length - 1] = 0; strcat(path, "/xmms"); if (!(XMMS_pid = fork())) { execv(path, argv); exit(-1); } if (XMMS_pid == -1) { Com_Printf ("Couldn't execute XMMS\n"); return; } for (i = 0; i < 6; i++) { Sys_MSleep(50); if (MP3_IsPlayerRunning()) { Com_Printf("XMMS is now running\n"); return; } } Com_Printf("XMMS (probably) failed to run\n"); }
//static qbool XMMS2_started = false; void MP3_XMMS2_Execute_f(void) { char exec_name[MAX_OSPATH], *argv[2] = {"xmms2-launcher", NULL}/*, **s*/; int pid, i; if (MP3_XMMS2_IsPlayerRunning()) { Com_Printf("XMMS2 is already running\n"); return; } strlcpy(exec_name, argv[0], sizeof(exec_name)); if (!(pid = fork())) { // Child execvp(exec_name, argv); exit(-1); } if (pid == -1) { Com_Printf ("Couldn't execute xmms2-launcher\n"); return; } for (i = 0; i < 6; i++) { Sys_MSleep(50); XMMS2_Connect(); if (MP3_XMMS2_IsPlayerRunning()) { Com_Printf("XMMS2 is now running\n"); return; } } Com_Printf("XMMS2 (probably) failed to run\n"); }
static void SB_PingTree_ScanProxies(void) { int i; proxy_request_queue queue = { NULL, 0, false }; size_t request = 0; FILE *f = NULL; for (i = 0; i < ping_nodes_count; i++) { if (ping_nodes[i].proxport) { queue.items++; } } if (!queue.items) return; queue.data = (proxy_query_request_t *) Q_malloc(sizeof(proxy_query_request_t) * queue.items); for (i = 0; i < ping_nodes_count; i++) { if (ping_nodes[i].proxport) { queue.data[request].done = false; queue.data[request].nodeid = i; queue.data[request].sock = UDP_OpenSocket(NA_IPv4, PORT_ANY); request++; } } if (sb_listcache.value) { f = fopen(va("%s/%s", com_homedir, "proxies_data"), "wb"); if (f) SB_Proxylist_Serialize_Start(f); } for (i = 0; i < sb_proxretries.integer; i++) { queue.sending_done = false; Sys_CreateThread(SB_PingTree_SendQueryThread, (void *) &queue); SB_PingTree_RecvQuery(&queue, f); if (queue.allrecved) { break; } } if (f) { SB_Proxylist_Serialize_End(f); fclose(f); } while (!queue.sending_done) { // XXX: use semaphore instead Sys_MSleep(100); } for (i = 0; i < queue.items; i++) { closesocket(queue.data[i].sock); } Q_free(queue.data); }
// Returns true if it's not time yet to run a frame qbool VID_VSyncLagFix(void) { extern double vid_last_swap_time; double avg_rendertime, tmin, tmax; static int timings_idx; int i; if (!VID_VSyncIsOn() || !vid_vsync_lag_fix.integer) { return false; } if (!glConfig.displayFrequency) { Com_Printf("VID_VSyncLagFix: displayFrequency isn't set, can't enable vsync lag fix\n"); return false; } // collect statistics so that timings[timings_idx] = render_frame_end - render_frame_start; timings_idx = (timings_idx + 1) % NUMTIMINGS; avg_rendertime = tmin = tmax = 0; for (i = 0; i < NUMTIMINGS; i++) { if (timings[i] == 0) { return false; // not enough statistics yet } avg_rendertime += timings[i]; if (timings[i] < tmin || !tmin) { tmax = timings[i]; } if (timings[i] > tmax) { tmax = timings[i]; } } avg_rendertime /= NUMTIMINGS; // if (tmax and tmin differ too much) do_something(); ? avg_rendertime = tmax; // better be on the safe side double time_left = vid_last_swap_time + 1.0/glConfig.displayFrequency - Sys_DoubleTime(); time_left -= avg_rendertime; time_left -= vid_vsync_lag_tweak.value * 0.001; if (time_left > 0) { extern cvar_t sys_yieldcpu; if (time_left > 0.001 && sys_yieldcpu.integer) { Sys_MSleep(min(time_left * 1000, 500)); } return true; // don't run a frame yet } return false; }
void IN_SMouseShutdown(void) { double start = Sys_DoubleTime(); if (!use_m_smooth) return; use_m_smooth = false; // signaling to thread, time to die // // wait thread termination // while( smooth_thread ) { DWORD exitCode; if(!GetExitCodeThread(smooth_thread, &exitCode)) Sys_Error("IN_SMouseShutdown: GetExitCodeThread: failed"); if (exitCode != STILL_ACTIVE) { // ok, thread terminated // Terminating a thread does not necessarily remove the thread object from the operating system. // A thread object is deleted when the last handle to the thread is closed. CloseHandle(smooth_thread); smooth_thread = NULL; break; } if (Sys_DoubleTime() - start > 5) Sys_Error("IN_SMouseShutdown: thread does't respond"); Sys_MSleep(1); // sleep a bit, may be that help thread die fast } if (m_event) { CloseHandle(m_event); // close event m_event = NULL; } }