int srs_st_init() { int ret = ERROR_SUCCESS; #ifdef __linux__ // check epoll, some old linux donot support epoll. // @see https://github.com/simple-rtmp-server/srs/issues/162 if (!srs_st_epoll_is_supported()) { ret = ERROR_ST_SET_EPOLL; srs_error("epoll required on Linux. ret=%d", ret); return ret; } #endif // Select the best event system available on the OS. In Linux this is // epoll(). On BSD it will be kqueue. if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) { ret = ERROR_ST_SET_EPOLL; srs_error("st_set_eventsys use %s failed. ret=%d", st_get_eventsys_name(), ret); return ret; } srs_trace("st_set_eventsys to %s", st_get_eventsys_name()); if(st_init() != 0) { ret = ERROR_ST_INITIALIZE; srs_error("st_init failed. ret=%d", ret); return ret; } srs_trace("st_init success, use %s", st_get_eventsys_name()); return ret; }
int st_type_align_get(enum st_type type) { st_init(); if (type >= st_type_start && type < st_type_end) return st_type_align[type]; return -1; }
int main() { int fd, rc; int one = 1; //signal(SIGPIPE, SIG_IGN); also done by st_init() st_init(); fd = socket(PF_INET, SOCK_STREAM, 0); if(fd < 0) { perror("socket"); exit(1); } rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one)); if(rc < 0) perror("setsockopt(SO_REUSEADDR)"); memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(port); rc = bind(fd, (struct sockaddr*)&addr, sizeof(addr)); if(rc < 0) { perror("bind"); exit(1); } rc = listen(fd, 1024); if(rc < 0) { perror("listen"); exit(1); } accept_connection(fd); return 0; }
bool trace_init_backends(const char *events, const char *file) { #ifdef CONFIG_TRACE_SIMPLE if (!st_init(file)) { fprintf(stderr, "failed to initialize simple tracing backend.\n"); return false; } #else if (file) { fprintf(stderr, "error: -trace file=...: " "option not supported by the selected tracing backends\n"); return false; } #endif #ifdef CONFIG_TRACE_FTRACE if (!ftrace_init()) { fprintf(stderr, "failed to initialize ftrace backend.\n"); return false; } #endif trace_init_events(events); return true; }
int main() { st_thread_t thread; int rc; int i, j, s; arg = -1; res = -1; st_init(); for(i = 0; i < 10; i++) { s = 0; for(j = 0; j < 10000; j++) { res = -1; arg = j; thread = st_thread_create(thread_routine, NULL, 1, 0); st_sleep(0); while(res < 0) st_sleep(0); s += res; st_thread_join(thread, NULL); arg = -1; } } printf("%d\n", s); return 0; }
void Config_ResetDefault() { float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT; float tmp2[]=DEFAULT_MAX_FEEDRATE; long tmp3[]=DEFAULT_MAX_ACCELERATION; long tmp4[]=DEFAULT_DIGIPOT_MOTOR_CURRENT; for (short i=0;i<4;i++) { axis_steps_per_unit[i]=tmp1[i]; max_feedrate[i]=tmp2[i]; max_acceleration_units_per_sq_second[i]=tmp3[i]; digipot_motor_current[i]=tmp4[i]; } // steps per sq second need to be updated to agree with the units per sq second reset_acceleration_rates(); acceleration=DEFAULT_ACCELERATION; retract_acceleration=DEFAULT_RETRACT_ACCELERATION; minimumfeedrate=DEFAULT_MINIMUMFEEDRATE; minsegmenttime=DEFAULT_MINSEGMENTTIME; mintravelfeedrate=DEFAULT_MINTRAVELFEEDRATE; max_xy_jerk=DEFAULT_XYJERK; max_z_jerk=DEFAULT_ZJERK; max_e_jerk=DEFAULT_EJERK; add_homeing[0] = add_homeing[1] = add_homeing[2] = 0; #ifdef DELTA endstop_adj[0] = endstop_adj[1] = endstop_adj[2] = 0; #endif #ifdef ULTIPANEL plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP; plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP; plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED; absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP; absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP; absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED; #endif #ifdef DOGLCD lcd_contrast = DEFAULT_LCD_CONTRAST; #endif #ifdef PIDTEMP Kp = DEFAULT_Kp; Ki = scalePID_i(DEFAULT_Ki); Kd = scalePID_d(DEFAULT_Kd); // call updatePID (similar to when we have processed M301) updatePID(); st_init(); #ifdef PID_ADD_EXTRUSION_RATE Kc = DEFAULT_Kc; #endif//PID_ADD_EXTRUSION_RATE #endif//PIDTEMP zprobe_offset=DEFAULT_Z_PROBE_OFFSET_FROM_EXTRUDER; SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded"); }
int srs_init_st() { int ret = ERROR_SUCCESS; // check epoll, some old linux donot support epoll. // @see https://github.com/simple-rtmp-server/srs/issues/162 if (!srs_st_epoll_is_supported()) { ret = ERROR_ST_SET_EPOLL; srs_error("epoll required. ret=%d", ret); return ret; } // use linux epoll. if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) { ret = ERROR_ST_SET_EPOLL; srs_error("st_set_eventsys use linux epoll failed. ret=%d", ret); return ret; } srs_verbose("st_set_eventsys use linux epoll success"); if(st_init() != 0){ ret = ERROR_ST_INITIALIZE; srs_error("st_init failed. ret=%d", ret); return ret; } srs_verbose("st_init success"); return ret; }
int main(void) { size_t max = 100; size_t n = 20; char buf[strsiz]; size_t i; st_t st = st_init(max); for (i = 0; i < n; i++) { item_t t = newitem(randkey(), randstr(buf, strsiz)); st_insert(st, t); } st_sort(st, print); printf("\nThe item with key 11 is: "); print(st_search(st, 11)); printf("\nThe 4th smallest key is: "); print(st_select(st, 4)); st_delete(st, st_search(st, 11)); printf("\n delete the item with key 11.\n"); st_sort(st, print); /* delete all item */ while (!st_empty(st)) { item_t x = st_select(st, 0); printf("delete item: "); print(x); st_delete(st, st_select(st, 0)); } st_finalize(&st); return 0; }
/* * Asynchronous DNS host name resolution. This program creates one * ST thread for each host name (specified as command line arguments). * All threads do host name resolution concurrently. */ int main(int argc, char *argv[]) { int i; if (argc < 2) { fprintf(stderr, "Usage: %s <hostname1> [<hostname2>] ...\n", argv[0]); exit(1); } if (st_init() < 0) { perror("st_init"); exit(1); } for (i = 1; i < argc; i++) { /* Create a separate thread for each host name */ if (st_thread_create(do_resolve, argv[i], 0, 0) == NULL) { perror("st_thread_create"); exit(1); } } st_thread_exit(NULL); /* NOTREACHED */ return 1; }
int main() { int intArray[MAX_ARR_SIZE]; int numElm = 0; int result = 0; int choice, rc; StackType stack; st_init(&stack); //initialize the stack rc = getArrayData(intArray, &numElm); if (rc < 0) exit(1); printf("\nHow would like to sum the elements?\n"); printf(" (1) iteratively\n"); printf(" (2) recursively\n"); scanf("%d", &choice); switch (choice) { case 1: sumIterative(numElm, intArray, &result, &stack); printf("Sum is %d\n", result); break; case 2: sumRecursive(numElm, intArray, &result, &stack); printf("Sum is %d\n", result); } return 0; }
int SrsServer::initialize_st() { int ret = ERROR_SUCCESS; // use linux epoll. if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) { ret = ERROR_ST_SET_EPOLL; srs_error("st_set_eventsys use linux epoll failed. ret=%d", ret); return ret; } srs_verbose("st_set_eventsys use linux epoll success"); if(st_init() != 0){ ret = ERROR_ST_INITIALIZE; srs_error("st_init failed. ret=%d", ret); return ret; } srs_verbose("st_init success"); // set current log id. _srs_context->generate_id(); srs_info("log set id success"); return ret; }
void names_init(struct name_list *l) { st_init(&l->taken); l->prefix = ptrarray_create(); l->first = ptrarray_create(); l->second = ptrarray_create(); l->suffix = ptrarray_create(); }
int main(int argc,char **argv) { // Initialise StateThreads BEFORE the fork: st_init(); // THEN the SQLite subsystem AFTER forking: return 0; }
main(){ //initialize the ST library runtime, necessary for up() and down() st_init(); /* BoundedBuffer readInput; createBuffer(&readInput, MAX_BUFF_SIZE); */ int theBufferSize = MAX_BUFF_SIZE; semaphore fullSem; createSem(&fullSem, 0); //0 full buffers semaphore emptySem; createSem(&emptySem, MAX_BUFF_SIZE); //n empty buffers char theBuffer[MAX_BUFF_SIZE]; BoundedBuffer theBoundedBuffer = { &theBufferSize, &fullSem, &emptySem, theBuffer }; //have to derefernce the bufferSize pointer printf("Buffer Size: %d\n", (*theBoundedBuffer.bufferSize)); int i; for(i = 0; i < 10; i++){ up(theBoundedBuffer.fullBuffers); } for(i = 0; i < 6; i++){ down(theBoundedBuffer.emptyBuffers); } /* int i; for(i = 0; i < MAX_BUFF_SIZE; i++){ up(&readInput.emptyBuffers); emptyBuffersVal++; } for (i = 0; i < MAX_BUFF_SIZE; i++){ down(&readInput.emptyBuffers); emptyBuffersVal--; } */ //buffDeposit(&readInput); //buffRemove(&readInput); }
int main(int argc, char *argv[]) { g_assert(st_set_eventsys(ST_EVENTSYS_ALT) == 0); st_init(); int status = ares_library_init(ARES_LIB_INIT_ALL); if (status != ARES_SUCCESS) { fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status)); return 1; } int sock; int n; struct sockaddr_in serv_addr; if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { perror("socket"); } n = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof(n)) < 0) { perror("setsockopt SO_REUSEADDR"); } memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(8080); serv_addr.sin_addr.s_addr = inet_addr("0.0.0.0"); if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { perror("bind"); } if (listen(sock, 10) < 0) { perror("listen"); } st_netfd_t server_nfd = st_netfd_open_socket(sock); st_netfd_t client_nfd; struct sockaddr_in from; int fromlen = sizeof(from); for (;;) { client_nfd = st_accept(server_nfd, (struct sockaddr *)&from, &fromlen, ST_UTIME_NO_TIMEOUT); printf("accepted\n"); if (st_thread_create(handle_connection, (void *)client_nfd, 0, 1024 * 1024) == NULL) { fprintf(stderr, "st_thread_create error\n"); } } ares_library_cleanup(); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { init(); if(init_setting() != 0){ print_errmsg("ERROR: SETTING init fail. \n"); return 1; } if(gc_init() != 0){ print_errmsg("ERROR: G_CODE init fail. \n"); return 1; } if (cm_init() == false) { print_errmsg("ERROR: USB-DEV init fail. \n"); return 1; } if (cmd_init() == false) { print_errmsg("ERROR: G code init fail.\n"); cm_close(); return 1; } if (tp_init() == false) { print_errmsg("ERROR: Temperature library init fail. \n"); cmd_close(); cm_close(); return 1; } plan_init(); Config_ResetDefault(); st_init(); while(1) { LCD(10UL); getCommand(10UL); process_commands(50UL); stepper(1000L); manageHeater(10UL); } st_close(); plan_close(); tp_close(); cmd_close(); cm_close(); //debug //sfp_close(); return 0; }
int main (int argc, const char * argv[]) { thread_Producer_Consumer_init inputProcessing_init; thread_Producer_Consumer_init carriageToSpace_init; thread_Producer_Consumer_init starsToCaret_init; thread_Producer_Consumer_init outputProcessing_init; if (st_init()<0) { perror("st_init"); exit(1); } circularBuffer buf1, buf2, buf3; newBuffer(&buf1, BUFFER_SIZE); //for buffer inputProcessing & carriageToSpace newBuffer(&buf2, BUFFER_SIZE); //for buffer carriageToSpace & starsToCaret newBuffer(&buf3, BUFFER_SIZE); //for buffer starsToCaret & outputProcessing inputProcessing_init.buffer_C = NULL; inputProcessing_init.buffer_P = &buf1; carriageToSpace_init.buffer_C = &buf1; carriageToSpace_init.buffer_P = &buf2; starsToCaret_init.buffer_C = &buf2; starsToCaret_init.buffer_P = &buf3; outputProcessing_init.buffer_C = &buf3; outputProcessing_init.buffer_P = NULL; if (st_thread_create(inputProcessing, &inputProcessing_init, 0, 0)==NULL) { perror("st_thread_create \n"); exit(1); } if (st_thread_create(carriageToSpace, &carriageToSpace_init, 0, 0)==NULL) { perror("st_thread_create \n"); exit(1); } if (st_thread_create(starsToCaret, &starsToCaret_init, 0, 0)==NULL) { perror("st_thread_create \n"); exit(1); } if (st_thread_create(outputProcessing, &outputProcessing_init, 0, 0)==NULL) { perror("st_thread_create \n"); exit(1); } printf("Hello World~~~~~~\n"); fflush(stdout); st_thread_exit(NULL); return 0; }
void ums_init() { st_init(); umsEnabled = 0; commandCounter = 0; previousLimits = 0; nextStatusTime = UMS_STATUS_INTERVAL; umsLimits = 0; umsRunTime = 0; umsStatus = 0; umsXPos = umsYPos = umsZPos = umsUPos = 0; }
/** Initialize the lock strtree. */ void init_locks(void) { lock_list *ll; st_init(&lock_names, "LockNameTree"); hashinit(&htab_locks, 25); for (ll = lock_types; ll->type && *ll->type; ll++) hashadd(strupper(ll->type), ll, &htab_locks); local_locks(); }
/* * General server example: accept a client connection and do something. * This program just outputs a short HTML page, but can be easily adapted * to do other things. * * This server creates a constant number of processes ("virtual processors" * or VPs) and replaces them when they die. Each virtual processor manages * its own independent set of state threads (STs), the number of which varies * with load against the server. Each state thread listens to exactly one * listening socket. The initial process becomes the watchdog, waiting for * children (VPs) to die or for a signal requesting termination or restart. * Upon receiving a restart signal (SIGHUP), all VPs close and then reopen * log files and reload configuration. All currently active connections remain * active. It is assumed that new configuration affects only request * processing and not the general server parameters such as number of VPs, * thread limits, bind addresses, etc. Those are specified as command line * arguments, so the server has to be stopped and then started again in order * to change them. * * Each state thread loops processing connections from a single listening * socket. Only one ST runs on a VP at a time, and VPs do not share memory, * so no mutual exclusion locking is necessary on any data, and the entire * server is free to use all the static variables and non-reentrant library * functions it wants, greatly simplifying programming and debugging and * increasing performance (for example, it is safe to ++ and -- all global * counters or call inet_ntoa(3) without any mutexes). The current thread on * each VP maintains equilibrium on that VP, starting a new thread or * terminating itself if the number of spare threads exceeds the lower or * upper limit. * * All I/O operations on sockets must use the State Thread library's I/O * functions because only those functions prevent blocking of the entire VP * process and perform state thread scheduling. */ int main(int argc, char *argv[]) { /* Parse command-line options */ parse_arguments(argc, argv); /* Allocate array of server pids */ if ((vp_pids = calloc(vp_count, sizeof(pid_t))) == NULL) err_sys_quit(errfd, "ERROR: calloc failed"); /* Start the daemon */ if (!interactive_mode) start_daemon(); /* Initialize the ST library */ if (st_init() < 0) err_sys_quit(errfd, "ERROR: initialization failed: st_init"); /* Set thread throttling parameters */ set_thread_throttling(); /* Create listening sockets */ create_listeners(); /* Change the user */ if (username) change_user(); /* Open log files */ open_log_files(); /* Start server processes (VPs) */ start_processes(); /* Turn time caching on */ st_timecache_set(1); /* Install signal handlers */ install_sighandlers(); /* Load configuration from config files */ load_configs(); /* Start all threads */ start_threads(); /* Become a signal processing thread */ process_signals(NULL); /* NOTREACHED */ return 1; }
/** *** LaosMotion() Constructor *** Make new motion object **/ LaosMotion::LaosMotion() { extern GlobalConfig *cfg; #if DO_MOTION_TEST tActionRequest act[2]; int i=0; Timer t; #endif pwm.period(1.0 / cfg->pwmfreq); pwm = cfg->pwmmin/100.0; if ( laser == NULL ) laser = new DigitalOut(LASER_PIN); *laser = LASEROFF; mark_speed = cfg->speed; //start.mode(PullUp); xhome.mode(PullUp); yhome.mode(PullUp); isHome = false; plan_init(); st_init(); reset(); mark_speed = cfg->speed; bitmap_speed = cfg->xspeed; action.param = 0; action.target.x = action.target.y = action.target.z = action.target.e =0; action.target.feed_rate = 60*mark_speed; #if DO_MOTION_TEST t.start(); act[0].ActionType = act[1].ActionType = AT_MOVE; act[0].target.feed_rate = 60 * 100; act[1].target.feed_rate = 60 * 200; act[0].target.x = act[0].target.y = act[0].target.z = act[0].target.e = 0; act[1].target.x = act[1].target.y = act[1].target.z = act[1].target.e = 100; act[1].target.y = 200; while(1) { while( plan_queue_full() ) led3 = !led3; led1 = 1; i++; if ( i ) printf("%d PING...\n", t.read_ms()); else printf("%d PONG...\n", t.read_ms()); if ( i > 1 || i<0) i = 0; plan_buffer_line (&act[i]); led1 = 0; } #endif }
env_t *env_init(void) { env_t *env; node_t *node; node = (node_t *)util_malloc(sizeof(node_t)); node->st = st_init(); node->next = NULL; env = (env_t *)util_malloc(sizeof(env_t)); env->head = node; return env; }
int main() { int n; st_thread_t thread; st_init(); n = 0; thread = st_thread_create(thread_routine, NULL, 1, 4096); inc_n(); while(1) st_sleep(1); return 0; }
int main(void) { sp_init(); settings_init(); plan_init(); st_init(); spindle_init(); gc_init(); for (;;) { sleep_mode(); // Wait for it ... sp_process(); // ... process the serial protocol } return 0; /* never reached */ }
void st_calc_begin(pst_calc calc, int pack /*= 0*/) { st_init(); if (calc){ calc->pack = 0; calc->offset = 0; calc->size = 0; calc->nosizearray = 0; if (pack > 0 && 1 == bitcount32(pack)) calc->pack = pack; else calc->pack = st_pack_default; } }
// creates two threads using ST, one of which increments a shared counter, // and one of which decrements it. The counter's value is printed to stdout // after each operation. After a certain number of operations the program // terminates. int main (int argc, char const *argv[]) { // initialize the ST library runtime st_init(); // store an arbitrary integer int value = 0; // create a binary semaphore initialized to 1 semaphore bin_sem; createSem(&bin_sem, 1); // which output stream to use FILE *output = DEFAULT_OUT; // create our init data struct ThreadInit thread_init = { output, &bin_sem, &value }; //JSR int semValue = 1; int i; for (i = 0; i < 5; i++){ semValue++; up(thread_init.bin_sem); printf("semValue= %d\n", semValue); } /* // create the increment thread if (st_thread_create(increment_thread_func, &thread_init, 0, 0) == NULL) { perror("st_thread_create for increment thread failure"); exit(1); } // create the decrement thread if (st_thread_create(decrement_thread_func, &thread_init, 0, 0) == NULL) { perror("st_thread_create for decrement thread failure"); exit(1); } */ // main thread exits st_thread_exit(NULL); return 0; }
/* * Asynchronous DNS host name resolution. This program creates one * ST thread for each host name (specified as command line arguments). * All threads do host name resolution concurrently. */ int main(int argc, char *argv[]) { if (st_init() < 0) { perror("st_init"); exit(1); } condition = st_cond_new(); mutex = st_mutex_new(); int maxQueueP = 15; int maxQueueC = 10; st_thread_t p[6],c[6]; int i = 0; for (; i < maxQueueP; ++i) { if ( (p[i] = st_thread_create(producer,i,1,0) ) == NULL) { perror("st_thread_create producer failed"); exit(1); } } i = 0; for (; i < maxQueueC; ++i) { if ( (c[i] = st_thread_create(consumer,i,1,0) ) == NULL) { perror("st_thread_create consumer failed"); exit(1); } } i = 0; for (; i < maxQueueP; ++i) { st_thread_join(p[i],0); } i = 0; for (; i < maxQueueC; ++i) { st_thread_join(c[i],0); } /* NOTREACHED */ return 1; }
void ft_init_incantation(t_env *env) { int i; i = 0; env->incantation = NULL; if (!(env->incantation = (int **)malloc(sizeof(int *) * NB_LEVEL))) ft_exit("incation init fail."); while (i < NB_LEVEL) { if (!(env->incantation[i] = (int *)malloc(sizeof(int) * NB_STUFF))) ft_exit("incation init fail."); i++; } st_init(env); }
int main() { char line[256]; char *p; char c; char t; int v; int i = 0; int number = 0; st_init(); printf("INPUT: "); gets(line); p = line; while( (c=*p) != 0 && c!='\n') { if( c == ' ' || c == '\t' ) { p++; continue;} else if( '9' >= c && c >= '0' ) { p = get_number(p, &number); t = 0; st_push( t, number); } else { switch( c ) { case '*': case '/': case '+': case '-': calc( c ); st_push( c, 0 ); break; } p ++; } st_print(); } c = '='; calc( c ); st_print(); st_pop( &t, &v ); printf("Result: %d \n", v); }
int main(void) { // There are a lot of dependencies in the order of these inits. // Don't change the ordering unless you understand this. // Inits can assume that all memory has been zeroed by either // a hardware reset or a watchdog timer reset. cli(); // system and drivers sys_init(); // system hardware setup - must be first rtc_init(); // real time counter xio_init(); // xmega io subsystem sig_init(); // signal flags st_init(); // stepper subsystem - must precede gpio_init() gpio_init(); // switches and parallel IO pwm_init(); // pulse width modulation drivers - must follow gpio_init() // application structures tg_init(STD_INPUT); // tinyg controller (controller.c) - must be first app init; reqs xio_init() cfg_init(); // config records from eeprom - must be next app init mp_init(); // motion planning subsystem cm_init(); // canonical machine - must follow cfg_init() sp_init(); // spindle PWM and variables // now bring up the interupts and get started PMIC_SetVectorLocationToApplication(); // as opposed to boot ROM PMIC_EnableHighLevel(); // all levels are used, so don't bother to abstract them PMIC_EnableMediumLevel(); PMIC_EnableLowLevel(); sei(); // enable global interrupts rpt_print_system_ready_message();// (LAST) announce system is ready _unit_tests(); // run any unit tests that are enabled tg_canned_startup(); // run any pre-loaded commands while (true) { // if (tg.network == NET_MASTER) { // tg_repeater(); // } else if (tg.network == NET_SLAVE) { // tg_receiver(); // } else { tg_controller(); // NET_STANDALONE // } } }