APR_DECLARE(apr_status_t) apr_thread_pool_top(apr_thread_pool_t *me, apr_thread_start_t func, void *param, apr_byte_t priority, void *owner) { return add_task(me, func, param, priority, 0, owner); }
/** * \brief sets the motor rpm acording to the data.w[0] data.w[1] int values should be pased if negative robot will go backwords * * \param task Used to specify a pointer to a specific received task. * * \return void */ void set_rpm(task_t *task) { u32_union temp; temp.dw = task->data.value; int16_t l = (int16_t)temp.w[1],r = (int16_t)temp.w[0]; if (l>-1) { set_m_forward() l_motor.rpm = l; r_motor.rpm = r; } else { set_m_backward() l_motor.rpm = int16_abs_Q(l); r_motor.rpm = int16_abs_Q(r); } task_t motor2 = {.data.command = MOTOR_L, .data.value = l_motor.rpm}; add_task(&motor2); task_t motor3 = {.data.command = MOTOR_R, .data.value = r_motor.rpm}; add_task(&motor3); } uint16_t circle_time = 4400; /** * \brief Tunes the time that takes to complete the circle * * \param task Used to specify a pointer to a specific received task. u8[3] represents a multiple of 100ms * * \return void */ void set_circle_time(task_t *task) { circle_time = task->data.u8[3]*100; } static uint16_t L=7, R=15; void set_corner_time(task_t *task) { R = task->data.u8[3]; L = task->data.u8[2]; }
void state_find_track_turn_left_control_logic() { if (state_find_track_go_a_bit_more_control_data.not_first_run == false){ state_find_track_go_a_bit_more_control_data.not_first_run = true; task_t system_state = {.data.command = STATE_COMMAND, .data.timestamp=0, .data.value=STATE_FIND_LEFT_TURN}; add_task(&system_state); set_m_forward(); l_motor.rpm = 20; r_motor.rpm = 20; } }
void add_task_decode_slice_segment(decoder_context* ctx, int thread_id) { thread_task task; task.task_id = 0; // no ID task.task_cmd = THREAD_TASK_DECODE_SLICE_SEGMENT; task.work_routine = thread_decode_slice_segment; task.data.task_ctb_row.ctx = ctx; task.data.task_ctb_row.thread_context_id = thread_id; add_task(&ctx->thread_pool, &task); }
void Builder::create_task( const Environment& env, const NodeList& targets, const NodeList& sources, const ActionList& actions, Task::Scanner scanner ) const { add_task(env, targets, sources, actions); properties(targets[0]).task()->set_scanner(scanner); }
void add_task_decode_CTB_row(decoder_context* ctx, int thread_id, bool initCABAC) { thread_task task; task.task_id = 0; // no ID task.task_cmd = THREAD_TASK_DECODE_CTB_ROW; task.work_routine = thread_decode_CTB_row; task.data.task_ctb_row.ctx = ctx; task.data.task_ctb_row.initCABAC = initCABAC; task.data.task_ctb_row.thread_context_id = thread_id; add_task(&ctx->thread_pool, &task); }
int task_set_flags(int target_ID,int master_ID,unsigned long long flags) { struct set_flags set; set.tasknr=5; set.target_ID=target_ID; set.master_ID=master_ID; set.flags=flags; return add_task(&set,sizeof(set)); }
void core::curl_handler::perform_async(priority_t _priority, milliseconds_t _timeout, CURL* _handle, completion_callback_t _completion_callback) { if (keep_working_) { auto completion_handler = completion_handler_t(_completion_callback); add_task(_priority, _timeout, _handle, completion_handler); } else { _completion_callback(false); } }
int main() { init_pool(&tp,threads_number); int i; for(i=0;i<10;i++) { add_task(&tp,task,NULL); printf("%s%d\n", "add ",i+1); } destroy_pool(&tp); return 0; }
OneShotTask::OneShotTask( OneShotTask** handle, polclock_t run_when_clock ) : ScheduledTask( run_when_clock ), handle( handle ) { if ( handle != NULL ) { passert( *handle == NULL ); *handle = this; } add_task( this ); }
void t_hts_take_meas() { /* A variable defined to have under control buggy measurement preparing: when measurement was deputed, but no results can be get from sensor. */ static uint16_t meas_not_rdy_cnt = 0; // Attempting to get data for 500 miliseconds. if(meas_not_rdy_cnt == 500) { // Let GNSS module depute new measurement meas_not_rdy_cnt = 0; return; } if(!hts_take_meas()) { add_asynch_task(t_hts_take_meas, 10, false); meas_not_rdy_cnt += 10; } else { meas_not_rdy_cnt = 0; add_task(t_hts_dep_meas); add_task(t_hts_prep_data); hts_is_meas_listed = false; } }
void collect_info_handler(int signo) { list_node *curr = head->next; while (curr != NULL) { CLIENT *cl = (CLIENT*)curr->data; add_task(&thread_pool, cl); curr = curr->next; } }
int task_fire_from_clan(int target_ID,int master_ID,int clan,char *master_name) { struct fire_from_clan_data set; set.tasknr=2; set.target_ID=target_ID; set.master_ID=master_ID; set.clan=clan; strcpy(set.master_name,master_name); return add_task(&set,sizeof(set)); }
// --------- called by server thread --------------- int task_set_clan_rank(int target_ID,int master_ID,int clan,int rank,char *master_name) { struct set_clan_rank_data set; set.tasknr=1; set.target_ID=target_ID; set.master_ID=master_ID; set.clan=clan; set.rank=rank; strcpy(set.master_name,master_name); return add_task(&set,sizeof(set)); }
int kernel_main (void) { puts("This is ninjastorms OS"); puts(" shuriken ready"); add_task(&controller_task); start_scheduler(); puts("All done. ninjastorms out!"); return 0; }
void new_event(char event, void* data) { SYNC_TASK *task; DIR_NODE *dir; FILE_NODE *file; char full_name[DIR_LEN_MAX] = {0}; switch(event) { case ADD_DIR: case DEL_DIR: { dir = (DIR_NODE *)data; get_dir_full_name(dir, full_name); task = get_new_sync_task(event, full_name, dir->size); add_task(task); if (ADD_DIR == event) { add_dir_to_task(dir); } break; } case ADD_FILE: case DEL_FILE: case MOD_FILE: { file = (FILE_NODE *)data; get_file_full_name(file, full_name); task = get_new_sync_task(event, full_name, file->size); add_task(task); break; } default: { PRINT("unknow change\n"); } } }
stochastic_taskset *load_stochastic_taskset(FILE * source, char delimiter[]) { stochastic_taskset *taskset; stochastic_task_view t_view; size_t line_len = 0; ssize_t str_len = 0; double *buffer = NULL; char *line = NULL; unsigned int cells = 0; unsigned int distribution_offset = 3; taskset = new_stochastic_taskset(10); while ((str_len = getline(&line, &line_len, source)) != -1) { if (line[0] != '#') { cells = get_cells(line, delimiter) - distribution_offset; buffer = realloc(buffer, (cells) * sizeof(double)); if (!buffer) { return NULL; } memset(buffer, 0, (cells) * sizeof(double)); if (!parse_line (line, delimiter, buffer, cells, distribution_offset, &t_view)) { free(buffer); free(line); free_stochastic_taskset(taskset); return NULL; } if (!add_task(taskset, t_view)) { free(buffer); free(line); free_stochastic_taskset(taskset); return NULL; } } } free(buffer); free(line); return taskset; }
/* Initialize all kernel subsystems and run system */ int main(void) { printa("In main %x\n", (unsigned)main); init_int(); init_page_alloc(); init_pipes(); init_scheduler(); add_task(&init_systems); while (1) { schedule(); } return 0; }
int main() { thread_pool *tp = (thread_pool*)malloc(sizeof(thread_pool)); task** t = malloc(10 * sizeof(task*)); init_thread_pool(tp, 2, 4, 1000, create_thread_func); int i; for(i = 0; i < 10; ++i) { t[i] = malloc(sizeof(task)); t[i]->func = test; add_task(tp, t[i]); } wait_and_destroy(tp); }
/** * \brief ajoute une liste en tant que noeud XML dans un noeud passe * en parametre ainsi que les sous elements de celle-ci (Liste* et * Tache*) si il y en a * \param l : Liste*, la liste a ajouter * \param node : pugi::xml_node, le noeud parent */ void add_list(std::deque<ListComponent*> lc_, pugi::xml_node node) { pugi::xml_node k; /* Key for node */ const char* tmp; /* Value of key */ pugi::xml_node child; /* Node to add */ for(std::deque<ListComponent*>::iterator it = lc_.begin();it!=lc_.end();++it) { Liste *lc=dynamic_cast<Liste*>(*it); if(lc) { child = node.append_child(LIST_TAG);; child.append_attribute("id")=(unsigned int)(lc)->getId(); // Title k = child.append_child(KEY_TAG); tmp = (lc)->getTitle().c_str(); k.append_child(pugi::node_pcdata).set_value(tmp); k.append_attribute("name")="title"; // Date k = child.append_child(KEY_TAG); tmp = (lc)->getDate().c_str(); k.append_child(pugi::node_pcdata).set_value(tmp); k.append_attribute("name")="date"; // isChecked k = child.append_child(KEY_TAG); k.append_child(pugi::node_pcdata).set_value(lc->isDoneChecked()?"true":"false"); k.append_attribute("name")="isChecked"; // isOrdered k = child.append_child(KEY_TAG); k.append_child(pugi::node_pcdata).set_value(lc->isOrderedList()?"true":"false"); k.append_attribute("name")="isOrdered"; // deep k = child.append_child(KEY_TAG); unsigned int deepvalue = lc->getDeep(); std::stringstream deepss; deepss << deepvalue; k.append_child(pugi::node_pcdata).set_value(deepss.str().c_str()); k.append_attribute("name")="deep"; add_list(lc->getElements(),child); } else { add_task((Tache *)(*it),node); } } }
trace_result_t trace_create_target(const char* path, char** argv) { int pid = vfork(); if(pid < 0) { FTRACE_LOG("Error: vfork failed\n"); return -1; } if(pid == 0) { /* Child. */ long rc = ptrace(PTRACE_TRACEME, 0, NULL, NULL); if(rc < 0) { FTRACE_LOG("Error: ptrace failed\n"); return -1; } execvp(name, argv); /* Should not be reachable if ok. */ FTRACE_LOG("Error: exec failed\n"); exit(0); } /* Parent. Wait for child to exec and start tracing. */ int status = 0; waitpid(pid, &status, WUNTRACED); if(WIFEXITED(status)) { FTRACE_LOG("Error: child process failed to execute\n"); return FTRACE_INVALID_PROCESS; } // Add first task. if(0 != add_task(pid)) { return FTRACE_NO_MEMORY; } setup_ptrace_options(pid); ptrace(PTRACE_SYSCALL, pid, NULL, NULL); FTRACE_LOG("Starting trace for pid %d\n", pid); return start(); }
core::curl_handler::future_t core::curl_handler::perform(priority_t _priority, milliseconds_t _timeout, CURL* _handle) { auto promise = promise_t(); auto future = promise.get_future(); if (keep_working_) { auto completion_handler = completion_handler_t(promise_wrapper(std::move(promise))); add_task(_priority, _timeout, _handle, completion_handler); } else { promise.set_value(CURLE_FAILED_INIT); } return future; }
int main() { int i, *p; pool_init(4); p = (int*)malloc(10*sizeof(int)); for (i = 0; i < 10; i++) { *p[i] = i; add_task(process, (void *)p); } free(p); sleep(5); pool_destory(); return 0; }
void taskbar_read_clientlist (void) { Window *win, focus_win; int num, i, rev, desk, new_desk = 0; task *list, *next; desk = get_current_desktop (); if (desk != tb.my_desktop) { new_desk = 1; tb.my_desktop = desk; } XGetInputFocus (dd, &focus_win, &rev); win = get_prop_data (root_win, atom__NET_CLIENT_LIST, XA_WINDOW, &num); if (!win) return; /* remove windows that arn't in the _NET_CLIENT_LIST anymore */ list = tb.task_list; while (list) { list->focused = (focus_win == list->win); next = list->next; if (!new_desk) for (i = num - 1; i >= 0; i--) if (list->win == win[i]) goto dontdel; del_task (list->win); dontdel: list = next; } /* add any new windows */ for (i = 0; i < num; i++) { if (!find_task (win[i])) add_task (win[i], (win[i] == focus_win)); } XFree (win); }
void state_find_track_go_a_bit_more_control_logic() { if (state_find_track_go_a_bit_more_control_data.not_first_run == false){ state_find_track_go_a_bit_more_control_data.not_first_run = true; task_t system_state = {.data.command = STATE_COMMAND, .data.timestamp=0, .data.value=STATE_FIND_GO_A_BIT_MORE}; add_task(&system_state); set_m_forward(); l_motor.rpm = 0; r_motor.rpm = 0; //set_movement(0x32,C_FIND_BIT_MORE,BACKWARD); set_movement(0x32,C90,LEFT); } if (l_motor.corner==C0 && r_motor.corner==C0) { state_find_track_turn_left_control_data.not_first_run=false; set_state(state_find_track_turn_left_control_logic); } }
/** * Create a new task * @author Ivan Gualandri * @version 1.0 * @param task_name The name of the task * @param start_function the entry point of the task. */ pid_t new_task(char *task_name, void (*start_function)()){ asm("cli"); task_t new_task; table_address_t local_table; unsigned int new_pid = request_pid(); strcpy(new_task.name, task_name); new_task.start_function = start_function; new_task.pid = new_pid; new_task.eip = (unsigned int)start_function; new_task.esp = (unsigned int) kmalloc(STACK_SIZE) + STACK_SIZE - 100; new_task.state = READY; new_task.registers = (task_register_t*)new_task.esp; new_tss(new_task.registers, start_function); local_table = map_kernel(); new_task.pdir = local_table.page_dir; new_task.ptable = local_table.page_table; add_task(new_task.pid, &new_task); asm("sti"); return new_pid; }
void read_next_task(STREAM *file, TODOLIST *list) { char c; char *message = NULL; int done = 0; int priority = 0; skip_whitespace(file); c = stream_getc(file); if (c != '[') { if (c == '#') { read_next_option(file, list); skip_line(file); return; } stream_ungetc(c, file); skip_line(file); return; } c = stream_getc(file); switch (c) { case 'X': case 'x': done = 1; break; case ' ': done = 0; break; default: stream_ungetc(c, file); skip_line(file); return; } c = stream_getc(file); if (c != ']') { stream_ungetc(c, file); skip_line(file); return; } skip_whitespace(file); message = read_string(file); add_task(list, message, done, priority); }
void event_configure_notify(Window win) { // change in root window (xrandr) if (win == server.root_win) { signal_pending = SIGUSR1; return; } // 'win' is a trayer icon TrayWindow* traywin; GSList* l; for (l = systray.list_icons; l; l = l->next) { traywin = (TrayWindow*)l->data; if (traywin->tray_id == win) { XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, traywin->width, traywin->height); XResizeWindow(server.dsp, traywin->tray_id, traywin->width, traywin->height); panel_refresh = 1; return; } } // 'win' move in another monitor if (nb_panel == 1) return; Task* tsk = task_get_task(win); if (!tsk) return; Panel* p = tsk->area.panel; if (p->monitor != window_get_monitor(win)) { remove_task(tsk); tsk = add_task(win); if (win == window_get_active()) { set_task_state(tsk, TASK_ACTIVE); task_active = tsk; } panel_refresh = 1; } }
void enqueue_data(UCHAR * input, int size) { while (io_worker -> num_tasks > MAX_OUTPUT_TASKS) { // block to keep the output queue reasonably short. sched_yield(); } crypttask_t * task = malloc(sizeof(crypttask_t)); task -> blocks = (size + BLOCKSIZE - 1) / BLOCKSIZE; //round up, although size should ALWAYS be an even multiple of BLOCKSIZE task -> text = malloc(task -> blocks * BLOCKSIZE); memcpy(task -> text, input, size); if (size != task -> blocks * BLOCKSIZE) { memset(&(task -> text[size]), 0x0, task -> blocks * BLOCKSIZE - size); } task -> taskid = next_taskid++; //xor with nonce unsigned long iv_part = *((unsigned long *)nonce); iv_part ^= next_blockid_msb; memcpy(task -> iv, &iv_part, sizeof(unsigned long)); iv_part = *((unsigned long *)(&(nonce[sizeof(unsigned long)]))); iv_part ^= next_blockid_lsb; memcpy(&(task -> iv[sizeof(unsigned long)]), &iv_part, sizeof(unsigned long)); //increment counter next_blockid_lsb += task -> blocks; if (next_blockid_lsb < task -> blocks) next_blockid_msb++; // increment more significant counter if we overflowed. task -> complete = 0; task -> next_task = NULL; task -> next_block = NULL; add_task(&(crypters[task -> taskid % numthreads]), task); }
/** * QuickSort an array range */ void quicksort(int *array, int low, int high) { /** * BubbleSort performs better on smaller arrays */ if (high - low < MINSIZE) { pthread_mutex_lock(&clientLock); numberOfProducers--; // Exiting - decrease qSort count pthread_mutex_unlock(&clientLock); bubblesort(array, low, high); return; } int middle = partition(array, low, high); if (low < middle) { task_t * task = create_task(low, middle - 1); /** * Protect addition/removal to/from queue */ pthread_mutex_lock(&taskLock); add_task(sharedQueue, task); pthread_mutex_unlock(&taskLock); } if (middle < high) { pthread_mutex_lock(&clientLock); numberOfProducers++; // Increase every time quicksort is called pthread_mutex_unlock(&clientLock); quicksort(array, middle + 1, high); } /** * Protect addition/removal to/from queue */ pthread_mutex_lock(&clientLock); numberOfProducers--; // Exiting - decrease qSort count pthread_mutex_unlock(&clientLock); }