void test_tasklist_append(void) { int status; struct task *t, *u; assert(tl); status = tasklist_append(NULL, NULL); assert(status == -1); status = tasklist_append(tl, NULL); assert(status == -1); t = new_task(dup("foo"), NULL, dup("")); assert(t); status = tasklist_append(tl, t); assert(status == 0); assert(tl->head == t); assert(tl->head == tl->tail); u = new_task(dup("bar"), NULL, dup("")); assert(u); status = tasklist_append(tl, u); assert(status == 0); assert(tl->head == t); assert(tl->tail == u); }
struct task *dc_new_task(struct task_group *group, const char *name) { struct task *task = calloc(1, sizeof(struct task)); for (struct task_group *i = task_groups; i ; i = i->next) { for (struct task *j = i->tasks; j ; j = j->next) { if (strcmp(task->name, name) == 0) { log_error("dc", "task %s already registered in group %s", name, i->name); return 0; } } } task->group = group; task->name = strdup(name); if (group->tasks) { assert (group->tasks->prev == 0); group->tasks->prev = task; task->next = group->tasks; } group->tasks = task; if (mod_process (new_task(task)) != 0) goto unroll; if (mod_ubus (new_task(task)) != 0) goto unroll; return task; unroll: dc_delete_task(task); return 0; }
struct task_s * eval (struct expression_s *expr, struct continuation_s *cont) { switch ( expr->t ) { case EXPRESSION_FUNCTION: return invoke (cont, expr->d.expression_function_v); case EXPRESSION_APPLICATION: { struct continuation_s *ncont = new_continuation (); struct task_s *task = new_task (); ncont->t = CONTINUATION_APP1; init_ptr (&ncont->d.continuation_app1_v.rand, expr->d.expression_application_v.rand); init_ptr (&ncont->d.continuation_app1_v.cont, cont); task->t = TASK_EVAL; init_ptr (&task->d.task_eval_v.expr, expr->d.expression_application_v.rator); init_ptr (&task->d.task_eval_v.cont, ncont); #if 0 /* Harmless but not necessary */ free_continuation (ncont); #endif return task; } } fprintf (stderr, "INTERNAL ERROR: eval() surprised!\n"); return NULL; }
static int shared_mem_test(char *message, int len) { rd_t memrd = open_shared_mem(); if (memrd < 0) { strncpy(message, "Unable to open shared mem.", len); return FAILED; } swrite(memrd, IPC_MESSAGE); new_task(&memreader, 1, 0); int count = 100000; while (!passed && (count-- > 0)); if (passed == 1) { return PASSED; } else if (passed == -1) { strncpy(message, "Message mismatch", len); } else { strncpy(message, "Timed out", len); } return FAILED; }
int main(){ int i,j; task_t* task; char name[10][10][10]; char sanity[10][10]; struct timespec tv1, tv2; init_system(2,2); clock_gettime(CLOCK_MONOTONIC_RAW, &tv1); for ( i = 0 ; i < 1; i++){ sprintf(sanity[i],"Mytask%d",i); for ( j = 0 ; j < 10; j++){ task = new_task(hello,"task arg",sizeof(char)*9, my_sanity,"sanity arg",11*sizeof(char),j%2,0); push_task(task, "main_group"); } } // wait_group(char *group, int (*func) (void *), void * args , // unsigned int type, unsigned int time_ms, unsigned int // time_us, float ratio, unsigned int redo); wait_group("main_group" , big_sanity, sanity[0] , SYNC_RATIO, 0 , 0 , 0.8f, 0) ; // monte_carlo_pi(1000000); clock_gettime(CLOCK_MONOTONIC_RAW, &tv2); printf ("Total time = %10g seconds\n", (double) (tv2.tv_nsec - tv1.tv_nsec) / 1000000000.0 + (double) (tv2.tv_sec - tv1.tv_sec)); return 1; }
/***************************************************************************** * init_gdc7220 --- PD7220 の初期化 * * 引数: * なし * * 返り値: * エラー番号 * E_OK 正常終了 * * 機能: * グラフィック GDC の初期化を行う。 * 画面設定する: * サイズ: 640x400 * カラー数: 16 Color * * * 処理概要: * 1. RESETコマンドの発行 * 2. 動作モードの選択 * 3. 表示の開始 * * 4. ドライバ登録の実行 * */ ER init_pd7220 (void) { ER err; T_CTSK pktsk; /* err = gdc_reset (); CHK_ERR; err = gdc_sync (MODE_DISP, 80, 0x08, 0x07, 0, 0, 0, 400, 0); CHK_ERR; */ gdc_display (); err = def_dev (L"DSP", CHAR, ANY_DEVICE, &deviceid); if (err != E_OK) { printf ("cannot initialize for PD7220 device. err = %d\n", err); return (err); } pktsk.tskatr = TA_HLNG; pktsk.startaddr = gdc_server; pktsk.itskpri = 1; pktsk.stksz = PAGE_SIZE * 2; pktsk.addrmap = NULL; err = new_task (&pktsk, &taskid, TRUE); if (err != E_OK) { printf ("cannot create task for PD7220. err = %d\n", err); return (err); } printf ("PD7220: TASK ID = %d\n", taskid); return (E_OK); }
/***************************************************************************** * init_echo * * 引数: * なし * * 返り値: * エラー番号 * E_OK 正常終了 * * 機能: * * */ ER init_echo (void) { ER err; T_CTSK pktsk; err = def_dev (L"ECHO", CHAR, ANY_DEVICE, &deviceid); if (err != E_OK) { printf ("cannot initialize for echo device. err = %d\n", err); return (err); } DPRINTF(("init_echo: setup\n")); pktsk.tskatr = TA_HLNG; pktsk.startaddr = echo_server; pktsk.itskpri = 1; pktsk.stksz = PAGE_SIZE * 2; pktsk.addrmap = NULL; err = new_task (&pktsk, &taskid, TRUE); if (err != E_OK) { printf ("cannot create task for echo. err = %d\n", err); return (err); } printf ("echo: TASK ID = %d\n", taskid); return (E_OK); }
static void run_wait_task(void *(*fn)(void *), void *arg) { pid_t p; p = new_task("", fn, NULL); while (-EINTR == task_waitpid(p)); }
/************************************************************************************************** READ_TCP_QUERY Returns 0 on success, -1 on failure. **************************************************************************************************/ int read_tcp_query(TASK *t) { unsigned char *end; int rv; /* Read packet length if we haven't already */ if (!t->len) return read_tcp_length(t); end = t->query + t->len; /* Read whatever data is ready */ if ((rv = recv(t->fd, t->query + t->offset, t->len - t->offset, 0)) < 0) return Warn("%s: %s", clientaddr(t), _("recv (TCP)")); if (!rv) return (-1); /* Client closed connection */ #if DEBUG_ENABLED && DEBUG_TCP Debug("%s: 2+%d TCP octets in", clientaddr(t), rv); #endif t->offset += rv; if (t->offset > t->len) return Warnx("%s: %s", clientaddr(t), _("TCP message data too long")); if (t->offset < t->len) return 0; /* Not finished reading */ t->offset = 0; /* Reset offset for writing reply */ return new_task(t, t->query, t->len); }
void USART2_IRQHandler(void) //����2 �жϷ������ { uint8_t tmp; task * uart2_task; struct uart_buffer *uart2_buf; uint16_t length = 0; if(USART_GetITStatus(USART2, USART_IT_IDLE) != RESET) { tmp = USART_ReceiveData(USART2); DMA_Cmd(DMA1_Channel6, DISABLE); // close DMA length = USART_RECEIVED_MAX_LEN - DMA_GetCurrDataCounter(DMA1_Channel6); //printf("uart2 dma2 length:%d\n", length); uart2_buf = (struct uart_buffer*)malloc(sizeof(struct uart_buffer)); uart2_buf->buf = (uint8_t*)malloc(length + 1); uart2_buf->length = length + 1; memcpy(uart2_buf->buf, g_usart2_received_buf, length); uart2_buf->buf[length] = 0; uart2_task = new_task(); uart2_task->handler = module_data_handler; uart2_task->pdata = uart2_buf; add_task(uart2_task); // set data length of transmission DMA_SetCurrDataCounter(DMA1_Channel6, USART_RECEIVED_MAX_LEN); // open DMA DMA_Cmd(DMA1_Channel6,ENABLE); } if(USART_GetITStatus(USART2, USART_IT_TXE) != RESET) //�����Ϊ�˱���STM32 USART ��һ���ֽڷ�����ȥ��BUG { USART_ITConfig(USART2, USART_IT_TXE, DISABLE); //��ֹ�����������жϣ� } }
void * distill_loop(void *arg) { FILE *f = (FILE *)arg; FILE *html; task_t *request; char url[256]; int ss; while (1) { if (feof(f)) (void)fseek(f, 0L, SEEK_SET); /* read next URL from file */ fgets(url, sizeof(url), f); if (url[ss = strlen(url)-1] == '\n') url[ss] = '\0'; if ((html = fopen(url, "r")) == NULL) { proxy_errlog_2("Skipping file '%s', couldn't open", url); continue; } new_task(&request); SET_TASK_ID(request, request_count); SET_TASK_GO_PROC(request, file_go_proc); SET_TASK_DATA(request, html); assert(dispatch(request) == 0); request_count++; } }
void deq_test(int argc, char **argv) { if (argc != 1) { printf("Usage: %s\r\n", argv[0]); return; } message_t *m1 = malloc(sizeof(message_t)); if (m1 == NULL) { printf("Unable to malloc m1\r\n"); return; } m1->m = "Message 1"; message_t *m2 = malloc(sizeof(message_t)); if (m1 == NULL) { printf("Unable to malloc m1\r\n"); return; } m2->m = "Message 2"; message_t *m3 = malloc(sizeof(message_t)); if (m1 == NULL) { printf("Unable to malloc m1\r\n"); return; } m3->m = "Message 3"; sdeq_add(&deque, m1); sdeq_add(&deque, m2); sdeq_add(&deque, m3); new_task(&t1, 1, 40); new_task(&t2, 1, 100); yield_if_possible(); /* Make sure other tasks are done */ usleep(1000000); list_t *l = __sdeq_pop(&deque); while(l) { message_t *m = container_of(l, message_t, _list); printf("deq_test got: %s\r\n", m->m); free(m); l = __sdeq_pop(&deque); } }
int run_program(char *filename,uint32_t limit4k){ uint8_t *file_buffer; uint8_t file; uint32_t task_id; int loadelf_return; file_t fileinfo; entry_t entry; fileinfo = file_info(filename); uint8_t *task_base_address; if(fileinfo.status != 0){ print_string("Read file failed."); return -1; } file_buffer = malloc(fileinfo.item.size); if(file_buffer == NULL){ return -3; } file = read_file(filename,(uint8_t *)file_buffer,fileinfo.item.size); if(file != 0){ print_string("Read file failed."); return -2; } entry = get_elf_entry((uint8_t *)file_buffer); free(file_buffer); if(limit4k > 0){ task_base_address = (uint8_t *)malloc(limit4k*4096); if(task_base_address == NULL){ return -3; } if(loadelf_return = loadelf((uint8_t *)file_buffer,(uint8_t *)task_base_address,fileinfo.item.size)){ return -3-loadelf_return; } task_id = new_task((uint32_t)task_base_address,limit4k,entry,limit4k*4096); }else{ task_base_address = (uint8_t *)malloc(DEFAULT_TASK_LIMIT_4K*4096); if(task_base_address == NULL){ return -3; } print_hex((uint32_t)task_base_address); if(loadelf_return = loadelf((uint8_t *)file_buffer,(uint8_t *)task_base_address,fileinfo.item.size)){ return -3-loadelf_return; } task_id = new_task((uint32_t)task_base_address,DEFAULT_TASK_LIMIT_4K,entry,DEFAULT_TASK_LIMIT_4K*4096); } return task_id; }
void mv__scheduler_init(void) { sched_state.task_idle = new_task(task_idle, 128); /* The idle task doesn't start with a rolled up task state. Rewind its * current stack position. */ sched_state.task_idle->stack_current += sizeof(nx_task_stack_t); sched_state.task_current = sched_state.task_idle; }
void run (W entry) { W i; struct boot_header *info; struct module_info *modulep; ID rid; T_CTSK pktsk; T_TCB *new_taskp; info = (struct boot_header *)MODULE_TABLE; if ((entry < 1) || (entry >= info->count)) { printf ("module is overflow.\n"); return; } modulep = info->modules; pktsk.tskatr = TA_HLNG; pktsk.itskpri = 2; pktsk.stksz = PAGE_SIZE * 2; pktsk.addrmap = NULL; pktsk.startaddr = (FP)modulep[entry].entry; if (new_task (&pktsk, &rid, FALSE) != E_OK) { printf ("Can not make new task.\n"); return; } printf ("Task id = %d, eip = 0x%x\n", rid, modulep[entry].entry); new_taskp = get_tskp (rid); if (new_taskp == NULL) { printf ("new task is NULL.\n"); return; } /* 生成したタスクの仮想メモリにモジュールをマッピング */ /* ただしドライバの場合には、マッピングしない */ if (modulep[entry].type == driver) { printf ("This module is driver. not mapped\n"); } else { for (i = 0; i < ROUNDUP (modulep[entry].length, PAGE_SIZE) / PAGE_SIZE; i++) { if (vmap (new_taskp, modulep[entry].vaddr + i * PAGE_SIZE, modulep[entry].paddr + i * PAGE_SIZE) == FALSE) { printf ("Cannot memory map: virtual addr: 0x%x, phisical addr = 0x%x\n", modulep[entry].vaddr + i * PAGE_SIZE, modulep[entry].paddr + i * PAGE_SIZE); } } } sta_tsk (rid, 0); task_switch (TRUE); }
void TTPT_init(){ msched_args_t ps_args = (msched_args_t)MSG_host_get_data(MSG_host_self()); task_t facto,update,elim; unsigned int BS = ps_args->ui_BS; unsigned int p = ps_args->ui_p; unsigned int q = ps_args->ui_q; int K, M, RD; int k,mmm, nnn; K = min( p, q); for (k = 0; k < K; k++) { for (M = k; //M < p-1 || M == k; // No bottom single-row subdomain M < p || M == k; // The line above is PLASMA code, the line here is our variants, note: we need square tiles M += BS) { facto = new_task(F, ps_args,NULL,M, k,0,0); for (nnn = k+1; nnn < q; nnn++) { update = new_task(H,ps_args,facto, M,k, nnn,0); } for (mmm = M+1; //(mmm < M+BS && mmm < p) || mmm == p-1; // Suck in bottom single-row domain (mmm < M+BS && mmm < p); // The line above is PLASMA code, the line here is our variants, note: we need square tiles mmm++) { facto = new_task(F, ps_args,NULL,mmm, k,0,0); elim = new_task(Z,ps_args,NULL, mmm, M, k,0); for (nnn = k+1; nnn < q; nnn++) { update = new_task(H,ps_args,facto, mmm,k, nnn,0); update = new_task(V,ps_args,elim, mmm,M, k,nnn); } } } for (RD = BS; RD < p-k; RD *= 2) { for (M = k; //M+RD < p-1; // No reduction with bottom single-row subdomain M+RD < p; // The line above is PLASMA code, the line here is our variants, note: we need square tiles M += 2*RD) { elim = new_task(Z,ps_args,NULL, M+RD, M, k,0); for (nnn = k+1; nnn < q; nnn++) { update = new_task(V,ps_args,elim, M+RD,M, k,nnn); } } } } }
void blink(int argc, char **argv) { if (argc < 2) { printf("Usage: %s LED...\r\nExample: blink blue orange\r\n", argv[0]); return; } for (int i = 1; i < argc; i++) { if (!strncmp(argv[i], "blue", 16)) { if (enabled_blue) { printf("Blue LED already enabled.\r\n"); } else { printf("Enabling blue LED..."); new_task(&blue_led, 5, 500); enabled_blue = 1; printf("Done.\r\n"); } } else if (!strncmp(argv[i], "orange", 16)) { if (enabled_orange) { printf("Orange LED already enabled.\r\n"); } else { printf("Enabling orange LED..."); new_task(&orange_led, 5, 2000); enabled_orange = 1; printf("Done.\r\n"); } } else if (!strncmp(argv[i], "green", 16)) { if (enabled_green) { printf("Green LED already enabled.\r\n"); } else { printf("Enabling green LED..."); new_task(&green_led, 5, 1000); enabled_green = 1; printf("Done.\r\n"); } } else { printf("Unknown LED: %s\r\n", argv[i]); } } }
void set_hx711_b32(ADC_HANDLE handle, int delay, void (*callback)(void*, int), void* callback_env) { handle_details* details; details = get_handle_details(handle); if (details != NULL) { new_task(details, B32, delay, callback, callback_env); } }
void set_hx711_wait(ADC_HANDLE handle, int delay) { handle_details* details; details = get_handle_details(handle); if (details != NULL) { new_task(details, WAIT, delay, dummy_callback, NULL); } }
/* called to create a new server task */ static void standard_new_task(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *service_name, void (*new_task)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *), void *private_data) { pid_t pid; struct tevent_context *ev2; pid = fork(); if (pid != 0) { /* parent or error code ... go back to the event loop */ return; } pid = getpid(); /* This is now the child code. We need a completely new event_context to work with */ ev2 = s4_event_context_init(NULL); /* setup this as the default context */ s4_event_context_set_default(ev2); /* the service has given us a private pointer that encapsulates the context it needs for this new connection - everything else will be freed */ talloc_steal(ev2, private_data); /* this will free all the listening sockets and all state that is not associated with this new connection */ talloc_free(ev); /* ldb/tdb need special fork handling */ ldb_wrap_fork_hook(); tevent_add_fd(ev2, ev2, child_pipe[0], TEVENT_FD_READ, standard_pipe_handler, NULL); close(child_pipe[1]); /* Ensure that the forked children do not expose identical random streams */ set_need_random_reseed(); setproctitle("task %s server_id[%d]", service_name, pid); /* setup this new task. Cluster ID is PID based for this process modal */ new_task(ev2, lp_ctx, cluster_id(pid, 0), private_data); /* we can't return to the top level here, as that event context is gone, so we now process events in the new event context until there are no more to process */ event_loop_wait(ev2); talloc_free(ev2); exit(0); }
void close_hx711(ADC_HANDLE handle, void (*callback)(void*, int), void* callback_env) { handle_details* details; details = get_handle_details(handle); if (details != NULL) { open_handles[handle] = NULL; new_task(details, TERMINATE, 0, callback, callback_env); write_console("close\n"); } }
void lowpass_test(int argc, char **argv) { if (argc != 1) { printf("Usage: %s\r\n", argv[0]); return; } printf("This program will continuously print a mathematically correct filtered roll angle.\r\n\ It is ghetto and CANNOT BE STOPPED WHEN RUN.\r\n\ q to quit now, any other key will continue.\r\n"); if(getc() != 'q') { printf("LOL TOO LATE NOW FOOL. HOPE YOU GOT YOUR RESET BUTTON HANDY. SCRUB.\r\n"); new_task(&ghetto_lp, 8, DELTA_T*DT_TO_JIFFIES); } }
void xmr_waiting_wnd_add_task(XmrWaitingWnd *wnd, InfoType type, const gchar *text) { g_return_if_fail(wnd != NULL); if (text != NULL) { new_task(wnd->priv, type, text); xmr_waiting_wnd_show(wnd); gtk_widget_queue_draw(GTK_WIDGET(wnd)); } }
void cFontLoader ::CreateDistanceFieldFontAsync(FreeTypeFace& face, uint32_t tex_size, std::function<void(tDistanceFontHandle)> callback) { cCreateBitmapFontTask* task; std::unique_ptr<cCreateBitmapFontTask> new_task( new cCreateBitmapFontTask( face, tex_size, 8, 3)); task = new_task.get(); new_task->SetCallback( [this, task, callback](tTaskHandle handle){ tDistanceFontHandle dff = InsertDistanceFont(task->GetCompletedFont()); callback(dff); }); mWorkerPool.AddTask(std::move(new_task)); }
/* called to create a new server task */ static void standard_new_task(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *service_name, void (*new_task)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *), void *private_data) { pid_t pid; pid = fork(); if (pid != 0) { /* parent or error code ... go back to the event loop */ return; } pid = getpid(); /* this will free all the listening sockets and all state that is not associated with this new connection */ if (tevent_re_initialise(ev) != 0) { smb_panic("Failed to re-initialise tevent after fork"); } /* ldb/tdb need special fork handling */ ldb_wrap_fork_hook(); tevent_add_fd(ev, ev, child_pipe[0], TEVENT_FD_READ, standard_pipe_handler, NULL); close(child_pipe[1]); /* Ensure that the forked children do not expose identical random streams */ set_need_random_reseed(); setproctitle("task %s server_id[%d]", service_name, (int)pid); /* setup this new task. Cluster ID is PID based for this process modal */ new_task(ev, lp_ctx, cluster_id(pid, 0), private_data); /* we can't return to the top level here, as that event context is gone, so we now process events in the new event context until there are no more to process */ event_loop_wait(ev); talloc_free(ev); exit(0); }
void ipctest(int argc, char **argv) { if (argc != 1) { printf("Usage: %s\n", argv[0]); return; } rd_t memrd = open_shared_mem(); if (memrd < 0) { printf("Error: unable to open shared mem.\r\n"); } printf("WRITING MEM.\r\n"); swrite(memrd, "THIS IS A TEST OF SHARED MEMORY REGIONS N STUFF."); printf("READING MEM.\r\n"); new_task(&memreader, 5, 0); }
int main (int argc, char *argv[]) { struct expression_s *expr; struct continuation_s *finis = new_continuation (); struct continuation_s *cont = new_continuation (); struct task_s *task = new_task (); if ( argc == 1 ) expr = parse (stdin); else if ( argc == 2 ) { FILE *f; f = fopen (argv[1], "r"); if ( ! f ) { perror ("Can't open input file"); exit (1); } expr = parse (f); fclose (f); } else { fprintf (stderr, "Expected zero or one argument"); exit (1); } finis->t = CONTINUATION_FINAL; push_cont(finis); cont->t = CONTINUATION_ABORT; task->t = TASK_EVAL; init_ptr (&task->d.task_eval_v.expr, expr); init_ptr (&task->d.task_eval_v.cont, cont); while ( task->t != TASK_FINAL ) { struct task_s *next_task = run (task); free_task (task); task = next_task; } return 0; }
int main() { uint8_t r = 0; diag_init(); BSP_PB_Init(0, 0); new_task(0, led_handler, NULL); while (1) { int state = BSP_PB_GetState(0); if (state) { r++; r %= 8; } ksleep(100); diag_putc(r); ksleep(100); } return 0; }
/* called to startup a new task */ static void single_new_task(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *service_name, void (*new_task)(struct tevent_context *, struct loadparm_context *, struct server_id, void *), void *private_data) { pid_t pid = getpid(); /* start our taskids at MAX_INT32, the first 2^31 tasks are is reserved for fd numbers */ static uint32_t taskid = INT32_MAX; /* * We use the PID so we cannot collide in with cluster ids * generated in other single mode tasks, and, and won't * collide with PIDs from process model starndard because a the * combination of pid/task_id should be unique system-wide * * Using the pid unaltered makes debugging of which process * owns the messaging socket easier. */ new_task(ev, lp_ctx, cluster_id(pid, taskid++), private_data); }
// taylor series for (x)^(-1) for a = 0 int simple_sum() { task_t *temp; int *terms= (int *) calloc((NUM_TERMS+1),sizeof(int)); int i; terms[0] = 1; for (i=0; i<NUM_TERMS; ++(i)) { temp = new_task(sum_elements,&terms[i],sizeof(int), NULL,NULL,0,1,0); // define_in_dependencies(temp, 1, &terms[i] , sizeof(int)); // define_out_dependencies(temp, 1, &terms[i+1] , sizeof(int)); push_task(temp,"sum"); } wait_group("sum", NULL, NULL, SYNC_ALL , 0, 0, 1.0, 0); for (i=0; i<NUM_TERMS+1; ++i) { printf("%d \n",terms[i]); } return 0; }