int init(void){ task_init(&init_task,0); //添加进程1 tss[0] = malloc(sizeof(struct task_struct)); if(tss[0] == NULL){ printf("malloc error\n"); return -1; } task_init(tss[0],1); list_add_tail(&(tss[0]->own),&(init_task.children)); //添加进程2 tss[1] = malloc(sizeof(struct task_struct)); if(tss[1] == NULL){ printf("malloc error\n"); return -1; } task_init(tss[1],2); list_add_tail(&(tss[1]->own),&(init_task.children)); //添加进程3 tss[2] = malloc(sizeof(struct task_struct)); if(tss[2] == NULL){ printf("malloc error\n"); return -1; } task_init(tss[2],3); list_add_tail(&(tss[2]->own),&(tss[0]->children)); return 0; };
void tasks_setup() { task_init(&bootstrapTask, "bootstrap", 0); bootstrapTask.state = TASK_RUNNING; task_init(&irqTask, "irq", 0); irqTask.state = TASK_RUNNING; IRQTask = &irqTask; IRQBackupTask = NULL; CurrentRunning = &bootstrapTask; }
/* And so it begins... */ int main (int argc, char **argv) { /***** Initializations *****/ MPI_Init (&argc, &argv); MPI_Comm_size (MPI_COMM_WORLD, &numtasks); MPI_Comm_rank (MPI_COMM_WORLD, &taskid); task_init (); /* printf ("PID of task %d : %d\n", ID, getpid()); */ /* MASTER */ if (!taskid) { dispatch_input (); receive_output (); } /* SLAVES */ else { receive_input (); send_output (Head); /* Send Blank Line to mark end of transmission */ MPI_Send ("", 50, MPI_UNSIGNED_CHAR, 0, 0, MPI_COMM_WORLD); /* printf ("Done sending output from task %d\n", ID); */ } task_close (); MPI_Finalize (); return 0; }
int main(void) { unsigned int user_stacks[TASK_LIMIT][STACK_SIZE]; unsigned int *usertasks[TASK_LIMIT]; size_t task_count = 0; size_t current_task; task_init(); print_str("OS: Starting...\n"); print_str("OS: First create task 1\n"); usertasks[0] = create_task(user_stacks[0], &task1_func); task_count += 1; print_str("OS: Back to OS, create task 2\n"); usertasks[1] = create_task(user_stacks[1], &task2_func); task_count += 1; print_str("\nOS: Start round-robin scheduler!\n"); /* SysTick configuration */ *SYSTICK_LOAD = ( SystemCoreClock / TICK_RATE_HZ) - 1UL; *SYSTICK_VAL = 0; *SYSTICK_CTRL = 0x07; current_task = 0; while (1) { print_str("OS: Activate next task\n"); usertasks[current_task] = activate(usertasks[current_task]); print_str("OS: Back to OS\n"); current_task = current_task == (task_count - 1) ? 0 : current_task + 1; } return 0; }
/* \details This function initializes the scheduler. It should be * called after all peripherals are initialized and interrupts are on. * \return Zero on success or an error code */ int sched_start(void * (*init)(void*), int priority){ #if SINGLE_TASK == 0 sched_table[0].init = init; sched_table[0].priority = priority; sched_table[0].attr.stackaddr = &_data; sched_table[0].attr.stacksize = caoslib_system_memory_size; //Start the scheduler in a new thread if ( task_init(SCHED_RR_DURATION, scheduler, //run the scheduler NULL, //Let the task init function figure out where the stack needs to be and the heap size caoslib_system_memory_size) ){ return -1; } #else start_function = init; //Enter thread mode task_init_single(start_single, NULL, caoslib_system_memory_size); #endif //Program never gets to this point return -1; }
int main (int argc, char *argv[]) { printf ("Main INICIO\n") ; task_init () ; sem_create (&s1, 1) ; sem_create (&s2, 0) ; task_create (&a1, TaskA, "A1") ; task_create (&a2, TaskA, " A2") ; task_create (&b1, TaskB, " B1") ; task_create (&b2, TaskB, " B2") ; task_join (&a1) ; sem_destroy (&s1) ; sem_destroy (&s2) ; task_join (&a2) ; task_join (&b1) ; task_join (&b2) ; printf ("Main FIM\n") ; task_exit (0) ; exit (0) ; }
void task1_main(void) { /* * This is the bootstrap task- start up the scheduler and load the * second task. Our scheduler is driven by the PIT timer IRQ at * 100 Hz. */ Timer_InitPIT(PIT_HZ / 100); Intr_SetMask(0, TRUE); Intr_SetHandler(IRQ_VECTOR(IRQ_TIMER), schedulerIRQ); /* * Create the second task. It can start running at any time now. */ task_init(&task2, task2_main); while (1) { Intr_Disable(); Console_WriteString("Task 1\n"); Console_Flush(); Intr_Enable(); } }
int main(void) { unsigned int user_stacks[TASK_LIMIT][STACK_SIZE]; unsigned int *usertasks[TASK_LIMIT]; size_t task_count = 0; size_t current_task; usart_init(); task_init(); print_str("OS: Starting...\n"); print_str("OS: First create task 1\n"); usertasks[0] = create_task(user_stacks[0], &task1_func); task_count += 1; print_str("OS: Back to OS, create task 2\n"); usertasks[1] = create_task(user_stacks[1], &task2_func); task_count += 1; print_str("\nOS: Start multitasking, back to OS till task yield!\n"); current_task = 0; while (1) { print_str("OS: Activate next task\n"); usertasks[current_task] = activate(usertasks[current_task]); print_str("OS: Back to OS\n"); current_task = current_task == (task_count - 1) ? 0 : current_task + 1; } return 0; }
void _benmain(void) { struct FIFO32 fifo; int keybuf[128]={0}; fifo32_init(&fifo, 128, keybuf); struct TSS32 tss_a = {0}; cons_init(); env_init(); /* keyboard setting */ init_kb(&fifo, 256); tss_a.ldtr = 0; tss_a.iomap = 0x40000000; set_segmdesc(gdt + 0, 103, (int) &tss_a, AR_TSS32); task_init(memman); /* Unfortunate try the switch back to 0*8 (_benmain) with farjmp but not working. * And the reason still unknown. * So that I use another thread_kb_io() to catch the keyboard interrupt. */ load_tr(0 * 8); // record current working task to tss_a task_create((int) &thread_kb_io, memman, "bshell", 1); task_create((int) &thread_events, memman, "events", 0); /* strange issue encountered if run pci_init at the setup_hw() */ puts("pci scan bus\n"); pci_init(); farjmp(0, 4*8); puts("\nSystem Halted \n"); _syshalt(); }
static int create_task(func_t entry, funcP_t funcP, const char *name, int priority, void *param) { int i; TASK *t; for (i=0; i<MAX_TASKS; i++) { t = Tasks + i; if (!t->valid) break; } if (i == MAX_TASKS) panic("create_task"); task_init(t, i, funcP, param, name, priority); if (priority == HIGH_PRIORITY) { t->next = prio_high; prio_high = t; } else { t->next = prio_low; prio_low = t; } if (t->next) t->next->prev = t; t->prev = NULL; //printf("C%d-%s entry %p func %p param %p\n", t->id, name, entry, funcP, param); fflush(stdout); setjmp(t->jb); t->pc = (u_int64_t) entry; t->sp = ((u_int64_t) (t->stk + STACK_SIZE) & ~STACK_ALIGN) + 8; // +8 for proper alignment moving doubles to stack return t->id; }
void kmain(u32 init_stack) { init_esp_start = init_stack; init_video(); puts_color_str("Booting Panda OS ...\n", 0x0B); cli(); time_init(); gdt_init(); idt_init(); kb_init(); mm_init(); buf_init(); file_init(); inode_init(); ide_init(); task_init(); timer_init(); sysc_init(); spawn(init_user); sti(); init = 0; while(1) { if(!init) { printk("kernel running ...\n"); init = 1; } sti(); sched(); } }
int main(int argc, char **argv) { int *array; int array_size; int nThreads; int i; if (argc != 3) { printf("Usage:\n\t%s <array_size> <nthreads>\n", argv[0]); exit(1); } array_size = atoi(argv[1]); nThreads = atoi(argv[2]); assert(array_size > 0); #pragma css start(nThreads) /* alloc spaces for the option data */ #pragma css malloc array = (int*)malloc( array_size * sizeof(int) ); #pragma css sync ; #pragma css task inout(array[array_size]) in(array_size) task_init(array, array_size); #pragma css task inout(array[array_size]) in(array_size) task_set(array, array_size); #pragma css task in(array[array_size]) in(array_size) task_print(array, array_size); #pragma css task inout(array[array_size]) in(array_size) task_unset(array, array_size); #pragma css task in(array[array_size]) in(array_size) task_print(array, array_size); #pragma css finish return 0; }
Task::Task(Task *parent, void *user, std::function<void(Task&)> taskFn, size_t stackSize, TaskScheduler *scheduler, bool deleteOnFinish) : m_Child(nullptr), m_Scheduler(scheduler), m_Func(taskFn), m_State(State::Runnable), m_DeleteOnFinish(deleteOnFinish) { assert((void *) this == &m_Context); void *stack = stackSize > 0 ? malloc(stackSize) : nullptr; task_init(&m_Context, &parent->m_Context, user, (taskfn) TaskScheduler::TaskFunc, stack, stackSize); }
int main() { // register tasks addTask(task1Init, task1Processor, task1Cancel); addTask(task2Init, task2Processor, task2Cancel); // run init for (Task* task=task_head; task!=0; task = task->next) { task->init(task->id); } int Task->action void task_init() // called at Start command, puts task in queue int task_process() // called while true. If returns 0, remove task from queue int task_progress() // called by Progress command void task_cancel() // called by Cancel command for (Task* task=task_head; task!=0; task = task->next) { if (task->action) { switch (task->action) { case START: // check if running task_init(); break; case PROGRESS: // check if running int progress = task_progress(); // ... break; case CANCEL: // check if running task_cancel(); removeFromRunning(task); break; } } else { int result = task_process(); if (result == DONE) removeFromRunning(task); } } // main loop int tick = 0; while (tick < 100) { for (Task* task=task_head; task!=0; task = task->next) { if (task->events) { task->events = task->process(task->events); } // MANUALLY INSERT EVENTS if (task->id==1 && tick==10) task->events = 30; if (task->id==1 && tick==20) interrupt(); if (task->id==2 && tick==15) task->events = 152; } tick++; } return 0; }
char task_start(struct task *tsk, unsigned char *rec) { tsk->recipe = rec; task_init(tsk); tsk->state = ST_SLEEPING; /* For safety, start paused */ return 0; }
void kernel_main() { int i = 0; //init_sys_mmu(); //start_mmu(); /* 开启MMU */ unsigned int end = (unsigned int)(&__end+PGDR_MASK)&0xffffc000; unsigned int physfree = init_paging(end-0xC0000000); init_ram(physfree); /* 重定位内核*/ asm volatile( "add sp, sp, #0xC0000000\n\t" ); /*清空恒等隐射*/ for(i = 1; i < NR_KERN_PAGETABLE; i++) PTD[i] = 0; uart_init(); char *_temp = "0000000000\r\n"; unsigned int temp; HexToString((unsigned int)&temp, _temp); uart_puts(_temp); task_init(); unsigned char rank = MAX_rank ; unsigned int task_func = (unsigned int)task_idle0; unsigned char TID = task_create( rank , task_func); task_run(TID); task_func = (unsigned int)task_idle1; TID = task_create( rank , task_func); task_run(TID); task_func = (unsigned int)task_idle2; TID = task_create( rank , task_func); task_run(TID); task_func = (unsigned int)task_idle3; TID = task_create( rank , task_func); task_run(TID); init_arm_timer(Kernel_1Hz); _enable_interrupts(); while(1) { char *_ch = "0000000000\r\n"; for(i = 0; i < 20; i++) { HexToString(PTD[i], _ch); uart_puts(_ch); } for(i = 0; i < 20; i++) { HexToString(PTD[i+0xC00], _ch); uart_puts(_ch); } sleep(500); } }
void acm_start() { task_init(&acm_parse_task, "ACM"); usb_setup(acm_enumerate, acm_started); usb_install_ep_handler(ACM_EP_SEND, USBIn, acm_sent, 0); usb_install_ep_handler(ACM_EP_RECV, USBOut, acm_received, 0); usb_install_setup_handler(acm_setup); }
void _benmain(void) { int i; int c = 0; int keybuf[128]={0}; struct FIFO32 fifo; struct TIMER *timer; fifo32_init(&fifo, 128, keybuf); struct TSS32 tss_a, tss_c; env_init(); /* keyboard setting */ init_kb(&fifo, 256); i=0; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); tss_a.ldtr = 0; tss_a.iomap = 0x40000000; tss_c.ldtr = 0; tss_c.iomap = 0x40000000; set_segmdesc(gdt + 3, 103, (int) &tss_a, AR_TSS32); task_init(memman); /* Unfortunate try the switch back to 3*8 (_benmain) with farjmp but not working. * And the reason still unknown. * So that I use another thread_kb_io() to catch the keyboard interrupt. */ load_tr(3 * 8); // record current working task to tss_a task_create((int) &thread_kb_io, memman, "bshell"); /* strange issue encountered if run pci_init at the setup_hw() */ puts("pci scan bus\n"); pci_init(); for (;;) { asm_cli(); if (fifo32_status(&fifo) == 0) { asm_stihlt(); // wake while keyboard input // got a interrupt } else { /* scan_code input */ c=fifo32_get(&fifo); asm_sti(); if (c == 1) { farjmp(0, 4*8); } else { puts("disabled boot options.\n"); } } } puts("\nSystem Halted \n"); _syshalt(); }
static void vUpdateTask(void *pvParameters) { drv_Init(); lib_init(); task_init(); while(1) { lib_update(); task_update(); } }
/* * Initialization code. * * Called from kernel_start() routine that is * implemented in HAL. * We assume that the following machine state has * been already set before this routine. * - Kernel BSS section is filled with 0. * - Kernel stack is configured. * - All interrupts are disabled. * - Minimum page table is set. (MMU systems only) */ int main(void) { sched_lock(); diag_init(); DPRINTF((BANNER)); /* * Initialize memory managers. */ page_init(); kmem_init(); /* * Do machine-dependent * initialization. */ machine_startup(); /* * Initialize kernel core. */ vm_init(); task_init(); thread_init(); sched_init(); exception_init(); timer_init(); object_init(); msg_init(); /* * Enable interrupt and * initialize devices. */ irq_init(); clock_init(); device_init(); /* * Set up boot tasks. */ task_bootstrap(); /* * Start scheduler and * enter idle loop. */ sched_unlock(); thread_idle(); /* NOTREACHED */ return 0; }
/************************************************************************************************** ACCEPT_TCP_QUERY **************************************************************************************************/ int accept_tcp_query(int fd, int family) { struct sockaddr_in addr4; #if HAVE_IPV6 struct sockaddr_in6 addr6; #endif socklen_t addrlen; int rmt_fd; TASK *t; #if HAVE_IPV6 if (family == AF_INET6) { addrlen = sizeof(struct sockaddr_in6); if ((rmt_fd = accept(fd, (struct sockaddr *)&addr6, &addrlen)) < 0) { return Warn("%s", _("accept (TCPv6)")); } fcntl(rmt_fd, F_SETFL, fcntl(rmt_fd, F_GETFL, 0) | O_NONBLOCK); if (!(t = task_init(NEED_READ, rmt_fd, SOCK_STREAM, AF_INET6, &addr6))) return (-1); } else #endif { addrlen = sizeof(struct sockaddr_in); if ((rmt_fd = accept(fd, (struct sockaddr *)&addr4, &addrlen)) < 0) { return Warn("%s", _("accept (TCP)")); } fcntl(rmt_fd, F_SETFL, fcntl(rmt_fd, F_GETFL, 0) | O_NONBLOCK); if (!(t = task_init(NEED_READ, rmt_fd, SOCK_STREAM, AF_INET, &addr4))) return (-1); } #if DEBUG_ENABLED && DEBUG_TCP Debug("%s: TCP connection accepted", clientaddr(t)); #endif return 0; }
int main(int argc, char** argv) { struct heaptimer_t* timer; struct task_t* t; struct task_step_t* t1, *t2, *t3; struct timeval timeout; struct timeval tv; int32_t loop = argc > 1 ? atoi(argv[1]) : 3; cp = curl_pool_init(); assert(cp); timer = timer_init(); assert(timer); t = task_init(on_success, on_fail, (void*)&loop); assert(t); t1 = task_step_init(t1_run); assert(t1); task_push_back_step(t, t1); id = task_step_id(t1); t2 = task_step_init(t2_run); assert(t2); task_push_back_step(t, t2); t3 = task_step_init(t3_run); assert(t3); task_push_back_step(t, t3); timeout.tv_sec = 1; timeout.tv_usec = 0; task_run(t, timer, &timeout); while (1) { if (curl_pool_running_count(cp) > 0) { curl_pool_run(cp); } util_gettimeofday(&tv, NULL); timer_poll(timer, &tv); if (task_finished(t) == 0) { break; } } task_release(t); timer_release(timer); curl_pool_release(cp); return 0; }
void acm_start() { task_init(&acm_parse_task, "ACM", TASK_DEFAULT_STACK_SIZE); usb_setup(acm_enumerate, acm_started); usb_install_ep_handler(ACM_EP_SEND, USBIn, acm_sent, 0); usb_install_ep_handler(ACM_EP_RECV, USBOut, acm_received, 0); usb_install_setup_handler(acm_setup); acm_prev_printf_handler = addPrintfHandler(acm_buffer_notify); }
int main() { i2c_init(); uart_init(); task_init(); task_create(hmc5883l_task, NULL); task_start(); return 0; // Never reached }
char task_restart(struct task *tsk) { if(tsk->recipe == NULL) { return 1; /* Can't restart an empty recipe */ } else { task_init(tsk); tsk->state = ST_SLEEPING; return 0; } }
/*FUNCTION********************************************************************** * * Function Name : OSA_Init * Description : This function is used to setup the basic services, it should * be called first in function main. Return kStatus_OSA_Success if services * are initialized successfully, otherwise return kStatus_OSA_Error. * *END**************************************************************************/ osa_status_t OSA_Init(void) { #if (TASK_MAX_NUM > 0) task_init(); #endif #if (FSL_OSA_BM_TIMER_CONFIG != FSL_OSA_BM_TIMER_NONE) OSA_TimeInit(); #endif return kStatus_OSA_Success; }
int rmd_rec_start() { set_report_rec_stat(); if (driver_init() != 0) return -1; if (task_init() != 0) return -1; return 0; }
void navilnux_init(void) { mem_init(); task_init(); msg_init(); syscall_init(); os_timer_init(); gpio0_init(); os_timer_start(); }
s32 os_main(u32 sp) { struct __os_task__ *ptask; int_init(); uart_init(); dram_init(); timer_init(); mmc_init(); PRINT_INFO("%s\n", sys_banner); coretimer_init(); task_init(); semaphore_init(); PRINT_INFO("cpu_mode: %s; lr: 0x%x; sp: 0x%x; cpsr: 0x%x\n", get_cpu_mode(NULL), __get_lr(), sp, __get_cpsr()); gpio_set_function(GPIO_16, OUTPUT); gpio_set_output(GPIO_16, 0); /* set_log_level(LOG_DEBUG); */ /* create idle task */ if ((ptask = tcb_alloc()) == NULL) { panic(); } tcb_init(ptask, idle_task, 0, 256); /*os_ready_insert(ptask);*/ current_task = &tcb[IDLE_TASK_ID]; /* assume that this is idle_task */ /* create main task */ if ((ptask = tcb_alloc()) == NULL) { panic(); } tcb_init(ptask, main_task, 0, 100); os_ready_insert(ptask); /* 'slip into idle task', cause the os_main() is not a task (it's the god code of system) */ __set_sp(&(task_stack[0][TASK_STK_SIZE])); current_task->state = TASK_RUNNING; idle_task(0); kassert(0); return 0; }
int gp_init() { if(common_init()) return -1; //armv6 works. if(cmd_init()) return -1; if(memory_init()) return -1; if(task_init()) return -1; if(bdev_init()) return -1; if(image_init()) return -1; if(nvram_init()) return -1; if(fs_init()) return -1; if(fb_init()) return -1; gGpHasInit = TRUE; return 0; }