TCase * make_mutex_tcase(void) { TCase *tc; initThreads(0); tc = tcase_create("Mutex"); tcase_add_checked_fixture(tc, test_setup, test_teardown); tcase_add_test(tc, MUTEX0100); tcase_add_test(tc, MUTEX0101); tcase_add_test(tc, MUTEX0102); tcase_add_test(tc, MUTEX0103); tcase_add_test(tc, MUTEX0200); tcase_add_test(tc, MUTEX0201); tcase_add_test(tc, MUTEX0202); tcase_add_test(tc, MUTEX0203); tcase_add_test(tc, MUTEX0300); tcase_add_test(tc, MUTEX0301); tcase_add_test(tc, MUTEX0302); tcase_add_test(tc, MUTEX0400); tcase_add_test(tc, MUTEX0401); tcase_add_test(tc, MUTEX0402); tcase_add_test(tc, MUTEX0403); tcase_add_test(tc, MUTEX0405); tcase_add_test(tc, MUTEX0406); tcase_add_test(tc, MUTEX0407); tcase_add_test(tc, MUTEX0500); tcase_add_test(tc, MUTEX0501); tcase_add_test(tc, MUTEX0600); tcase_add_test(tc, MUTEX0700); tcase_add_test(tc, MUTEX0705); return tc; }
std::shared_ptr<SimState> setState( const std::shared_ptr<const SimState> s){ if ( state && state->numThreads > 1 ) stopThreads(); auto old = state; state = std::make_shared<SimState>(*s); if ( state->numThreads > 1 ) initThreads(); return old; }
void Contest::init() { logMsg("Initialize Database..."); initDB(); logMsg("done\n"); /* logMsg("Load codes into RAM..."); loadCodes(); logMsg("done\n");*/ logMsg("Initialize Prizes..."); if (SetupPrizes == true) { setupPrizes(); logMsg("done\n"); } else logMsg("Already initialized.\n"); logMsg("Started signal handler..."); initSignal(); logMsg("done\n"); logMsg("Started thread engine..."); initThreads(iaddr); logMsg("done\n"); current_day = 0; current_week = 0; current_month = 0; return; }
int main(int argc, char* argv[]) { initData(); initThreads(); }
std::shared_ptr<SimState> setState(const SimState &s){ if ( state && state->numThreads > 1 ) stopThreads(); auto old = state; state.reset( new SimState(s) ); if ( state->numThreads > 1 ) initThreads(); return old; }
TCase * make_schedule_inheritance_graph_tcase(void) { TCase *tc; initThreads(0); tc = tcase_create("Schedule inheritance graph"); tcase_add_checked_fixture(tc, test_setup, test_teardown); tcase_add_test(tc, SIGRAPH0100); tcase_add_test(tc, SIGRAPH0200); tcase_add_test(tc, SIGRAPH0201); tcase_add_test(tc, SIGRAPH0202); tcase_add_test(tc, SIGRAPH0203); tcase_add_test(tc, SIGRAPH0204); tcase_add_test(tc, SIGRAPH0205); tcase_add_test(tc, SIGRAPH0206); tcase_add_test(tc, SIGRAPH0207); tcase_add_test(tc, SIGRAPH0208); tcase_add_test(tc, SIGRAPH0300); tcase_add_test(tc, SIGRAPH0301); tcase_add_test(tc, SIGRAPH0302); tcase_add_test(tc, SIGRAPH0303); tcase_add_test(tc, SIGRAPH0304); tcase_add_test(tc, SIGRAPH0305); tcase_add_test(tc, SIGRAPH0306); tcase_add_test(tc, SIGRAPH0400); tcase_add_test(tc, SIGRAPH0401); tcase_add_test(tc, SIGRAPH0500); tcase_add_test(tc, SIGRAPH0501); tcase_add_test(tc, SIGRAPH0502); tcase_add_test(tc, SIGRAPH0503); return tc; }
int mypthread_create(mypthread_t *thread, const mypthread_attr_t *attr, void *(*start_routine) (void *), void *arg) { if (count == MAXTHREADS) { printf("Maximum number of threads reached: %d\n", MAXTHREADS); return -1; } static int firstRun = 1; if (firstRun) { initThreads(); firstRun = 0; mainSetup = 0; } int unused = getUnused(); if (getcontext(&(allThreads[unused].context)) != 0) { perror("Error getting context.\n"); return -1; } allThreads[unused].context.uc_stack.ss_sp = malloc(STACKSIZE); allThreads[unused].context.uc_stack.ss_size = STACKSIZE; makecontext(&(allThreads[unused].context), (void*) start_routine, 1, arg); allThreads[unused].status = READY; *thread = allThreads[unused]; count++; return 0; }
void MandelbrotWidget::setThreadCount(int threadCount) { Q_ASSERT(threadCount > 0); stopRendering(); m_threadCount = threadCount; initThreads(); }
CMPI_EXTERN_C CMPIInstanceMI * TestInstanceProvider_Create_InstanceMI (const CMPIBroker * brkr, const CMPIContext * ctx, CMPIStatus * rc) { static CMPIInstanceMI mi = { ((void *) 0), &instMIFT__, }; _broker = brkr; initThreads(); initialize(); return &mi; }
void initialize () { glMatrixMode(GL_PROJECTION); glViewport(0, 0, TCC::windowWidth, TCC::windowHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glClearColor(1, 1, 1, 1); TCC::displayBuffer = new TCC::Display(TCC::windowWidth, TCC::windowHeight); TCC::buffer = new TCC::GridBuffer(TCC::windowWidth, TCC::windowHeight); initThreads(); ImguiConf::InitImGui(); TCC::buffer->randomFill(); }
int main(void) { irq_initialize_vectors(); cpu_irq_enable(); sysclk_init(); board_init(); configure_console(); ctrl_access_init(); // Required with FreeRTOS //memories_initialization(); // Create a semaphore to manage the memories data transfer vSemaphoreCreateBinary(main_trans_semphr); Assert( main_trans_semphr != NULL ); // Start USB stack to authorize VBus monitoring // udc_start(); // Create a task to process data transfer /** xTaskCreate(main_memories_trans_task, ((const signed portCHAR *)"DATA TRANSFER"), #if defined(CONF_BOARD_NAND) 3072/sizeof(portSTACK_TYPE), // NF require large stack #else 256, #endif NULL, tskIDLE_PRIORITY + 1, NULL); */ initThreads(); initBMS(); // Uncomment the following line, if you want FreeRTOS to always run // when USB cable is unplugged. // IDLE is the sleep level required by the Timer counter used by FreeRTOS. // sleepmgr_lock_mode(SLEEPMGR_IDLE); // Start OS scheduler vTaskStartScheduler(); return 0; }
static void test_setup(void) { L4_Word_t res; res = okl4_kmutexid_allocany(mutexid_pool, &mutex1); fail_unless(res == OKL4_OK, "Failed to allocate any mutex id."); res = okl4_kmutexid_allocany(mutexid_pool, &mutex2); fail_unless(res == OKL4_OK, "Failed to allocate any mutex id."); initThreads(0); setup_thread = test_tid; L4_CreateMutex(mutex1); L4_CreateMutex(mutex2); prio6bis_thread = L4_nilthread; prio8_thread = L4_nilthread; }
int _glfwPlatformInit( void ) { // Initialize display if( !initDisplay() ) { return GL_FALSE; } // Initialize thread package initThreads(); // Start the timer _glfwInitTimer(); return GL_TRUE; }
void Main () { int i, me; void printMyThread(); initThreads (); me = getThread (); for(i=1; i<MAXTHREADS; i++) spawnThread(printMyThread,0); for (i = 0; i < NUMYIELDS; i++) { Printf("0 T%d\n",me); yieldThread(1); } exitThread (); }
TCase * make_smt_tcase(void) { TCase *tc; initThreads(0); tc = tcase_create("Multi-threaded (SMT) Tests"); tcase_add_checked_fixture(tc, test_setup, test_teardown); tcase_add_test(tc, SMT0100); tcase_add_test(tc, SMT0200); tcase_add_test(tc, SMT0300); tcase_add_test(tc, SMT0301); tcase_add_test(tc, SMT0302); tcase_add_test(tc, SMT0303); tcase_add_test(tc, SMT0304); tcase_add_test(tc, SMT0500); tcase_add_test(tc, SMT0600); return tc; }
void initNtop(char *devices) { char value[32]; revertSlashIfWIN32(myGlobals.dbPath, 0); revertSlashIfWIN32(myGlobals.spoolPath, 0); initIPServices(); handleProtocols(); myGlobals.l7.numSupportedProtocols = IPOQUE_MAX_SUPPORTED_PROTOCOLS; if(myGlobals.numIpProtosToMonitor == 0) addDefaultProtocols(); /* * Initialize memory and data. */ initDevices(devices); init_events(); if(myGlobals.runningPref.enableSessionHandling) initPassiveSessions(); initL7Discovery(); /* ********************************** */ initGdbm(myGlobals.dbPath, myGlobals.spoolPath, 0); /* We just initialized gdbm: let's now dump serials */ dumpHostSerial(&myGlobals.broadcastEntry->hostSerial, myGlobals.broadcastEntry->serialHostIndex); dumpHostSerial(&myGlobals.otherHostEntry->hostSerial, myGlobals.otherHostEntry->serialHostIndex); if(myGlobals.runningPref.daemonMode) { /* Before bacoming a daemon we need o make sure that ntop has been installed properly and that all the html files are on the right place */ int idx, found = 0; for(idx=0; (!found) && (myGlobals.dataFileDirs[idx] != NULL); idx++) { char tmpStr[256]; struct stat statbuf; if(strcmp(myGlobals.dataFileDirs[idx], ".") /* ignore local paths */ ) { safe_snprintf(__FILE__, __LINE__, tmpStr, sizeof(tmpStr), "%s/html/%s", myGlobals.dataFileDirs[idx], "ntop.gif" /* This file must always exist */); if(stat(tmpStr, &statbuf) == 0) { found = 1; break; } } } if(!found) { traceEvent(CONST_TRACE_WARNING, "ntop will not become a daemon as it has not been"); traceEvent(CONST_TRACE_WARNING, "installed properly (did you do 'make install')"); } else daemonizeUnderUnix(); } /* Handle local addresses (if any) */ handleLocalAddresses(myGlobals.runningPref.localAddresses); /* Handle known subnetworks (if any) */ handleKnownAddresses(myGlobals.runningPref.knownSubnets); if((myGlobals.pcap_file_list != NULL) && (myGlobals.runningPref.localAddresses == NULL)) { char *any_net = "0.0.0.0/0"; traceEvent(CONST_TRACE_WARNING, "-m | local-subnets must be specified when the -f option is used" "Assuming %s", any_net); myGlobals.runningPref.localAddresses = strdup(any_net); } if(myGlobals.runningPref.currentFilterExpression != NULL) parseTrafficFilter(); else myGlobals.runningPref.currentFilterExpression = strdup(""); /* so that it isn't NULL! */ /* Handle flows (if any) */ handleFlowsSpecs(); createPortHash(); initCounters(); initApps(); initThreads(); #ifndef MAKE_MICRO_NTOP traceEvent(CONST_TRACE_NOISY, "Starting Plugins"); startPlugins(); traceEvent(CONST_TRACE_NOISY, "Plugins started... continuing with initialization"); #endif #if defined(MEMORY_DEBUG) && defined(MAKE_WITH_SAFER_ROUTINES) resetLeaks(); #endif addNewIpProtocolToHandle("IGMP", 2, 0 /* no proto */); addNewIpProtocolToHandle("OSPF", 89, 0 /* no proto */); addNewIpProtocolToHandle("IPsec", 50, 51); init_maps(); loadGeoIP(); /* Note that by default ntop will merge network interfaces */ if(myGlobals.runningPref.mergeInterfaces == 0) traceEvent(CONST_TRACE_ALWAYSDISPLAY, "NOTE: Interface merge disabled by default"); else traceEvent(CONST_TRACE_ALWAYSDISPLAY, "NOTE: Interface merge enabled by default"); if(fetchPrefsValue("globals.displayPolicy", value, sizeof(value)) == -1) { myGlobals.hostsDisplayPolicy = showAllHosts /* 0 */; storePrefsValue("globals.displayPolicy", "0"); } else { myGlobals.hostsDisplayPolicy = atoi(value); /* Out of range check */ if((myGlobals.hostsDisplayPolicy < showAllHosts) || (myGlobals.hostsDisplayPolicy > showOnlyRemoteHosts)) myGlobals.hostsDisplayPolicy = showAllHosts; } if(fetchPrefsValue("globals.localityPolicy", value, sizeof(value)) == -1) { myGlobals.localityDisplayPolicy = showSentReceived /* 0 */; storePrefsValue("globals.localityPolicy", "0"); } else { myGlobals.localityDisplayPolicy = atoi(value); /* Out of range check */ if((myGlobals.localityDisplayPolicy < showSentReceived) || (myGlobals.localityDisplayPolicy > showOnlyReceived)) myGlobals.localityDisplayPolicy = showSentReceived; } if(myGlobals.runningPref.skipVersionCheck != TRUE) { pthread_t myThreadId; createThread(&myThreadId, checkVersion, NULL); } }
void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); static bool pause = false; static bool step = false; std::vector<std::future<std::array<unsigned int, 4>>> res; res.resize(TCC::workerThreads.size()); if (!pause || step) { auto range = (unsigned int)std::ceil((float)(TCC::windowWidth * TCC::windowHeight) / (float)TCC::workerThreads.size()); for (std::size_t i = 0; i < TCC::workerThreads.size(); ++i) { auto from = range * i; auto to = (from + range); if (to > TCC::windowWidth * TCC::windowHeight) to = TCC::windowWidth * TCC::windowHeight; res[i] = TCC::workerThreads[i]->getCommandQueue() .priorityFutureEmplace<TCC::WorkerThread::Compute, std::array<unsigned int, 4>>(from, to); } TCC::Counter[TCC::Medecine] = 0; TCC::Counter[TCC::Cancer] = 0; TCC::Counter[TCC::None] = 0; TCC::Counter[TCC::Healthy] = 0; for (std::size_t i = 0; i < res.size(); ++i) { auto t = res[i].get(); TCC::Counter[0] += t[0]; TCC::Counter[1] += t[1]; TCC::Counter[2] += t[2]; TCC::Counter[3] += t[3]; } TCC::buffer->swap(); } step = false; TCC::buffer->fillDisplay(*TCC::displayBuffer); for (auto i = 0; i < TCC::injectionThickness; ++i) { if (TCC::injectionRadius == 1 && TCC::injectionThickness == 1) TCC::displayBuffer->drawPixel(TCC::Position(TCC::mouse_x / TCC::zoom, (TCC::windowHeight - TCC::mouse_y) / TCC::zoom), TCC::Color(30)); else TCC::displayBuffer->drawCircle(TCC::Position(TCC::mouse_x / TCC::zoom, (TCC::windowHeight - TCC::mouse_y) / TCC::zoom), TCC::injectionRadius + i, TCC::Color(30)); } if (TCC::rMouse) { TCC::buffer->inject((unsigned int)(TCC::mouse_x / TCC::zoom), (unsigned int)((TCC::windowHeight - TCC::mouse_y) / TCC::zoom)); } TCC::displayBuffer->render(); ImguiConf::UpdateImGui(); ImGui::Text("Right click to inject medecine ! \nCancer cells are red, healthy one are green, and medecine is yellow ! \n"); static float ms_per_frame[120] = { 0 }; static int ms_per_frame_idx = 0; static float ms_per_frame_accum = 0.0f; ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx]; ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f; ms_per_frame_accum += ms_per_frame[ms_per_frame_idx]; ms_per_frame_idx = (ms_per_frame_idx + 1) % 120; const float ms_per_frame_avg = ms_per_frame_accum / 120; ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg); ImGui::Text("Injection Radius"); ImGui::SliderInt("Injection Radius", &TCC::injectionRadius, 1, 200); ImGui::SliderInt("Injection Thickness", &TCC::injectionThickness, 1, 100); if (ImGui::SliderInt("Cancer %", &TCC::cancerPercent, 0, 100 - TCC::healthyPercent)) { TCC::buffer->randomFill(); } if (ImGui::SliderInt("Healthy %", &TCC::healthyPercent, 0, 100 - TCC::cancerPercent)) { TCC::buffer->randomFill(); } if (ImGui::SliderInt("Threads number", &TCC::threadNumber, 1, 16)) { initThreads(); } ImGui::SliderFloat("Zoom ", &TCC::zoom, 1, 15); ImGui::Text("Healthy cells : %i", TCC::Counter[TCC::Healthy]); ImGui::Text("Cancer cells : %i", TCC::Counter[TCC::Cancer]); ImGui::Text("Medecine cells : %i", TCC::Counter[TCC::Medecine]); ImGui::Text("Empty cells : %i", TCC::Counter[TCC::None]); if (ImGui::Button("Reset")) { TCC::buffer->randomFill(); } static std::string playpausestr = "Pause"; if (ImGui::Button(playpausestr.c_str())) { pause = !pause; if (pause) playpausestr = "Play"; else playpausestr = "Pause"; } if (pause) { if (ImGui::Button("Step forward")) { step = true; } } ImGui::Render(); glutSwapBuffers(); }
void Halite::init() { //Add colors to possible colors: possible_colors.clear(); possible_colors.push_back({ 1.0f, 0.0f, 0.0f }); possible_colors.push_back({ 0.0f, 1.0f, 0.0f }); possible_colors.push_back({ 0.0f, 0.0f, 1.0f }); possible_colors.push_back({ 1.0f, 1.0f, 0.0f }); possible_colors.push_back({ 1.0f, 0.0f, 1.0f }); possible_colors.push_back({ 0.0f, 1.0f, 1.0f }); possible_colors.push_back({ 1.0f, 1.0f, 1.0f }); possible_colors.push_back({ .87f, .72f, .53f }); possible_colors.push_back({ 1.0f, 0.5f, 0.5f }); possible_colors.push_back({ 1.0f, .65f, 0.0f }); //Create color codes std::vector<Color> newColors = possible_colors; color_codes.clear(); for(int a = 0; a < number_of_players; a++) { int index = rand() % newColors.size(); color_codes[a + 1] = newColors[index]; newColors.erase(newColors.begin() + index); } //Default initialize player_moves = std::vector< std::set<hlt::Move> >(); turn_number = 0; player_names = std::vector< std::string >(number_of_players); //Output initial map to file std::vector<unsigned char> * turn = new std::vector<unsigned char>; turn->reserve(game_map.map_height * game_map.map_width * 1.25); unsigned char presentOwner = game_map.contents.begin()->begin()->owner; std::list<unsigned char> strengths; short numPieces = 0; for(auto a = game_map.contents.begin(); a != game_map.contents.end(); a++) for(auto b = a->begin(); b != a->end(); b++) { if (numPieces == 255 || b->owner != presentOwner) { turn->push_back(numPieces); turn->push_back(presentOwner); for(auto b = strengths.begin(); b != strengths.end(); b++) turn->push_back(*b); strengths.clear(); numPieces = 0; presentOwner = b->owner; } numPieces++; strengths.push_back(b->strength); } //Final output set: turn->push_back(numPieces); turn->push_back(presentOwner); for(auto b = strengths.begin(); b != strengths.end(); b++) turn->push_back(*b); turn->shrink_to_fit(); //Add to full game: full_game.push_back(turn); //Initialize player moves vector player_moves.resize(number_of_players); //Init statistics alive_frame_count = std::vector<unsigned short>(number_of_players, 1); full_territory_count = std::vector<unsigned int>(number_of_players, 1); full_strength_count = std::vector<unsigned int>(number_of_players, 255); full_production_count = std::vector<unsigned int>(number_of_players); full_still_count = std::vector<unsigned int>(number_of_players); full_cardinal_count = std::vector<unsigned int>(number_of_players); total_response_time = std::vector<unsigned int>(number_of_players); timeout_tags = std::set<unsigned short>(); //Send initial package std::vector< std::future<bool> > initThreads(number_of_players); const int BOT_INITIALIZATION_TIMEOUT_MILLIS = 2000 + (game_map.map_width * game_map.map_height) * 2; for(unsigned char a = 0; a < number_of_players; a++) { initThreads[a] = std::async(&Networking::handleInitNetworking, networking, static_cast<unsigned int>(BOT_INITIALIZATION_TIMEOUT_MILLIS), static_cast<unsigned char>(a + 1), game_map, &player_names[a]); } for(unsigned char a = 0; a < number_of_players; a++) { bool success = initThreads[a].get(); if (!success) { networking.killPlayer(a + 1); } } }
static void test_setup(void) { initThreads(1); ipc_main_thread = test_tid; }
TCase * make_ipc_cpx_tcase(void) { TCase *tc; initThreads(0); tc = tcase_create("Ipc complex"); tcase_add_checked_fixture(tc, test_setup, test_teardown); tcase_add_test(tc, IPCCPX0001); tcase_add_test(tc, IPCCPX0002); tcase_add_test(tc, IPCCPX0003); tcase_add_test(tc, IPCCPX0004); tcase_add_test(tc, IPCCPX0005); tcase_add_test(tc, IPCCPX0006); tcase_add_test(tc, IPCCPX0007); tcase_add_test(tc, IPCCPX0008); tcase_add_test(tc, IPCCPX0009); tcase_add_test(tc, IPCCPX0010); tcase_add_test(tc, IPCCPX0011); tcase_add_test(tc, IPCCPX0012); tcase_add_test(tc, IPCCPX0013); tcase_add_test(tc, IPCCPX0014); tcase_add_test(tc, IPCCPX0015); tcase_add_test(tc, IPCCPX0016); tcase_add_test(tc, IPCCPX0017); tcase_add_test(tc, IPCCPX0018); tcase_add_test(tc, IPCCPX0019); tcase_add_test(tc, IPCCPX0020); tcase_add_test(tc, IPCCPX0021); tcase_add_test(tc, IPCCPX0022); tcase_add_test(tc, IPCCPX0023); tcase_add_test(tc, IPCCPX0024); tcase_add_test(tc, IPCCPX0025); tcase_add_test(tc, IPCCPX0026); tcase_add_test(tc, IPCCPX0027); tcase_add_test(tc, IPCCPX0028); tcase_add_test(tc, IPCCPX0029); tcase_add_test(tc, IPCCPX0030); tcase_add_test(tc, IPCCPX0031); tcase_add_test(tc, IPCCPX0032); tcase_add_test(tc, IPCCPX0033); tcase_add_test(tc, IPCCPX0034); tcase_add_test(tc, IPCCPX0035); tcase_add_test(tc, IPCCPX0036); tcase_add_test(tc, IPCCPX0037); tcase_add_test(tc, IPCCPX0038); tcase_add_test(tc, IPCCPX0039); tcase_add_test(tc, IPCCPX0040); tcase_add_test(tc, IPCCPX0041); tcase_add_test(tc, IPCCPX0042); tcase_add_test(tc, IPCCPX0043); tcase_add_test(tc, IPCCPX0044); tcase_add_test(tc, IPCCPX0045); tcase_add_test(tc, IPCCPX0046); tcase_add_test(tc, IPCCPX0047); tcase_add_test(tc, IPCCPX0048); return tc; }
static void test_setup(void) { initThreads(0); main_thread = test_tid; }