void threads_test_case(int nthreads, int nyields) { test_thread_param_t* params = calloc(nthreads, sizeof(test_thread_param_t)); int counter = 0; int i; printf("Started test case with %d threads, each yielding %d times.\n", nthreads, nyields); for (i=0;i<nthreads;++i) { params[i].global_counter = &counter; params[i].nthreads = nthreads; params[i].num_yields = nyields; params[i].thread_id = i; } thread_manager_init(sched_init(stFifo)); for (i=0;i<nthreads;++i) { create_thread(&test_thread, ¶ms[i]); // printf("Thread %d created.\n", i); } // printf("Starting threads.\n"); threads_start(); // printf("All threads finished.\n"); }
BOOL do_run(ui_cmd_t* cmd, app_data_t* app_data) { unsigned i; if (!app_data->loaded) { printf("Must call 'load' before 'run'.\n"); return FALSE; } if (!app_data->initialized) { initialize_threads(app_data); } app_data->policy = atoi(cmd->param); //if param is empty, 0 is returned which is spDefault. app_data->job_count = 0; for (i=0;i<app_data->ntasks; ++i) { app_data->tasks[i].done = FALSE; } threads_start(); printf("All threads terminated.\n"); app_data->initialized = FALSE; return TRUE; }
int main(int argc, char *argv[]) { print_level = LOG_NOTICE; // print_level = LOG_DEBUG; parse_commandline(argc, argv); /* if history-lowpass is used ... if ((opt_switch_mux_frequency / SWITCH_LOWPASS_FREQUENCY) > MAX_BLINKENLIGHT_HISTORY_ENTRIES) { print(LOG_ERR, "Configuration error: multiplexing with %d Hz, Switch lowpass %d Hz:\n", opt_mux_frequency, SWITCH_LOWPASS_FREQUENCY) ; print(LOG_ERR, " would need %d value history entries, but only %d available!\n", (opt_mux_frequency / SWITCH_LOWPASS_FREQUENCY), MAX_BLINKENLIGHT_HISTORY_ENTRIES) ; exit(1); } */ sprintf(program_info, "PDP-15 blinkenlightd - Blinkenlight API server daemon for PDP-15 %s", VERSION); info(); print(LOG_INFO, "Start\n"); #ifdef TEST while(1) { struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 1000 * 100000/*microsecs*/; nanosleep(&ts, NULL); } exit(0); #endif // link set/get events blinkenlight_api_panel_get_controlvalues_evt = on_blinkenlight_api_panel_get_controlvalues; blinkenlight_api_panel_set_controlvalues_evt = on_blinkenlight_api_panel_set_controlvalues; blinkenlight_api_panel_get_state_evt = on_blinkenlight_api_panel_get_state; blinkenlight_api_panel_set_state_evt = on_blinkenlight_api_panel_set_state; blinkenlight_api_panel_get_mode_evt = on_blinkenlight_api_panel_get_mode; blinkenlight_api_panel_set_mode_evt = on_blinkenlight_api_panel_set_mode; blinkenlight_api_get_info_evt = on_blinkenlight_api_get_info; register_controls(); if (opt_test) { printf("Dump of register <-> control data struct:\n"); blinkenlight_panels_diagprint(blinkenlight_panel_list, stdout); exit(0); } threads_start(); // does never end! blinkenlight_api_server(); // does never end! print_close(); // well .... blinkenlight_panels_destructor(blinkenlight_panel_list); return 0; }
/* service_main */ static VOID WINAPI service_main(DWORD argc, LPTSTR *argv) { config_t conf; void* net; void* threads; void* pipe; h_service = RegisterServiceCtrlHandler(LDMSVC_SERVICE_NAME, handler); if(h_service == NULL) { return; } set_state1(SERVICE_START_PENDING); // SERVICE_START_PENDING // open the heap if(!heap_start()) { dout("Failed to create the heap\n"); set_state2(SERVICE_STOPPED, 1); return; } // parse configuration if(!config_parse_args(&conf, argc, argv)) { heap_stop(); set_state2(SERVICE_STOPPED, 1); return; } if(0) { dout(va("PORT: %u\n", conf.port)); dout(va("PIPE: %s\n", conf.pipe)); dout(va("MAXC: %u\n", conf.maxconn)); } // open network if((net = net_start()) == NULL) { heap_stop(); set_state2(SERVICE_STOPPED, 1); return; } // open the pipe if((pipe = pipe_start(conf.pipe)) == NULL) { net_stop(net); heap_stop(); set_state2(SERVICE_STOPPED, 1); return; } // connect the pipe if(!pipe_open(pipe)) { pipe_stop(pipe); net_stop(net); heap_stop(); set_state2(SERVICE_STOPPED, 1); return; } // start threads if((threads = threads_start(net, pipe, conf.maxconn)) == NULL) { pipe_stop(pipe); net_stop(net); heap_stop(); set_state2(SERVICE_STOPPED, 1); return; } set_state1(SERVICE_RUNNING); // SERVICE_RUNNING while(svc_state == SERVICE_RUNNING) { if(!net_is_ready(net)) { net_bind(net, NULL, conf.port); } if(!threads_think(threads)) { break; } Sleep(1); } set_state1(SERVICE_STOP_PENDING); // SERVICE_STOP_PENDING // close everything here threads_stop(threads); pipe_stop(pipe); net_stop(net); heap_stop(); set_state2(SERVICE_STOPPED, 0); // SERVICE_STOPPED }