//============================================================================== bool CC_Base::execute(int argc, char *argv[]) { po::options_description desc; init_options(desc); try { po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("log")) init_log(argc, argv, option_log_name_); if (!read_options(desc, vm)) return false; if (init_programmer() && init_unit()) { log_info("main, start task processing"); process_tasks(); log_info("main, finish task processing"); programmer_.unit_close(); return true; } } catch (std::runtime_error& e) // usb, file error { std::cout << " Error occured"; if (strlen(e.what())) { std::cout << ": " << e.what(); log_info("%s", e.what()); } std::cout << "\n"; } catch (po::error& e) //command line error { std::cout << " Bad command line options"; if (strlen(e.what())) std::cout << " (" << e.what() << ")"; std::cout << "\n Try --help for more information\n"; } return false; }
int main(){ int i; for (i = 0; i < N; i++){ a[i] = b[i] = i; c[i] = 0; } process_tasks(); for (i = 0; i < N; ++i) printf("%d\t",a[i]); printf("\n"); for (i = 0; i < N; ++i) printf("%d\t",b[i]); printf("\n"); for (i = 0; i < N; ++i) printf("%d\t",c[i]); printf("\n"); return 0; }
static LRESULT WINAPI notif_wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_MK_CONTINUE: { BindProtocol *This = (BindProtocol*)lParam; process_tasks(This); IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface); return 0; } case WM_MK_RELEASE: { tls_data_t *data = get_tls_data(); if(!--data->notif_hwnd_cnt) { DestroyWindow(hwnd); data->notif_hwnd = NULL; } } } return DefWindowProcW(hwnd, msg, wParam, lParam); }
int main(void) { _delay_ms(50); init_task_man(); USART_INIT_POLLING(); bluetooth_init(); // USART_INIT_INTERRUPT(); AVC_init(1); sei(); // usart_put_c('t'); _delay_ms(200); // AVC_add_tx_transaction_from_list(SELF_REGISTER); sei(); // wdt_enable( WDTO_2S ); while(1){ // Reset watchdog. // wdt_reset(); process_tasks(); } }
void radiosity() { long process_id; long rad_start, refine_done, vertex_start, vertex_done; THREAD_INIT_FREE(); LOCK(global->index_lock); process_id = global->index++; UNLOCK(global->index_lock); process_id = process_id % n_processors; BARINCLUDE(global->barrier); if ((process_id == 0) || (dostats)) CLOCK(rad_start); /* POSSIBLE ENHANCEMENT: Here is where one might pin processes to processors to avoid migration */ /* POSSIBLE ENHANCEMENT: Here is where one might reset the statistics that one is measuring about the parallel execution */ // Enable Modeling CarbonEnableModels(); /* Decompose model objects into patches and build the BSP tree */ /* Create the initial tasks */ init_modeling_tasks(process_id) ; process_tasks(process_id) ; /* Gather rays & do BF refinement */ while( init_ray_tasks(process_id) ) { /* Wait till tasks are put in the queue */ BARRIER(global->barrier, n_processors); /* Then perform ray-gathering and BF-refinement till the solution converges */ process_tasks(process_id) ; } if ((process_id == 0) || (dostats)) CLOCK(refine_done); BARRIER(global->barrier, n_processors); if ((process_id == 0) || (dostats)) CLOCK(vertex_start); /* Compute area-weighted radiosity value at each vertex */ init_radavg_tasks( RAD_AVERAGING_MODE, process_id ) ; process_tasks(process_id) ; /* Then normalize the radiosity at vertices */ init_radavg_tasks( RAD_NORMALIZING_MODE, process_id ) ; process_tasks(process_id) ; if ((process_id == 0) || (dostats)) CLOCK(vertex_done); if ((process_id == 0) || (dostats)) { timing[process_id]->rad_start = rad_start; timing[process_id]->rad_time = vertex_done - rad_start; timing[process_id]->refine_time = refine_done - rad_start; timing[process_id]->vertex_time = vertex_done - vertex_start; timing[process_id]->wait_time = vertex_start - refine_done; } // Disable Models CarbonDisableModels(); }
void start_radiosity(long val) #endif { static long state = 0 ; long i; long total_rad_time, max_rad_time, min_rad_time; long total_refine_time, max_refine_time, min_refine_time; long total_wait_time, max_wait_time, min_wait_time; long total_vertex_time, max_vertex_time, min_vertex_time; #if defined(SGI_GL) && defined(GL_NASA) long val ; val = g_get_choice_val( ap, &choices[0] ) ; #endif if( val == CHOICE_RAD_RUN ) { if( state == -1 ) { printf( "Please reset first\007\n" ) ; return ; } /* Time stamp */ CLOCK( time_rad_start ) ; global->index = 0; /* Create slave processes */ for (i = 0 ; i < n_processors ; i++ ) { taskqueue_id[i] = assign_taskq(0) ; } /* And start processing */ CREATE(radiosity, n_processors); WAIT_FOR_END(n_processors); /* Time stamp */ CLOCK( time_rad_end ); /* Print out running time */ /* Print out running time */ printf("TIMING STATISTICS MEASURED BY MAIN PROCESS:\n"); print_running_time(0); if (dostats) { printf("\n\n\nPER-PROCESS STATISTICS:\n"); printf("%8s%20s%20s%12s%12s\n","Proc","Total","Refine","Wait","Smooth"); printf("%8s%20s%20s%12s%12s\n\n","","Time","Time","Time","Time") ; for (i = 0; i < n_processors; i++) printf("%8ld%20lu%20lu%12lu%12lu\n",i,timing[i]->rad_time, timing[i]->refine_time, timing[i]->wait_time, timing[i]->vertex_time); total_rad_time = timing[0]->rad_time; max_rad_time = timing[0]->rad_time; min_rad_time = timing[0]->rad_time; total_refine_time = timing[0]->refine_time; max_refine_time = timing[0]->refine_time; min_refine_time = timing[0]->refine_time; total_wait_time = timing[0]->wait_time; max_wait_time = timing[0]->wait_time; min_wait_time = timing[0]->wait_time; total_vertex_time = timing[0]->vertex_time; max_vertex_time = timing[0]->vertex_time; min_vertex_time = timing[0]->vertex_time; for (i = 1; i < n_processors; i++) { total_rad_time += timing[i]->rad_time; if (timing[i]->rad_time > max_rad_time) max_rad_time = timing[i]->rad_time; if (timing[i]->rad_time < min_rad_time) min_rad_time = timing[i]->rad_time; total_refine_time += timing[i]->refine_time; if (timing[i]->refine_time > max_refine_time) max_refine_time = timing[i]->refine_time; if (timing[i]->refine_time < min_refine_time) min_refine_time = timing[i]->refine_time; total_wait_time += timing[i]->wait_time; if (timing[i]->wait_time > max_wait_time) max_wait_time = timing[i]->wait_time; if (timing[i]->wait_time < min_wait_time) min_wait_time = timing[i]->wait_time; total_vertex_time += timing[i]->vertex_time; if (timing[i]->vertex_time > max_vertex_time) max_vertex_time = timing[i]->vertex_time; if (timing[i]->vertex_time < min_vertex_time) min_vertex_time = timing[i]->vertex_time; } printf("\n\n%8s%20lu%20lu%12lu%12lu\n","Max", max_rad_time, max_refine_time, max_wait_time, max_vertex_time); printf("\n%8s%20lu%20lu%12lu%12lu\n","Min", min_rad_time, min_refine_time, min_wait_time, min_vertex_time); printf("\n%8s%20lu%20lu%12lu%12lu\n","Avg", (long) (((double) total_rad_time) / ((double) (1.0 * n_processors))), (long) (((double) total_refine_time) / ((double) (1.0 * n_processors))), (long) (((double) total_wait_time) / ((double) (1.0 * n_processors))), (long) (((double) total_vertex_time) / ((double) (1.0 * n_processors)))); printf("\n\n"); } /* print_fork_time(0) ; */ print_statistics( stdout, 0 ) ; /* Display image */ display_scene( disp_fill_mode, disp_patch_switch, disp_mesh_switch, disp_interaction_switch, 0) ; state = -1 ; } else if( val == CHOICE_RAD_STEP ) { if( state == -1 ) { printf( "Please reset first\007\n" ) ; return ; } /* Step execution */ switch( state ) { case 0: /* Step execute as a single process */ global->index = 1; /* Create slave processes */ for ( i = 0 ; i < n_processors ; i++ ) { taskqueue_id[i] = assign_taskq(0) ; } CREATE(radiosity, n_processors/* - 1*/); /* Decompose model objects into patches and build the BSP tree */ /* Create the first tasks (MASTER only) */ init_modeling_tasks(0) ; process_tasks(0) ; state ++ ; break ; case 1: if( init_ray_tasks(0) ) { BARRIER(global->barrier, n_processors); process_tasks(0) ; } else state++ ; break ; default: BARRIER(global->barrier, n_processors); init_radavg_tasks( RAD_AVERAGING_MODE, 0 ) ; process_tasks(0) ; init_radavg_tasks( RAD_NORMALIZING_MODE, 0 ) ; process_tasks(0) ; WAIT_FOR_END(n_processors/* - 1*/) state = -1 ; } /* Display image */ display_scene( disp_fill_mode, disp_patch_switch, disp_mesh_switch, disp_interaction_switch, 0) ; } else if( val == CHOICE_RAD_RESET ) { /* Initialize global variables again */ init_global(0) ; init_visibility_module(0) ; g_clear() ; state = 0 ; } }
static HRESULT WINAPI BindProtocol_StartEx(IInternetProtocolEx *iface, IUri *pUri, IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE *dwReserved) { BindProtocol *This = impl_from_IInternetProtocolEx(iface); IInternetProtocol *protocol = NULL; IInternetProtocolEx *protocolex; IInternetPriority *priority; IServiceProvider *service_provider; BOOL urlmon_protocol = FALSE; CLSID clsid = IID_NULL; LPOLESTR clsid_str; HRESULT hres; TRACE("(%p)->(%p %p %p %08x %p)\n", This, pUri, pOIProtSink, pOIBindInfo, grfPI, dwReserved); if(!pUri || !pOIProtSink || !pOIBindInfo) return E_INVALIDARG; This->pi = grfPI; IUri_AddRef(pUri); This->uri = pUri; hres = IInternetProtocolSink_QueryInterface(pOIProtSink, &IID_IServiceProvider, (void**)&service_provider); if(SUCCEEDED(hres)) { /* FIXME: What's protocol CLSID here? */ IServiceProvider_QueryService(service_provider, &IID_IInternetProtocol, &IID_IInternetProtocol, (void**)&protocol); IServiceProvider_Release(service_provider); } if(!protocol) { IClassFactory *cf; IUnknown *unk; hres = get_protocol_handler(pUri, &clsid, &urlmon_protocol, &cf); if(FAILED(hres)) return hres; if(This->from_urlmon) { hres = IClassFactory_CreateInstance(cf, NULL, &IID_IInternetProtocol, (void**)&protocol); IClassFactory_Release(cf); if(FAILED(hres)) return hres; }else { hres = IClassFactory_CreateInstance(cf, (IUnknown*)&This->IInternetBindInfo_iface, &IID_IUnknown, (void**)&unk); IClassFactory_Release(cf); if(FAILED(hres)) return hres; hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocol, (void**)&protocol); IUnknown_Release(unk); if(FAILED(hres)) return hres; } } StringFromCLSID(&clsid, &clsid_str); IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_PROTOCOLCLASSID, clsid_str); CoTaskMemFree(clsid_str); This->protocol = protocol; if(urlmon_protocol) { IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&This->wininet_info); IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&This->wininet_http_info); } set_binding_sink(This, pOIProtSink, pOIBindInfo); hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority); if(SUCCEEDED(hres)) { IInternetPriority_SetPriority(priority, This->priority); IInternetPriority_Release(priority); } hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolEx, (void**)&protocolex); if(SUCCEEDED(hres)) { hres = IInternetProtocolEx_StartEx(protocolex, pUri, &This->IInternetProtocolSink_iface, &This->IInternetBindInfo_iface, 0, NULL); IInternetProtocolEx_Release(protocolex); }else { hres = IUri_GetDisplayUri(pUri, &This->display_uri); if(FAILED(hres)) return hres; hres = IInternetProtocol_Start(protocol, This->display_uri, &This->IInternetProtocolSink_iface, &This->IInternetBindInfo_iface, 0, 0); } if(SUCCEEDED(hres)) process_tasks(This); return hres; }
int main(int argc, char *argv[]) { int c, status; char *src; buf_s *in; struct sigaction sa; sym_record_s *rec, *recb; pthread_t req_thread; sigset_t mask; if(argc > 1) { src = readfile(argv[1]); parse(src); closefile(); } else { src = readfile("test"); parse(src); closefile(); } name = "ap"; name_stripped = "ap"; name_len = sizeof("ap")-1; if(access("out/", F_OK)) { if(errno == ENOENT) mkdir("out", S_IRWXU); else { perror("Directory Access"); exit(EXIT_FAILURE); } } logfile = fopen("out/ap", "w"); if(!logfile) { perror("Error Creating file for redirection"); exit(EXIT_FAILURE); } sa.sa_handler = sigUSR1; sa.sa_flags = SA_RESTART; sigemptyset(&sa.sa_mask); status = sigaction(SIGUSR1, &sa, NULL); if(status < 0) { perror("Error installing handler for SIGUSR1"); exit(EXIT_FAILURE); } sa.sa_handler = sigALARM; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); status = sigaction(SIGALRM, &sa, NULL); if(status < 0) { perror("Error installing handler for SIGTERM"); exit(EXIT_FAILURE); } shm_mediums = shmget(SHM_KEY_S, sizeof(*mediums), IPC_CREAT|SHM_R|SHM_W); if(shm_mediums < 0) { perror("Failed to set up shared memory segment"); exit(EXIT_FAILURE); } mediums = shmat(shm_mediums, NULL, 0); if(mediums == (medium_s *)-1) { perror("Failed to attached shared memory segment."); exit(EXIT_FAILURE); } mediums->isbusy = false; shm_mediumc = shmget(SHM_KEY_C, sizeof(*mediumc), IPC_CREAT|SHM_R|SHM_W); if(shm_mediumc < 0) { perror("Failed to set up shared memory segment"); exit(EXIT_FAILURE); } mediumc = shmat(shm_mediumc, NULL, 0); if(mediumc == (medium_s *)-1) { perror("Failed to attached shared memory segment."); exit(EXIT_FAILURE); } mediumc->isbusy = false; status = pthread_create(&req_thread, NULL, process_request, NULL); if(status) { perror("Failure to set up thread"); exit(EXIT_FAILURE); } sigemptyset(&mask); sigaddset(&mask, SIGUSR2); status = pthread_sigmask(SIG_BLOCK, &mask, NULL); if(status) { perror("Failure to mask SIGUSR2 in parent thread."); exit(EXIT_FAILURE); } process_tasks(); in = buf_init(); /* Get command line input */ printf("> "); while((c = getchar()) != EOF) { buf_addc(&in, c); if(c == '\n') { buf_addc(&in, '\0'); parse(in->buf); process_tasks(); buf_reset(&in); printf("> "); } } buf_free(in); pthread_mutex_lock(&station_table_lock); /* kill all children */ for(c = 0; c < SYM_TABLE_SIZE; c++) { rec = station_table.table[c]; while(rec) { kill_child(rec->data.ptr); recb = rec->next; free(rec); rec = recb; } } pthread_mutex_unlock(&station_table_lock); pthread_mutex_destroy(&station_table_lock); fclose(logfile); exit(EXIT_SUCCESS); }
void open_pid(pid_t pid) { debug(DEBUG_PROCESS, "open_pid(pid=%d)", pid); /* If we are already tracing this guy, we should be seeing all * his children via normal tracing route. */ if (pid2proc(pid) != NULL) return; /* First, see if we can attach the requested PID itself. */ if (open_one_pid(pid)) { fprintf(stderr, "Cannot attach to pid %u: %s\n", pid, strerror(errno)); trace_fail_warning(pid); return; } /* Now attach to all tasks that belong to that PID. There's a * race between process_tasks and open_one_pid. So when we * fail in open_one_pid below, we just do another round. * Chances are that by then that PID will have gone away, and * that's why we have seen the failure. The processes that we * manage to open_one_pid are stopped, so we should eventually * reach a point where process_tasks doesn't give any new * processes (because there's nobody left to produce * them). */ size_t old_ntasks = 0; int have_all; while (1) { pid_t *tasks; size_t ntasks; size_t i; if (process_tasks(pid, &tasks, &ntasks) < 0) { fprintf(stderr, "Cannot obtain tasks of pid %u: %s\n", pid, strerror(errno)); break; } have_all = 1; for (i = 0; i < ntasks; ++i) if (pid2proc(tasks[i]) == NULL && open_one_pid(tasks[i])) have_all = 0; free(tasks); if (have_all && old_ntasks == ntasks) break; old_ntasks = ntasks; } struct Process *leader = pid2proc(pid)->leader; /* XXX Is there a way to figure out whether _start has * actually already been hit? */ arch_dynlink_done(leader); /* Done. Continue everyone. */ each_task(leader, NULL, start_one_pid, NULL); }