/* * A thread function to test reparenting. Start a child wakeme_test process, * and if arg1 is > 1, create a child process that will do the same (with arg1 * decrementd. Calling this with arg1 results in 2 * arg1 processes, half of * them waiting on wake_me_q. None of them wait, so as they exit, they should * all become children of init. */ void *reparent_test(int arg1, void *arg2) { start_proc(NULL, "reparented" , wakeme_test, arg1); if ( arg1 > 1 ) start_proc(NULL, "reparent ", reparent_test, arg1-1); do_exit(0); return NULL; }
void *mzrt_thread_stub(void *data){ mzrt_thread_stub_data *stub_data = (mzrt_thread_stub_data*) data; mz_proc_thread_start start_proc = stub_data->start_proc; void *start_proc_data = stub_data->data; void* res; scheme_init_os_thread(); proc_thread_self = stub_data->thread; free(data); res = start_proc(start_proc_data); #ifdef WIN32 proc_thread_self->res = res; #endif if (!--proc_thread_self->refcount) free(proc_thread_self); scheme_done_os_thread(); return res; }
int main(int argc, char** argv){ int rx_mode = DMA_MODE,tx_mode = DMA_MODE; int recv_mode = RECEIVE_MODE; char ifname[10] = {0}, *bindstr; char rxif[128], *pif; int numproc = 4, i = 0; lib_init(); for(i=1; i<argc; i++){ if(!strncmp(argv[i], "-r", 2)){ sprintf(rxif, "%s", argv[i]+2); } } pif = rxif; sscanf(pif, "eth%d", &rx_port); sprintf(ifname, "eth%d", rx_port); sockfd = open_sock(ifname, rx_mode, tx_mode, recv_mode, numproc); if(sockfd < 0) { printf("open_sock %s failure!\n",ifname); } else { printf("open_sock %s success!\n",ifname); } bindstr = "1:2:3:4"; set_sockopt(sockfd,SET_BINDING,bindstr); start_proc(sockfd); printf("start now...\n"); while(1) { tIfStat rxstat; get_sockopt(sockfd, GET_IF_RXTX_STAT, (int *)&rxstat); //system("clear"); //write_in_file(rxstat.rx_bps, rxstat.rx_pps); db_insert(rxstat.rx_bps*8+rxstat.rx_pps*PAD_LEN*8, rxstat.rx_pps); printf("eth%d %lu bps, %u pps.\n", sockfd, rxstat.rx_bps*8+rxstat.rx_pps*PAD_LEN*8, rxstat.rx_pps); sleep(10); //system("clear"); } close_sock(sockfd); return 0; }
/** * Starts a program */ void console_start(char *dir, char *command) { memset(senddir, 0, 64); strcpy(senddir, dir); strcat(senddir, "/"); strcat(senddir, get_argument(command, 1)); // Cut the arguments from the path if(get_argument(senddir, 1)) { strncpy(senddir, senddir, strlen(senddir) - strlen(get_argument(senddir, 1)) - 1); } char *arguments = kmalloc(128); memset(arguments, 0, 128); strcpy(arguments, get_argument(command, 2)); int procn = start_proc(senddir, arguments); if(procn != PROC_STOPPED) { while(proc_state(procn) != PROC_STOPPED); remove_proc(procn); printk("\n"); } }
/* * This is the top level function for generating the tk script. */ void dump_tk_script( struct kconfig * scfg ) { int menu_depth; int menu_num [64]; int imenu, i; int top_level_num = 0; struct kconfig * cfg; struct kconfig * cfg1 = NULL; const char * name = "No Name"; /* * Mark begin and end of each menu so I can omit submenus when walking * over a parent menu. */ tot_menu_num = 0; menu_depth = 0; menu_num [0] = 0; for ( cfg = scfg; cfg != NULL; cfg = cfg->next ) { switch ( cfg->token ) { default: break; case token_mainmenu_name: name = cfg->label; break; case token_mainmenu_option: if ( ++menu_depth >= 64 ) { fprintf( stderr, "menus too deep\n" ); exit( 1 ); } if ( ++tot_menu_num >= 100 ) { fprintf( stderr, "too many menus\n" ); exit( 1 ); } menu_num [menu_depth] = tot_menu_num; menu_first [tot_menu_num] = cfg; menu_last [tot_menu_num] = cfg; /* * Note, that menu_number is set to the number of parent * (upper level) menu. */ cfg->menu_number = menu_num[menu_depth - 1]; if ( menu_depth == 1 ) ++top_level_num; break; case token_endmenu: menu_last [menu_num [menu_depth]] = cfg; /* flatten menus with proper scoping */ if ( --menu_depth < 0 ) { fprintf( stderr, "unmatched endmenu\n" ); exit( 1 ); } break; case token_bool: case token_choice_header: case token_choice_item: case token_comment: case token_dep_bool: case token_dep_tristate: case token_dep_mbool: case token_hex: case token_int: case token_string: case token_tristate: cfg->menu_number = menu_num[menu_depth]; if ( menu_depth == 0 ) { fprintf( stderr, "statement not in menu\n" ); exit( 1 ); } break; case token_define_bool: case token_define_hex: case token_define_int: case token_define_string: case token_define_tristate: case token_unset: cfg->menu_number = menu_num[menu_depth]; break; } } /* * Generate menus per column setting. * There are: * four extra buttons for save/quit/load/store; * one blank button * add two to round up for division */ printf( "set menus_per_column %d\n", (top_level_num + 4 + 1 + 2) / 3 ); printf( "set total_menus %d\n\n", tot_menu_num ); printf( "proc toplevel_menu {num} {\n" ); for ( imenu = 1; imenu <= tot_menu_num; ++imenu ) { int parent = 1; if ( menu_first[imenu]->menu_number == 0 ) parent = menu_first[imenu]->menu_number; else printf( "\tif {$num == %d} then {return %d}\n", imenu, menu_first[imenu]->menu_number ); } printf( "\treturn $num\n}\n\n" ); /* * Generate the menus. */ printf( "mainmenu_name \"%s\"\n", name ); for ( imenu = 1; imenu <= tot_menu_num; ++imenu ) { int menu_line = 0; int nr_submenu = imenu; int menu_name_omitted = 0; int opt_count = 0; clear_globalflags(); start_proc( menu_first[imenu]->label, imenu, !menu_first[imenu]->menu_number ); for ( cfg = menu_first[imenu]->next; cfg != NULL && cfg != menu_last[imenu]; cfg = cfg->next ) { switch ( cfg->token ) { default: break; case token_mainmenu_option: while ( menu_first[++nr_submenu]->menu_number > imenu ) ; cfg->menu_line = menu_line++; printf( "\tsubmenu $w.config.f %d %d \"%s\" %d\n", cfg->menu_number, cfg->menu_line, cfg->label, nr_submenu ); cfg = menu_last[nr_submenu]; break; case token_comment: if ( !cfg->menu_line && !menu_name_omitted ) { cfg->menu_line = -1; menu_name_omitted = 1; } else { menu_name_omitted = 1; cfg->menu_line = menu_line++; printf( "\tcomment $w.config.f %d %d \"%s\"\n", cfg->menu_number, cfg->menu_line, cfg->label ); } break; case token_bool: cfg->menu_line = menu_line++; printf( "\tbool $w.config.f %d %d \"%s\" %s\n", cfg->menu_number, cfg->menu_line, cfg->label, vartable[cfg->nameindex].name ); break; case token_choice_header: /* * I need the first token_choice_item to pick out the right * help text from Documentation/Configure.help. */ cfg->menu_line = menu_line++; printf( "\tglobal tmpvar_%d\n", -(cfg->nameindex) ); printf( "\tminimenu $w.config.f %d %d \"%s\" tmpvar_%d %s\n", cfg->menu_number, cfg->menu_line, cfg->label, -(cfg->nameindex), vartable[cfg->next->nameindex].name ); printf( "\tmenu $w.config.f.x%d.x.menu -tearoffcommand \"menutitle \\\"%s\\\"\"\n", cfg->menu_line, cfg->label ); cfg1 = cfg; opt_count = 0; break; case token_choice_item: /* note: no menu line; uses choice header menu line */ printf( "\t$w.config.f.x%d.x.menu add radiobutton -label \"%s\" -variable tmpvar_%d -value \"%s\" -command \"update_active\"\n", cfg1->menu_line, cfg->label, -(cfg1->nameindex), cfg->label ); opt_count++; if ( cfg->next && cfg->next->token != token_choice_item ) { /* last option in the menu */ printf( "\tmenusplit $w $w.config.f.x%d.x.menu %d\n", cfg1->menu_line, opt_count ); } break; case token_dep_bool: case token_dep_mbool: cfg->menu_line = menu_line++; printf( "\tdep_bool $w.config.f %d %d \"%s\" %s\n", cfg->menu_number, cfg->menu_line, cfg->label, vartable[cfg->nameindex].name ); break; case token_dep_tristate: cfg->menu_line = menu_line++; printf( "\tdep_tristate $w.config.f %d %d \"%s\" %s\n", cfg->menu_number, cfg->menu_line, cfg->label, vartable[cfg->nameindex].name ); break; case token_hex: cfg->menu_line = menu_line++; printf( "\thex $w.config.f %d %d \"%s\" %s\n", cfg->menu_number, cfg->menu_line, cfg->label, vartable[cfg->nameindex].name ); break; case token_int: cfg->menu_line = menu_line++; printf( "\tint $w.config.f %d %d \"%s\" %s\n", cfg->menu_number, cfg->menu_line, cfg->label, vartable[cfg->nameindex].name ); break; case token_string: cfg->menu_line = menu_line++; printf( "\tistring $w.config.f %d %d \"%s\" %s\n", cfg->menu_number, cfg->menu_line, cfg->label, vartable[cfg->nameindex].name ); break; case token_tristate: cfg->menu_line = menu_line++; printf( "\ttristate $w.config.f %d %d \"%s\" %s\n", cfg->menu_number, cfg->menu_line, cfg->label, vartable[cfg->nameindex].name ); break; } } end_proc( scfg, imenu ); } /* * The top level menu also needs an update function. When we update a * submenu, we may need to disable one or more of the submenus on * the top level menu, and this procedure will ensure that things are * correct. */ clear_globalflags(); printf( "proc update_mainmenu {} {\n" ); for ( imenu = 1; imenu <= tot_menu_num; imenu++ ) { if ( menu_first[imenu]->cond != NULL && menu_first[imenu]->menu_number == 0 ) generate_if( menu_first[imenu], menu_first[imenu]->cond, imenu, -1 ); } printf( "}\n\n\n" ); clear_globalflags(); /* * Generate code to load the default settings into the variables. * The script in tail.tk will attempt to load .config, * which may override these settings, but that's OK. */ for ( cfg = scfg; cfg != NULL; cfg = cfg->next ) { switch ( cfg->token ) { default: break; case token_bool: case token_choice_item: case token_dep_bool: case token_dep_tristate: case token_dep_mbool: case token_tristate: if ( ! vartable[cfg->nameindex].global_written ) { printf( "set %s 0\n", vartable[cfg->nameindex].name ); vartable[cfg->nameindex].global_written = 1; } break; case token_choice_header: printf( "set tmpvar_%d \"(not set)\"\n", -(cfg->nameindex) ); break; case token_hex: case token_int: if ( ! vartable[cfg->nameindex].global_written ) { printf( "set %s %s\n", vartable[cfg->nameindex].name, cfg->value ? cfg->value : "0" ); vartable[cfg->nameindex].global_written = 1; } break; case token_string: if ( ! vartable[cfg->nameindex].global_written ) { printf( "set %s \"%s\"\n", vartable[cfg->nameindex].name, cfg->value ); vartable[cfg->nameindex].global_written = 1; } break; } } /* * Define to an empty value all other variables (which are never defined) */ for ( i = 1; i <= max_varnum; i++ ) { if ( ! vartable[i].global_written && strncmp( vartable[i].name, "CONSTANT_", 9 ) ) printf( "set %s 4\n", vartable[i].name ); } /* * Generate a function to write all of the variables to a file. */ printf( "proc writeconfig {file1 file2} {\n" ); printf( "\tset cfg [open $file1 w]\n" ); printf( "\tset autocfg [open $file2 w]\n" ); printf( "\tset notmod 1\n" ); printf( "\tset notset 0\n" ); printf( "\tputs $cfg \"#\"\n"); printf( "\tputs $cfg \"# Automatically generated make config: don't edit\"\n"); printf( "\tputs $cfg \"#\"\n" ); printf( "\tputs $autocfg \"/*\"\n" ); printf( "\tputs $autocfg \" * Automatically generated C config: don't edit\"\n" ); printf( "\tputs $autocfg \" */\"\n" ); printf( "\tputs $autocfg \"#define AUTOCONF_INCLUDED\"\n" ); clear_globalflags(); for ( cfg = scfg; cfg != NULL; cfg = cfg->next ) { switch ( cfg->token ) { default: break; case token_bool: case token_choice_header: case token_comment: case token_define_bool: case token_define_hex: case token_define_int: case token_define_string: case token_define_tristate: case token_dep_bool: case token_dep_tristate: case token_dep_mbool: case token_hex: case token_int: case token_string: case token_tristate: generate_writeconfig( cfg ); break; } } printf( "\tclose $cfg\n" ); printf( "\tclose $autocfg\n" ); printf( "}\n\n\n" ); /* * Generate a simple function that updates the master choice * variable depending upon what values were loaded from a .config * file. */ printf( "proc clear_choices { } {\n" ); for ( cfg = scfg; cfg != NULL; cfg = cfg->next ) { if ( cfg->token == token_choice_header ) { for ( cfg1 = cfg->next; cfg1 != NULL && cfg1->token == token_choice_item; cfg1 = cfg1->next ) { printf( "\tglobal %s; set %s 0\n", vartable[cfg1->nameindex].name, vartable[cfg1->nameindex].name ); } } } printf( "}\n\n\n" ); printf( "proc update_choices { } {\n" ); for ( cfg = scfg; cfg != NULL; cfg = cfg->next ) { if ( cfg->token == token_choice_header ) { printf( "\tglobal tmpvar_%d\n", -(cfg->nameindex) ); printf("\tset tmpvar_%d \"%s\"\n", -(cfg->nameindex), cfg->value); for ( cfg1 = cfg->next; cfg1 != NULL && cfg1->token == token_choice_item; cfg1 = cfg1->next ) { printf( "\tglobal %s\n", vartable[cfg1->nameindex].name ); printf( "\tif { $%s == 1 } then { set tmpvar_%d \"%s\" }\n", vartable[cfg1->nameindex].name, -(cfg->nameindex), cfg1->label ); } } } printf( "}\n\n\n" ); generate_update_var( scfg, 0 ); /* * That's it. We are done. The output of this file will have header.tk * prepended and tail.tk appended to create an executable wish script. */ }
/** * Wrapper around user thread start proc. * Used to perform some duty jobs right after thread is started * and before thread is finished. */ static int HYTHREAD_PROC hythread_wrapper_start_proc(void *arg) { IDATA UNUSED status; hythread_t thread; hythread_start_proc_data start_proc_data; hythread_entrypoint_t start_proc; // store procedure arguments to local start_proc_data = *(hythread_start_proc_data_t) arg; free(arg); // get hythread global lock status = hythread_global_lock(); assert(status == TM_ERROR_NONE); // get native thread thread = start_proc_data.thread; start_proc = start_proc_data.proc; CTRACE(("TM: native thread started: native: %p tm: %p", port_thread_current(), thread)); // check hythread library state if (hythread_lib_state() != TM_LIBRARY_STATUS_INITIALIZED) { // set TERMINATED state port_mutex_lock(&thread->mutex); thread->state = TM_THREAD_STATE_TERMINATED; port_mutex_unlock(&thread->mutex); // set hythread_self() hythread_set_self(thread); assert(thread == hythread_self()); // release thread structure data hythread_detach(thread); // zero hythread_self() because we don't do it in hythread_detach_ex() hythread_set_self(NULL); CTRACE(("TM: native thread terminated due to shutdown: native: %p tm: %p", port_thread_current(), thread)); // release hythread global lock status = hythread_global_unlock(); assert(status == TM_ERROR_NONE); return 0; } // register to group and set ALIVE & RUNNABLE states status = hythread_set_to_group(thread, start_proc_data.group); assert(status == TM_ERROR_NONE); // set hythread_self() hythread_set_self(thread); assert(thread == hythread_self()); // set priority status = hythread_set_priority(thread, thread->priority); // FIXME - cannot set priority //assert(status == TM_ERROR_NONE); // release hythread global lock status = hythread_global_unlock(); assert(status == TM_ERROR_NONE); // Do actual call of the thread body supplied by the user. start_proc(start_proc_data.proc_args); assert(hythread_is_suspend_enabled()); // get hythread global lock status = hythread_global_lock(); assert(status == TM_ERROR_NONE); // set TERMINATED state port_mutex_lock(&thread->mutex); thread->state = TM_THREAD_STATE_TERMINATED; port_mutex_unlock(&thread->mutex); // detach and free thread hythread_detach(thread); // release hythread global lock status = hythread_global_unlock(); assert(status == TM_ERROR_NONE); return 0; }
void *student_tests(int arg1, void *arg2) { kmutex_init(&mutex); kmutex_init(&reader_mutex); kmutex_init(&writer_mutex); /* Student Test 1 */ int rv = 0; int i = 0; dbg_print("broadcast order test"); race2 = 0; for (i = 0; i < 10; i++ ) start_proc("broadcast order test", broadcast_order, 0); stop_until_queued(10, &wake_me_len2); race2 = 0; sched_broadcast_on(&wake_me_q); wait_for_all(); KASSERT(wake_me_len2 == 0 && "Error on wakeme bookkeeping"); /* Student Test 2 */ int checkVal = 0; dbg_print("reader writer test"); start_proc("reader writer test", reader, 0); start_proc("reader writer test", reader, 0); start_proc("reader writer test", writer, 0); checkVal++; start_proc("reader writer test", reader, 1); start_proc("reader writer test", reader, 1); start_proc("reader writer test", reader, 1); start_proc("reader writer test", writer, 0); checkVal++; start_proc("reader writer test", writer, 0); checkVal++; start_proc("reader writer test", reader, 3); start_proc("reader writer test", reader, 3); wait_for_all(); KASSERT(checkVal == rwval && "Error in Reader Writer!"); return NULL; }
/* The core testproc code */ void *testproc(int arg1, void *arg2) { proc_thread_t pt; pid_t pid = -1; int rv = 0; int i = 0; #if CS402TESTS > 0 dbg_print("waitpid any test"); start_proc(&pt, "waitpid any test", waitpid_test, 23); wait_for_any(); dbg_print("waitpid test"); start_proc(&pt, "waitpid test", waitpid_test, 32); pid = do_waitpid(2323, 0, &rv); if ( pid != -ECHILD ) dbg_print("Allowed wait on non-existent pid\n"); wait_for_proc(pt.p); /* dbg_print("kthread exit test"); start_proc(&pt, "kthread exit test", kthread_exit_test, 0); wait_for_proc(pt.p); */ /* dbg_print("many test"); for (i = 0; i < 10; i++) start_proc(NULL, "many test", waitpid_test, i); wait_for_all();a */ #endif #if CS402TESTS > 1 dbg_print("Context switch test"); start_proc(&pt, "Context switch", racer_test, 0); wait_for_proc(pt.p); #endif #if CS402TESTS > 2 sched_queue_init(&wake_me_q); dbg_print("wake me test"); wake_me_len = 0; start_proc(&pt, "wake me test", wakeme_test, 0); /* Make sure p has blocked */ stop_until_queued(1, &wake_me_len); sched_wakeup_on(&wake_me_q); wait_for_proc(pt.p); KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping"); dbg_print("broadcast me test"); for (i = 0; i < 10; i++ ) start_proc(NULL, "broadcast me test", wakeme_test, 0); stop_until_queued(10, &wake_me_len); /* Make sure the processes have blocked */ sched_broadcast_on(&wake_me_q); wait_for_all(); KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping"); #endif #if CS402TESTS > 3 dbg_print("wake me uncancellable test"); start_proc(&pt, "wake me uncancellable test", wakeme_uncancellable_test, 0); /* Make sure p has blocked */ stop_until_queued(1, &wake_me_len); sched_wakeup_on(&wake_me_q); wait_for_proc(pt.p); KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping"); dbg_print("broadcast me uncancellable test"); for (i = 0; i < 10; i++ ) start_proc(NULL, "broadcast me uncancellable test", wakeme_uncancellable_test, 0); /* Make sure the processes have blocked */ stop_until_queued(10, &wake_me_len); sched_broadcast_on(&wake_me_q); wait_for_all(); KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping"); #endif #if CS402TESTS > 4 dbg_print("cancel me test"); start_proc(&pt, "cancel me test", cancelme_test, 0); /* Make sure p has blocked */ stop_until_queued(1, &wake_me_len); sched_cancel(pt.t); wait_for_proc(pt.p); KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping"); dbg_print("prior cancel me test"); start_proc(&pt, "prior cancel me test", cancelme_test, 0); /* Cancel before sleep */ sched_cancel(pt.t); wait_for_proc(pt.p); KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping"); dbg_print("cancel me head test"); start_proc(&pt, "cancel me head test", cancelme_test, 0); start_proc(NULL, "cancel me head test", wakeme_test, 0); stop_until_queued(2, &wake_me_len); sched_cancel(pt.t); sched_wakeup_on(&wake_me_q); wait_for_all(); KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping"); dbg_print("cancel me tail test"); start_proc(NULL, "cancel me tail test", wakeme_test, 0); start_proc(&pt, "cancel me tail test", cancelme_test, 0); stop_until_queued(2, &wake_me_len); sched_cancel(pt.t); sched_wakeup_on(&wake_me_q); wait_for_all(); KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping"); #endif #if CS402TESTS > 5 dbg_print("Reparenting test"); start_proc(NULL, "Reparenting test", reparent_test, 1); stop_until_queued(1, &wake_me_len); sched_wakeup_on(&wake_me_q); wait_for_all(); stop_until_zero(&wake_me_len); dbg_print("Reparenting stress test"); start_proc(NULL, "Reparenting stress test", reparent_test, 10); stop_until_queued(10, &wake_me_len); sched_broadcast_on(&wake_me_q); wait_for_all(); stop_until_zero(&wake_me_len); KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping"); #endif #if CS402TESTS > 6 kmutex_init(&mutex); dbg_print("show race test"); race = 0; for (i = 0; i < 10; i++ ) start_proc(NULL, "show race test", racer_test, 0); wait_for_all(); dbg_print("fix race test"); race = 0; for (i = 0; i < 10; i++ ) start_proc(NULL, "fix race test", mutex_uncancellable_test, 0); wait_for_all(); dbg_print("fix race test w/cancel"); race = 0; for (i = 0; i < 10; i++ ) { if ( i % 2 == 0) { start_proc(NULL, "fix race test w/cancel", mutex_test, 0); } else { start_proc(&pt, "fix race test w/cancel", mutex_test_cancelme, 0); sched_cancel(pt.t); } } wait_for_all(); #endif #if CS402TESTS > 7 dbg_print("kill all test"); for ( i=0 ; i < 10; i++ ) start_proc(NULL, "kill all test", cancelme_test, 0); stop_until_queued(10, &wake_me_len); proc_kill_all(); wait_for_all(); KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping"); #endif #if CS402TESTS > 8 student_tests(arg1, arg2); #endif dbg_print("All tests completed\n\n"); return NULL; }