//--------------------------------------------------------------------------- int main(void) { Kernel_Init(); Thread_Init( &stMainThread, aucMainStack, MAIN_STACK_SIZE, 1, (ThreadEntry_t)AppMain, NULL ); Thread_Init( &stIdleThread, aucIdleStack, MAIN_STACK_SIZE, 0, (ThreadEntry_t)IdleMain, NULL ); Thread_Start( &stMainThread ); Thread_Start( &stIdleThread ); Driver_SetName( (Driver_t*) &stUART, "/dev/tty"); ATMegaUART_Init( &stUART ); DriverList_Add( (Driver_t*)&stUART ); Kernel_Start(); }
//--------------------------------------------------------------------------- int main(void) { // See the annotations in lab1. Kernel_Init(); // In this exercise, we create two threads at the same priority level. // As a result, the CPU will automatically swap between these threads // at runtime to ensure that each get a chance to execute. Thread_Init( &stApp1Thread, awApp1Stack, APP1_STACK_SIZE, 1, App1Main, 0); Thread_Init( &stApp2Thread, awApp2Stack, APP2_STACK_SIZE, 1, App2Main, 0); // Set the threads up so that Thread 1 can get 4ms of CPU time uninterrupted, // but Thread 2 can get 8ms of CPU time uninterrupted. This means that // in an ideal situation, Thread 2 will get to do twice as much work as // Thread 1 - even though they share the same scheduling priority. // Note that if SetQuantum() isn't called on a thread, a default value // is set such that each thread gets equal timeslicing in the same // priority group by default. You can play around with these values and // observe how it affects the execution of both threads. Thread_SetQuantum( &stApp1Thread, 4 ); Thread_SetQuantum( &stApp2Thread, 8 ); Thread_Start( &stApp1Thread ); Thread_Start( &stApp2Thread ); Kernel_Start(); return 0; }
/** * @brief */ static void Frame(const uint32_t msec) { Cbuf_Execute(); if (threads->modified) { threads->modified = false; Thread_Shutdown(); Thread_Init(threads->integer); } if (game->modified) { game->modified = false; Fs_SetGame(game->string); if (Fs_Exists("autoexec.cfg")) { Cbuf_AddText("exec autoexec.cfg\n"); Cbuf_Execute(); } } Sv_Frame(msec); Cl_Frame(msec); }
/* * @brief Setup fixture. */ void setup(void) { Mem_Init(); Thread_Init(2); memset(&cs, 0, sizeof(cs)); }
//--------------------------------------------------------------------------- int main(void) { // See the annotations in previous labs for details on init. Kernel_Init(); Thread_Init( &stApp1Thread, awApp1Stack, APP1_STACK_SIZE, 1, App1Main, 0); Thread_Init( &stApp2Thread, awApp2Stack, APP2_STACK_SIZE, 1, App2Main, 0); Thread_Start( &stApp1Thread ); Thread_Start( &stApp2Thread ); EventFlag_Init( &stFlags ); Kernel_Start(); return 0; }
//--------------------------------------------------------------------------- int main(void) { // See the annotations in previous labs for details on init. Kernel_Init(); Thread_Init( &stApp1Thread, awApp1Stack, APP1_STACK_SIZE, 1, App1Main, 0); Thread_Init( &stApp2Thread, awApp2Stack, APP2_STACK_SIZE, 1, App2Main, 0); Thread_Start( &stApp1Thread ); Thread_Start( &stApp2Thread ); // Initialize the mutex used in this example. Mutex_Init( &stMyMutex ); Kernel_Start(); return 0; }
IoObject *IoThread_threadCount(IoObject *self, IoObject *locals, IoMessage *m) { Thread_Init(); List *threads; size_t count; threads = Thread_Threads(); count = List_size(threads); List_free(threads); return IONUMBER(count); }
static int NsThread_Init (Tcl_Interp *interp, void *cd) { struct mydata *md = (struct mydata*)cd; int ret = Thread_Init(interp); if (ret != TCL_OK) { Ns_Log(Warning, "can't load module %s: %s", md->modname, Tcl_GetStringResult(interp)); return TCL_ERROR; } Tcl_SetAssocData(interp, "thread:nsd", NULL, (ClientData)md); return TCL_OK; }
/** **************************************************** * \fn void TPOS_Init(void) **************************************************** */ void TPOS_Init(void) { Thread *th; uint16_t i; Thread_Current()->next = NULL; EV_Init(&Thread_Current()->wakeEvent,TPos_ThreadWake,Thread_Current()); for(i = 1; i < THREAD_POOL_SIZE; i++) { th = Thread_Alloc(); Thread_Init(th,EV_Loop); th->next = unusedqHead; unusedqHead = th; EV_Init(&th->wakeEvent,TPos_ThreadWake,th); } Mutex_Init(&testRSema); }
/******************************************************************************* 函数名: main 功能说明: 主函数 参数: 无 返回值: 无 *******************************************************************************/ int main(void) { Thread_Init(); SysHard_Init(); //系统相关硬件初始化 WDG_Init(5,2000); FIFOInit(); //初始化队列缓冲区 Instruct_Init(); DeviceResetCheck_Init(); Test_Init(); Unit_Init(); while(1) { Process_FIFOData(&rcv433fifo, &rcv_433); //处理接收FIFO Process_FIFOData(&rcv433_shortfifo, &rcv_433short); //处理接收FIFO Thread_Process(); } }
/******************************************************************************* 函数名: main 功能说明: 主函数 参 数: 无 返回值: 无 *******************************************************************************/ int main(void) { Key_Init(); KeyLowPowerHandle(); Thread_Init(); SysHard_Init(); //系统相关硬件初始化 FIFOInit(); //初始化队列缓冲区 Instruct_Init(); DeviceResetCheck_Init(); Test_Init(); Unit_Init(); KeyTimer_Init(); while(1) { Process_FIFOData(&rcv433fifo, &rcv_433); //处理接收FIFO Thread_Process(); } }
IoThread *IoThread_proto(void *state) { IoThread *self = IoObject_new(state); IoObject_tag_(self, IoThread_newTag(state)); IoState_registerProtoWithFunc_(state, self, IoThread_proto); { IoMethodTable methodTable[] = { {"threadCount", IoThread_threadCount}, {"createThread", IoThread_createThread}, //{"endCurrentThread", IoThread_endCurrentThread}, {NULL, NULL}, }; IoObject_addMethodTable_(self, methodTable); } Thread_Init(); return self; }
IoObject *IoThread_createThread(IoObject *self, IoObject *locals, IoMessage *m) { IoSeq *s = IoMessage_locals_seqArgAt_(m, locals, 0); IoState *newState = IoState_new(); Thread *t; Thread_Init(); t = Thread_new(); IoThreadInfo *ti = IoThreadInfo_new(); IoThreadInfo_setState_(ti, newState); IoThreadInfo_setThread_(ti, t); IoThreadInfo_setEvalString_(ti, CSTRING(s)); Thread_setFunc_(t, IoThread_BeginThread); Thread_setFuncArg_(t, (void *)ti); Thread_start(t); return self; }
//--------------------------------------------------------------------------- static void Thread_Profiling() { K_USHORT i; for (i = 0; i < 100; i++) { // Profile the amount of time it takes to initialize a representative // test Thread_t, simulating an "average" system Thread_t. Create the // Thread_t at a higher priority than the current Thread_t. ProfileTimer_Start( &stThreadInitTimer ); Thread_Init( &stTestThread1, aucTestStack1, TEST_STACK1_SIZE, 2, (ThreadEntry_t)Thread_ProfilingThread, NULL); ProfileTimer_Stop( &stThreadInitTimer ); // Profile the time it takes from calling "start" to the time when the // Thread_t becomes active ProfileTimer_Start( &stThreadStartTimer ); Thread_Start( &stTestThread1 ); //-- Switch to the test Thread_t -- // Stop the Thread_t-exit profiling timer, which was started from the // test Thread_t ProfileTimer_Stop( &stThreadExitTimer ); } Scheduler_SetScheduler(0); for (i = 0; i < 100; i++) { // Context switch profiling - this is equivalent to what's actually // done within the AVR-implementation. ProfileTimer_Start( &stContextSwitchTimer ); { Thread_SaveContext(); g_pstNext = g_pstCurrent; Thread_RestoreContext(); } ProfileTimer_Stop( &stContextSwitchTimer ); } Scheduler_SetScheduler(1); }
int Libsqlite_Init( Tcl_Interp *interp) { #ifdef TCL_THREADS if (Thread_Init(interp) == TCL_ERROR) { return TCL_ERROR; } #endif Sqlite_Init(interp); #ifdef SQLITE_TEST { extern int Sqlitetest1_Init(Tcl_Interp*); extern int Sqlitetest2_Init(Tcl_Interp*); extern int Sqlitetest3_Init(Tcl_Interp*); extern int Md5_Init(Tcl_Interp*); Sqlitetest1_Init(interp); Sqlitetest2_Init(interp); Sqlitetest3_Init(interp); Md5_Init(interp); Tcl_StaticPackage(interp, "sqlite", Libsqlite_Init, Libsqlite_Init); } #endif return TCL_OK; }
//--------------------------------------------------------------------------- static void Semaphore_Profiling() { Semaphore_t stSem; K_USHORT i; for (i = 0; i < 100; i++) { ProfileTimer_Start( &stSemInitTimer ); Semaphore_Init( &stSem, 0, 1000); ProfileTimer_Stop( &stSemInitTimer ); } for (i = 0; i < 100; i++) { ProfileTimer_Start( &stSemPostTimer ); Semaphore_Post( &stSem ); ProfileTimer_Stop( &stSemPostTimer ); } for (i = 0; i < 100; i++) { ProfileTimer_Start( &stSemPendTimer ); Semaphore_Pend( &stSem ); ProfileTimer_Stop( &stSemPendTimer ); } Semaphore_Init( &stSem, 0, 1); for (i = 0; i < 100; i++) { Thread_Init( &stTestThread1, aucTestStack1, TEST_STACK1_SIZE, 2, (ThreadEntry_t)Semaphore_Flyback, (void*)&stSem); Thread_Start( &stTestThread1 ); Semaphore_Post( &stSem ); } return; }
/* ** This routine runs first. */ int main(int argc, char **argv){ Tcl_Interp *interp; char *args; char buf[100]; int tty; char TCLdir[20]; char TKdir[20]; char autopath[20]; char sourceCmd[80]; #ifdef WITHOUT_TK Tcl_Obj *resultPtr; Tcl_Obj *commandPtr = NULL; char buffer[1000]; int code, gotPartial, length; Tcl_Channel inChannel, outChannel, errChannel; #endif /* Create a Tcl interpreter */ Tcl_FindExecutable(argv[0]); interp = Tcl_CreateInterp(); if( Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 1)==0 ){ return 1; } args = Tcl_Merge(argc-1, (CONST84 char * CONST *)argv+1); Tcl_SetVar(interp, "argv", args, TCL_GLOBAL_ONLY); ckfree(args); sprintf(buf, "%d", argc-1); Tcl_SetVar(interp, "argc", buf, TCL_GLOBAL_ONLY); Tcl_SetVar(interp, "argv0", argv[0], TCL_GLOBAL_ONLY); tty = isatty(0); Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); /* We have to initialize the virtual filesystem before calling ** Tcl_Init(). Otherwise, Tcl_Init() will not be able to find ** its startup script files. */ Zvfs_Init(interp); Tcl_SetVar(interp, "extname", "", TCL_GLOBAL_ONLY); Zvfs_Mount(interp, (char *)Tcl_GetNameOfExecutable(), "/"); sprintf(TCLdir, "%s/tcl", mountPt); Tcl_SetVar2(interp, "env", "TCL_LIBRARY", TCLdir, TCL_GLOBAL_ONLY); sprintf(TKdir, "%s/tk", mountPt); Tcl_SetVar2(interp, "env", "TK_LIBRARY", TKdir, TCL_GLOBAL_ONLY); /* Initialize Tcl and Tk */ if( Tcl_Init(interp) ) return TCL_ERROR; sprintf(autopath, " %s", TCLdir); Tcl_SetVar(interp, "auto_path", autopath, TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); Tcl_SetVar(interp, "tcl_libPath", TCLdir, TCL_GLOBAL_ONLY); #ifdef WITHOUT_TK Tcl_SetVar(interp, "extname", "tclsh", TCL_GLOBAL_ONLY); #else Tk_InitConsoleChannels(interp); if ( Tk_Init(interp) ) { return TCL_ERROR; } Tcl_StaticPackage(interp,"Tk", Tk_Init, 0); Tk_CreateConsoleWindow(interp); #endif /* Start up all extensions. */ #if defined(__WIN32__) /* DRL - Do the standard Windows extentions */ if (Registry_Init(interp) == TCL_ERROR) { return TCL_ERROR; } Tcl_StaticPackage(interp, "Registry", Registry_Init, 0); if (Dde_Init(interp) == TCL_ERROR) { return TCL_ERROR; } Tcl_StaticPackage(interp, "Dde", Dde_Init, 0); #endif #ifndef WITHOUT_TDOM if (Tdom_Init(interp) == TCL_ERROR) { return TCL_ERROR; } Tcl_StaticPackage(interp, "Tdom", Tdom_Init, Tdom_SafeInit); #endif #ifndef WITHOUT_TLS if (Tls_Init(interp) == TCL_ERROR) { return TCL_ERROR; } Tcl_StaticPackage(interp, "Tls", Tls_Init, Tls_SafeInit); #endif /* #ifndef WITHOUT_MKZIPLIB if (Mkziplib_Init(interp) == TCL_ERROR) { return TCL_ERROR; } Tcl_StaticPackage(interp, "Mkziplib", Mkziplib_Init, Mkziplib_SafeInit); #endif */ #ifndef WITHOUT_XOTCL if (Xotcl_Init(interp) == TCL_ERROR) { return TCL_ERROR; } Tcl_StaticPackage(interp, "Xotcl", Xotcl_Init, Xotcl_SafeInit); /* if (Xotclexpat_Init(interp) == TCL_ERROR) { return TCL_ERROR; } Tcl_StaticPackage(interp, "xotclexpat", Xotclexpat_Init, 0); */ /* if (Xotclsdbm_Init(interp) == TCL_ERROR) { return TCL_ERROR; } */ // Tcl_StaticPackage(interp, "xotclsdbm", Xotclsdbm_Init, Xotclsdbm_SafeInit); /* if (Xotclgdbm_Init(interp) == TCL_ERROR) { return TCL_ERROR; } */ // Tcl_StaticPackage(interp, "xotclgdbm", Xotclgdbm_Init, Xotclgdbm_SafeInit); #endif #ifndef WITHOUT_TGDBM if (Tgdbm_Init(interp) == TCL_ERROR) { return TCL_ERROR; } Tcl_StaticPackage(interp, "Tgdbm", Tgdbm_Init, 0); #endif #ifndef WITHOUT_THREAD if (Thread_Init(interp) == TCL_ERROR) { return TCL_ERROR; } Tcl_StaticPackage(interp, "Thread", Thread_Init, 0); #endif #if !defined(WITHOUT_TK) && !defined(WITHOUT_WINICO) && (defined(__WIN32__) || defined(_WIN32)) if (Winico_Init(interp) == TCL_ERROR) return TCL_ERROR; Tcl_StaticPackage(interp, "Winico", Winico_Init, Winico_SafeInit); #endif /* Add some freeWrap commands */ if (Freewrap_Init(interp) == TCL_ERROR) return TCL_ERROR; /* After all extensions are registered, start up the ** program by running freewrapCmds.tcl. */ sprintf(sourceCmd, "source %s/freewrapCmds.tcl", mountPt); Tcl_Eval(interp, sourceCmd); #ifndef WITHOUT_TK /* * Loop infinitely, waiting for commands to execute. When there * are no windows left, Tk_MainLoop returns and we exit. */ Tk_MainLoop(); Tcl_DeleteInterp(interp); Tcl_Exit(0); #else /* * Process commands from stdin until there's an end-of-file. Note * that we need to fetch the standard channels again after every * eval, since they may have been changed. */ commandPtr = Tcl_NewObj(); Tcl_IncrRefCount(commandPtr); inChannel = Tcl_GetStdChannel(TCL_STDIN); outChannel = Tcl_GetStdChannel(TCL_STDOUT); gotPartial = 0; while (1) { if (tty) { Tcl_Obj *promptCmdPtr; promptCmdPtr = Tcl_GetVar2Ex(interp, (gotPartial ? "tcl_prompt2" : "tcl_prompt1"), NULL, TCL_GLOBAL_ONLY); if (promptCmdPtr == NULL) { defaultPrompt: if (!gotPartial && outChannel) { Tcl_WriteChars(outChannel, "% ", 2); } } else { code = Tcl_EvalObjEx(interp, promptCmdPtr, 0); inChannel = Tcl_GetStdChannel(TCL_STDIN); outChannel = Tcl_GetStdChannel(TCL_STDOUT); errChannel = Tcl_GetStdChannel(TCL_STDERR); if (code != TCL_OK) { if (errChannel) { Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp)); Tcl_WriteChars(errChannel, "\n", 1); } Tcl_AddErrorInfo(interp, "\n (script that generates prompt)"); goto defaultPrompt; } } if (outChannel) { Tcl_Flush(outChannel); } } if (!inChannel) { goto done; } length = Tcl_GetsObj(inChannel, commandPtr); if (length < 0) { goto done; } if ((length == 0) && Tcl_Eof(inChannel) && (!gotPartial)) { goto done; } /* * Add the newline removed by Tcl_GetsObj back to the string. */ Tcl_AppendToObj(commandPtr, "\n", 1); if (!TclObjCommandComplete(commandPtr)) { gotPartial = 1; continue; } gotPartial = 0; code = Tcl_RecordAndEvalObj(interp, commandPtr, 0); inChannel = Tcl_GetStdChannel(TCL_STDIN); outChannel = Tcl_GetStdChannel(TCL_STDOUT); errChannel = Tcl_GetStdChannel(TCL_STDERR); Tcl_DecrRefCount(commandPtr); commandPtr = Tcl_NewObj(); Tcl_IncrRefCount(commandPtr); if (code != TCL_OK) { if (errChannel) { Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp)); Tcl_WriteChars(errChannel, "\n", 1); } } else if (tty) { resultPtr = Tcl_GetObjResult(interp); Tcl_GetStringFromObj(resultPtr, &length); if ((length > 0) && outChannel) { Tcl_WriteObj(outChannel, resultPtr); Tcl_WriteChars(outChannel, "\n", 1); } } } /* * Rather than calling exit, invoke the "exit" command so that * users can replace "exit" with some other command to do additional * cleanup on exit. The Tcl_Eval call should never return. */ done: if (commandPtr != NULL) { Tcl_DecrRefCount(commandPtr); } sprintf(buffer, "exit %d", 0); Tcl_Eval(interp, buffer); #endif return TCL_OK; }
/*----------------------------------------------------------------------------------------------*/ int main(int argc, char* argv[]) { FILE* fp; int success; int state; int fin[2]; int fout[2]; pid_t pid; Parse_Arguments(argc, argv); success = Hardware_Init(); if(success == false) { Hardware_Shutdown(); fprintf(stderr,"Hardware_Init() failed, aborting.\n"); return(-1); } if(success) { success = Pipes_Init(); } else { Pipes_Shutdown(); Hardware_Shutdown(); fprintf(stderr,"Pipes_Init() failed, aborting.\n"); return(-1); } if(success) { success = Object_Init(); } else { Pipes_Shutdown(); Object_Shutdown(); Hardware_Shutdown(); fprintf(stderr,"Object_Init() failed, aborting.\n"); return(-1); } if(success) { success = Thread_Init(); } else { Thread_Shutdown(); Pipes_Shutdown(); Object_Shutdown(); Hardware_Shutdown(); fprintf(stderr,"Thread_Init() failed, aborting.\n"); return(-1); } while(grun) { usleep(10000); } Thread_Shutdown(); Pipes_Shutdown(); Object_Shutdown(); Hardware_Shutdown(); return(1); }
/* ==================== Host_Init ==================== */ static void Host_Init (void) { int i; const char* os; char vabuf[1024]; if (COM_CheckParm("-profilegameonly")) Sys_AllowProfiling(false); // LordHavoc: quake never seeded the random number generator before... heh if (COM_CheckParm("-benchmark")) srand(0); // predictable random sequence for -benchmark else srand((unsigned int)time(NULL)); // FIXME: this is evil, but possibly temporary // LordHavoc: doesn't seem very temporary... // LordHavoc: made this a saved cvar // COMMANDLINEOPTION: Console: -developer enables warnings and other notices (RECOMMENDED for mod developers) if (COM_CheckParm("-developer")) { developer.value = developer.integer = 1; developer.string = "1"; } if (COM_CheckParm("-developer2") || COM_CheckParm("-developer3")) { developer.value = developer.integer = 1; developer.string = "1"; developer_extra.value = developer_extra.integer = 1; developer_extra.string = "1"; developer_insane.value = developer_insane.integer = 1; developer_insane.string = "1"; developer_memory.value = developer_memory.integer = 1; developer_memory.string = "1"; developer_memorydebug.value = developer_memorydebug.integer = 1; developer_memorydebug.string = "1"; } if (COM_CheckParm("-developer3")) { gl_paranoid.integer = 1;gl_paranoid.string = "1"; gl_printcheckerror.integer = 1;gl_printcheckerror.string = "1"; } // COMMANDLINEOPTION: Console: -nostdout disables text output to the terminal the game was launched from if (COM_CheckParm("-nostdout")) sys_nostdout = 1; // used by everything Memory_Init(); // initialize console command/cvar/alias/command execution systems Cmd_Init(); // initialize memory subsystem cvars/commands Memory_Init_Commands(); // initialize console and logging and its cvars/commands Con_Init(); // initialize various cvars that could not be initialized earlier u8_Init(); Curl_Init_Commands(); Cmd_Init_Commands(); Sys_Init_Commands(); COM_Init_Commands(); FS_Init_Commands(); // initialize console window (only used by sys_win.c) Sys_InitConsole(); // initialize the self-pack (must be before COM_InitGameType as it may add command line options) FS_Init_SelfPack(); // detect gamemode from commandline options or executable name COM_InitGameType(); // construct a version string for the corner of the console os = DP_OS_NAME; dpsnprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring); Con_Printf("%s\n", engineversion); // initialize process nice level Sys_InitProcessNice(); // initialize ixtable Mathlib_Init(); // initialize filesystem (including fs_basedir, fs_gamedir, -game, scr_screenshot_name) FS_Init(); // register the cvars for session locking Host_InitSession(); // must be after FS_Init Crypto_Init(); Crypto_Init_Commands(); NetConn_Init(); Curl_Init(); //PR_Init(); //PR_Cmd_Init(); PRVM_Init(); Mod_Init(); World_Init(); SV_Init(); V_Init(); // some cvars needed by server player physics (cl_rollangle etc) Host_InitCommands(); Host_InitLocal(); Host_ServerOptions(); Thread_Init(); if (cls.state == ca_dedicated) Cmd_AddCommand ("disconnect", CL_Disconnect_f, "disconnect from server (or disconnect all clients if running a server)"); else { Con_DPrintf("Initializing client\n"); R_Modules_Init(); Palette_Init(); #ifdef CONFIG_MENU MR_Init_Commands(); #endif VID_Shared_Init(); VID_Init(); Render_Init(); S_Init(); CDAudio_Init(); Key_Init(); CL_Init(); } // save off current state of aliases, commands and cvars for later restore if FS_GameDir_f is called // NOTE: menu commands are freed by Cmd_RestoreInitState Cmd_SaveInitState(); // FIXME: put this into some neat design, but the menu should be allowed to crash // without crashing the whole game, so this should just be a short-time solution // here comes the not so critical stuff if (setjmp(host_abortframe)) { return; } Host_AddConfigText(); Cbuf_Execute(); // if stuffcmds wasn't run, then quake.rc is probably missing, use default if (!host_stuffcmdsrun) { Cbuf_AddText("exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\nstuffcmds\n"); Cbuf_Execute(); } // put up the loading image so the user doesn't stare at a black screen... SCR_BeginLoadingPlaque(true); #ifdef CONFIG_MENU if (cls.state != ca_dedicated) { MR_Init(); } #endif // check for special benchmark mode // COMMANDLINEOPTION: Client: -benchmark <demoname> runs a timedemo and quits, results of any timedemo can be found in gamedir/benchmark.log (for example id1/benchmark.log) i = COM_CheckParm("-benchmark"); if (i && i + 1 < com_argc) if (!sv.active && !cls.demoplayback && !cls.connect_trying) { Cbuf_AddText(va(vabuf, sizeof(vabuf), "timedemo %s\n", com_argv[i + 1])); Cbuf_Execute(); } // check for special demo mode // COMMANDLINEOPTION: Client: -demo <demoname> runs a playdemo and quits i = COM_CheckParm("-demo"); if (i && i + 1 < com_argc) if (!sv.active && !cls.demoplayback && !cls.connect_trying) { Cbuf_AddText(va(vabuf, sizeof(vabuf), "playdemo %s\n", com_argv[i + 1])); Cbuf_Execute(); } // COMMANDLINEOPTION: Client: -capturedemo <demoname> captures a playdemo and quits i = COM_CheckParm("-capturedemo"); if (i && i + 1 < com_argc) if (!sv.active && !cls.demoplayback && !cls.connect_trying) { Cbuf_AddText(va(vabuf, sizeof(vabuf), "playdemo %s\ncl_capturevideo 1\n", com_argv[i + 1])); Cbuf_Execute(); } if (cls.state == ca_dedicated || COM_CheckParm("-listen")) if (!sv.active && !cls.demoplayback && !cls.connect_trying) { Cbuf_AddText("startmap_dm\n"); Cbuf_Execute(); } if (!sv.active && !cls.demoplayback && !cls.connect_trying) { #ifdef CONFIG_MENU Cbuf_AddText("togglemenu 1\n"); #endif Cbuf_Execute(); } Con_DPrint("========Initialized=========\n"); //Host_StartVideo(); if (cls.state != ca_dedicated) SV_StartThread(); }
/** * @brief */ static void Init(void) { SDL_Init(SDL_INIT_TIMER); Mem_Init(); Cmd_Init(); Cvar_Init(); verbose = Cvar_Add("verbose", "0", 0, "Print verbose debugging information"); dedicated = Cvar_Add("dedicated", "0", CVAR_NO_SET, "Run a dedicated server"); if (strstr(Sys_ExecutablePath(), "-dedicated")) { Cvar_ForceSet("dedicated", "1"); } if (dedicated->value) { Cvar_ForceSet("threads", "0"); } game = Cvar_Add("game", DEFAULT_GAME, CVAR_LATCH | CVAR_SERVER_INFO, "The game module name"); game->modified = g_strcmp0(game->string, DEFAULT_GAME); threads = Cvar_Add("threads", "0", CVAR_ARCHIVE, "Specifies the number of threads to create"); threads->modified = false; time_demo = Cvar_Add("time_demo", "0", CVAR_LO_ONLY, "Benchmark and stress test"); time_scale = Cvar_Add("time_scale", "1.0", CVAR_LO_ONLY, "Controls time lapse"); const char *s = va("Quetoo %s %s %s", VERSION, __DATE__, BUILD_HOST); Cvar_Add("version", s, CVAR_SERVER_INFO | CVAR_NO_SET, NULL); quetoo.Debug = Debug; quetoo.Error = Error; quetoo.Print = Print; quetoo.Verbose = Verbose; quetoo.Warn = Warn; Fs_Init(true); Thread_Init(threads->integer); Con_Init(); Cmd_Add("mem_stats", MemStats_f, CMD_SYSTEM, "Print memory stats"); Cmd_Add("debug", Debug_f, CMD_SYSTEM, "Control debugging output"); Cmd_Add("quit", Quit_f, CMD_SYSTEM, "Quit Quetoo"); Netchan_Init(); Sv_Init(); Cl_Init(); Com_Print("Quetoo %s %s %s initialized\n", VERSION, __DATE__, BUILD_HOST); // reset debug value since Cbuf may change it from Com's "all" init Com_SetDebug("0"); // execute any +commands specified on the command line Cbuf_InsertFromDefer(); Cbuf_Execute(); // dedicated server, nothing specified, use Edge if (dedicated->value && !Com_WasInit(QUETOO_SERVER)) { Cbuf_AddText("map edge\n"); Cbuf_Execute(); } }
TEST_END //=========================================================================== TEST(ut_quanta) { K_ULONG ulAvg; K_ULONG ulMax; K_ULONG ulMin; K_ULONG ulRange; // Create three Thread_ts that only increment counters - similar to the // previous test. However, modify the Thread_t quanta such that each Thread_t // will get a different proportion of the CPU cycles. Thread_Init( &stThread1, aucStack1, TEST_STACK_SIZE, 1, RR_EntryPoint, (void*)&ulRR1); Thread_Init( &stThread2, aucStack2, TEST_STACK_SIZE, 1, RR_EntryPoint, (void*)&ulRR2); Thread_Init( &stThread3, aucStack3, TEST_STACK_SIZE, 1, RR_EntryPoint, (void*)&ulRR3); ulRR1 = 0; ulRR2 = 0; ulRR3 = 0; // Adjust Thread_t priority before starting test Thread_ts to ensure // they all start at the same time (when we hit the 1 second sleep) Thread_SetPriority( Scheduler_GetCurrentThread(), 2); // Set a different execution quanta for each Thread_t Thread_SetQuantum( &stThread1, 3); Thread_SetQuantum( &stThread2, 6); Thread_SetQuantum( &stThread3, 9); Thread_Start( &stThread1 ); Thread_Start( &stThread2 ); Thread_Start( &stThread3 ); Thread_Sleep(1800); // When the sleep ends, this will preempt the Thread_t in progress, // allowing us to stop them, and drop priority. Thread_Stop( &stThread1 ); Thread_Stop( &stThread2 ); Thread_Stop( &stThread3 ); Thread_SetPriority( Scheduler_GetCurrentThread(), 1); // Test point - make sure that Q3 > Q2 > Q1 EXPECT_GT( ulRR2, ulRR1 ); EXPECT_GT( ulRR3, ulRR2 ); // scale the counters relative to the largest value, and compare. ulRR1 *= 3; ulRR2 *= 3; ulRR2 = (ulRR2 + 1) / 2; // After scaling, they should be nearly identical (well, stose at least) if (ulRR1 > ulRR2) { ulMax = ulRR1; } else { ulMax = ulRR2; } if (ulMax < ulRR3) { ulMax = ulRR3; } if (ulRR1 < ulRR2) { ulMin = ulRR1; } else { ulMin = ulRR2; } if (ulMin > ulRR3) { ulMin = ulRR3; } ulRange = ulMax - ulMin; ulAvg = (ulRR1 + ulRR2 + ulRR3) / 3; #if KERNEL_TIMERS_TICKLESS // Max-Min delta should not exceed 5% of average for this test EXPECT_LT( ulRange, ulAvg / 20); #else // Max-Min delta should not exceed 20% of average for this test -- tick-based timers // are coarse, and prone to Thread_t preference due to phase. EXPECT_LT( ulRange, ulAvg / 5); #endif // Make sure none of the component values are 0 EXPECT_FAIL_EQUALS( ulRR1, 0 ); EXPECT_FAIL_EQUALS( ulRR2, 0 ); EXPECT_FAIL_EQUALS( ulRR3, 0 ); }