void *remove_some_recycle_tasks( void *vp) { int i; int iter = -1; work_task *ptask; pthread_mutex_lock(tr.mutex); for (i = 0; i < TASKS_TO_REMOVE; i++) { ptask = next_task_from_recycler(&tr.tasks, &iter); if (ptask == NULL) break; remove_task(&tr.tasks, ptask); pthread_mutex_unlock(ptask->wt_mutex); free(ptask->wt_mutex); free(ptask); } pthread_mutex_unlock(tr.mutex); return(NULL); } /* END remove_some_recycle_tasks() */
void kill_task(task_t *task) { remove_task(task); put_zombie(task); if (task->waited != FALSE) task->parent->waiting = FALSE; }
void mainloop(void) { extern int game_is_being_shut_down; struct task *current_task; struct timeval tv; double task_start; #ifdef SUPER_SNOOP read_snoop_file(); #endif (void) printf("Setting up ipc.\n"); (void)fflush(stdout); prepare_ipc(); (void) signal(SIGFPE, sigfpe_handler); while (!game_is_being_shut_down) { while (task_head.next == &task_head) { set_current_time(); deliver_signals(); call_out(&tv); if (task_head.next != &task_head) tv.tv_sec = tv.tv_usec = 0; nd_select(&tv); check_for_slow_shut_down(); } set_current_time(); current_task = task_head.next; remove_task(current_task); runtask(current_task); task_start = current_time; set_current_time(); update_runq_av((num_tasks + 1.0) * (current_time - task_start)); /* process callouts and IO */ deliver_signals(); if (task_head.next != &task_head || current_task->next == current_task) { tv.tv_sec = tv.tv_usec = 0; call_out(NULL); } else call_out(&tv); if (task_head.next != &task_head || current_task->next == current_task) tv.tv_sec = tv.tv_usec = 0; nd_select(&tv); check_for_slow_shut_down(); if (current_task->next == current_task) append_task(current_task); /* reschedule the task */ else free(current_task); } shutdowngame(); }
//This function checks for errors or inconsistencies in the task list, and attempts to correct them. void task_list_cleanup() { printf_P(PSTR("\tAttempting to restore task_list (by dropping all non-periodic tasks.\r\n\tIf you only see this message rarely, don't worry too much.\r\n")); volatile Task_t* cur_task = task_list; volatile Task_t* task_ptr_arr[MAX_NUM_SCHEDULED_TASKS]; uint8_t num_periodic_tasks = 0; ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { RTC.INTCTRL &= ~RTC_COMP_INT_LEVEL; while (cur_task != NULL) { if(cur_task->period==0) { cur_task = cur_task->next; } else { cur_task->scheduled_time=get_time()+cur_task->period+50; task_ptr_arr[num_periodic_tasks] = cur_task; cur_task = cur_task->next; task_ptr_arr[num_periodic_tasks]->next=NULL; num_periodic_tasks++; } } uint8_t task_is_periodic = 0; for(uint8_t i=0;i<MAX_NUM_SCHEDULED_TASKS;i++) { for(uint8_t j=0;j<num_periodic_tasks;j++) { if(&(task_storage_arr[i])==task_ptr_arr[j]) { //printf_P(PSTR("\tSaving task %X because it is periodic.\r\n"),&(task_storage_arr[i])); task_is_periodic = 1; break; } } if(!task_is_periodic) { //printf_P(PSTR("\tClearing memory of task %X.\r\n"), &(task_storage_arr[i])); remove_task(&(task_storage_arr[i])); } task_is_periodic = 0; } num_tasks = 0; task_list=NULL; //Now, the task list has been cleared out, but only non-periodic tasks have had their memory purged. for(uint8_t i=0;i<num_periodic_tasks;i++) { add_task_to_list(task_ptr_arr[i]); } } }
/* * Free a Telnet Control Block. */ static void telnet_free(telnet_t *tp) { nq_free(tp->t_rawq); nq_free(tp->t_canq); if (tp->t_optq != NULL) nq_free(tp->t_optq); nq_free(tp->t_outq); if (tp->task) remove_task(tp->task); tp->task = NULL; free(tp); }
static void force_remove_object(struct object *ob) { remove_object_from_stack(ob); remove_object_hash(ob); remove_task(ob->callout_task); delete_all_calls(ob); ob->next_all = obj_list_destruct; ob->prev_all = NULL; obj_list_destruct = ob; ob->flags |= O_DESTRUCTED; tot_alloc_dest_object++; }
void delete_task( struct work_task *ptask) /* M */ { if (ptask->wt_tasklist) remove_task(ptask->wt_tasklist,ptask); /* put the task in the recycler */ insert_task_into_recycler(ptask); pthread_mutex_unlock(ptask->wt_mutex); } /* END delete_task() */
static int handle_exit(struct task *task) { debug(DEBUG_EVENT, "+++ process pid=%d exited (status=%d)", task->pid, task->event.e_un.ret_val); show_exit(task); if (task->leader == task) { report_exit(task); untrace_proc(task); } else { remove_task(task); } return RET_DELETED; }
static void remove_finished_tasks( tr_web * g ) { CURLMsg * msg; int msgs_left; while(( msg = curl_multi_info_read( g->multi, &msgs_left ))) { if(( msg->msg == CURLMSG_DONE ) && ( msg->easy_handle != NULL )) { struct tr_web_task * task; CURL * e = msg->easy_handle; curl_easy_getinfo( e, CURLINFO_PRIVATE, (void*)&task ); assert( e == task->easy ); remove_task( task ); } } }
static int handle_exit_signal(struct task *task) { debug(DEBUG_EVENT, "+++ process pid=%d killed by signal %s (%d)", task->pid, strsignal(task->event.e_un.signum), task->event.e_un.signum); if (unlikely(options.verbose)) fprintf(stderr, "+++ process pid=%d killed by signal %s (%d)\n", task->pid, strsignal(task->event.e_un.signum), task->event.e_un.signum); if (task->leader == task) { report_exit(task); untrace_proc(task); } else { remove_task(task); } return RET_DELETED; }
void dispatch_task( struct work_task *ptask) /* M */ { if (ptask->wt_tasklist) remove_task(ptask->wt_tasklist, ptask); /* mark the task as being recycled - it gets freed later */ ptask->wt_being_recycled = TRUE; pthread_mutex_unlock(ptask->wt_mutex); if (ptask->wt_func != NULL) enqueue_threadpool_request((void *(*)(void *))ptask->wt_func, ptask); return; } /* END dispatch_task() */
void consumer(long wid) { //printf("Worker wid %ld started on %d\n",wid, sched_getcpu()); int sorts = 0; // count number of quicksort calls in this consumer task_t* task = NULL; int numberOfProducersLocal = numberOfProducers; /** * Check if called by the parent thread - if so call qucksort to start filling the queue */ if (wid == numConsumers - 1) { sorts ++; quicksort(array,initialTask->low,initialTask->high); free(initialTask); // No longer need the initial Task } /** * Loop while the queue is not empty or quicksort(in this case producer is still running) */ while (task || numberOfProducersLocal) { /** * Save number of producers to check in while loop */ pthread_mutex_lock(&taskLock); numberOfProducersLocal = numberOfProducers; /** * Try to get a task */ task = remove_task(sharedQueue); pthread_mutex_unlock(&taskLock); // sort it if (task) { pthread_mutex_lock(&clientLock); numberOfProducers++; pthread_mutex_unlock(&clientLock); sorts++; quicksort(array, task->low, task->high); free(task); // No longer need the task, this is safe to do since free doesn't reset // the pointer, so this is still a valid check for termination } } //printf("Worker wid %ld participated in %d sorts.\n", wid, sorts); }
void reschedule_task(struct task *t) { if (!t) return; if (t->next == t) return; /* It's the currently running task, it will be rescheduled when it is finnished */ if (t->next == 0) { t->prev = t->next = t; /* it's the currrently running task. Mark it for rescheduling */ return; } /* Move the task to the tail */ remove_task(t); append_task(t); }
int dispatch_task( struct work_task *ptask) /* M */ { int rc = PBSE_NONE; if (can_dispatch_task() == false) return(PBSE_SERVER_BUSY); if (ptask->wt_tasklist) remove_task(ptask->wt_tasklist, ptask); /* mark the task as being recycled - it gets freed later */ ptask->wt_being_recycled = TRUE; pthread_mutex_unlock(ptask->wt_mutex); if (ptask->wt_func != NULL) enqueue_threadpool_request((void *(*)(void *))ptask->wt_func, ptask); return(rc); } /* END dispatch_task() */
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; } }
static DWORD WINAPI ThreadProc(LPVOID pParam) { task_node* node = (task_node*)pParam; u32 event_count = 0; event_node* event = NULL; while ( true ){ if( InterlockedExchangeAdd(&(node->force_quit), 0 ) == true ) break; event = fetch_event_head(node); if( event == NULL ){ WaitForSingleObject(node->event_nofity, INFINITE); }else{ if( node->callback ){ node->callback(event->item); } SetEvent(event->notify); delete_event_node(event); } } remove_task(node); delete_task_node(node); return 0; }
int remove_from_rq(pcontext *pcb) { set_task_state(pcb, SLEEPING); return remove_task(pcb, 0); }
static void task_timeout_cb( int fd UNUSED, short what UNUSED, void * task ) { remove_task( task ); }
void taskbar_remove_task(gpointer key, gpointer value, gpointer user_data) { remove_task(task_get_task(*(Window*)key)); }
// Start tracing of created or attached process. static trace_result_t start(void) { int status; int pid; int signo; // wait on all child processes. while((pid = waitpid(-1, &status, 0)) != -1) { signo = 0; struct ftrace_task* task = find_task(pid); // Precondition: stopped task is known. FTRACE_ASSERT(task != NULL); // task exited, need to remove it from trace list. if(WIFEXITED(status) || WIFSIGNALED(status)) { FTRACE_LOG("task %d terminated\n", pid); remove_task(task); // task is stopped } else if(WIFSTOPPED(status)) { signo = WSTOPSIG(status); // SIGSTOP/SIGTRAP is our cue. if((signo == SIGTRAP) || (signo == SIGSTOP)) { // We stop process in case of cloning/forking and when it is entering/exiting syscalls. // To deffirentiate we use ptrace event code in process status. switch(FTRACE_EVENT(status)) { case PTRACE_EVENT_FORK: /* fallthru */ case PTRACE_EVENT_VFORK: /* fallthru */ case PTRACE_EVENT_CLONE: { // task cloned/forked - add another pid context. int new_pid; ptrace(PTRACE_GETEVENTMSG, task->pid, NULL, &new_pid); add_task(new_pid); FTRACE_LOG("task %d cloned, new pid is %d\n", task->pid, new_pid); break; } case 0: { // syscall trap trace_task(task); } default: break; }; } } else { FTRACE_LOG("Unknown task %d status\n", pid); } ptrace(PTRACE_SYSCALL, pid, NULL, NULL); } // stop tracing. return FTRACE_SUCCESS; }
int main(int argc, char* argv[]){ char* taskfilename = "todo.txt"; // char* donefile = "done.txt"; //bool verbose = false; int status = EXIT_SUCCESS; // parse the command line arguments. if (argc < 2){ print_short_help(); exit(status); } int i; //start the loop at 1 because argv[0] refers to the binary file for (i = 1; i < argc; i++){ // Add a new task. if (strings_equal(argv[i], "add", "-a")){ if (add_task(taskfilename, argv[i+1]) != 0){ status = EXIT_FAILURE; // We done goofed. } i++; // Skip the next argument. continue; } // Remove a task. if (strings_equal(argv[i], "rm", "-r")){ int index = atoi(argv[i+1]); if (remove_task(taskfilename, index) != 0){ status = EXIT_FAILURE; } i++; continue; } // Complete a task. if (strings_equal(argv[i], "do", "-d")){ int index = atoi(argv[i+1]); set_complete_task(taskfilename, index, true); i++; continue; } // Uncomplete a task. if (strings_equal(argv[i], "undo", "-u")){ int index = atoi(argv[i+1]); set_complete_task(taskfilename, index, false); i++; continue; } // List the tasks matching the string in the file. if (strings_equal(argv[i], "search", "-s")){ list_tasks_matching(taskfilename, argv[i+1]); i++; continue; } // Show all the tasks in the file. if(strings_equal(argv[i], "ls", "-l")){ list_tasks(taskfilename); continue; } // Show the help dialog. if (strcmp(argv[i], "-h") == 0){ print_help(); } // Set the taskfilename flag. if (strcmp(argv[i], "-f") == 0){ taskfilename = argv[i+1]; i++; continue; } // Set the verbosity flag. if (strcmp(argv[i], "-v") == 0){ // verbose = true; } } return status; }
void event_property_notify(XEvent* e) { int i; Task* tsk; Window win = e->xproperty.window; Atom at = e->xproperty.atom; if (xsettings_client) xsettings_client_process_event(xsettings_client, e); if (win == server.root_win) { if (!server.got_root_win) { XSelectInput(server.dsp, server.root_win, PropertyChangeMask | StructureNotifyMask); server.got_root_win = 1; } // Change name of desktops else if (at == server.atom._NET_DESKTOP_NAMES) { if (!taskbarname_enabled) return; GSList* l, *list = server_get_name_of_desktop(); gchar* name; Taskbar* tskbar; for (i = 0; i < nb_panel; i++) { l = list; for (uint8_t j = 0; j < panel1[i].desktop_count; j++) { if (l) { name = g_strdup(l->data); l = l->next; } else name = g_strdup_printf("%d", j + 1); tskbar = &panel1[i].taskbar[j]; if (strcmp(name, tskbar->bar_name.name) != 0) { g_free(tskbar->bar_name.name); tskbar->bar_name.name = name; tskbar->bar_name.area.resize = 1; } else g_free(name); } } for (l = list; l; l = l->next) g_free(l->data); g_slist_free(list); panel_refresh = 1; } // Change number of desktops else if (at == server.atom._NET_NUMBER_OF_DESKTOPS) { if (!taskbar_enabled) return; server.nb_desktop = server_get_number_of_desktop(); if (server.nb_desktop <= server.desktop) { server.desktop = server.nb_desktop - 1; } cleanup_taskbar(); init_taskbar(); for (i = 0; i < nb_panel; i++) { init_taskbar_panel(&panel1[i]); set_panel_items_order(&panel1[i]); visible_taskbar(&panel1[i]); panel1[i].area.resize = 1; } task_refresh_tasklist(); active_task(); panel_refresh = 1; } // Change desktop else if (at == server.atom._NET_CURRENT_DESKTOP) { if (!taskbar_enabled) return; int old_desktop = server.desktop; server.desktop = server_get_current_desktop(); for (i = 0; i < nb_panel; i++) { Panel* panel = &panel1[i]; set_taskbar_state(&panel->taskbar[old_desktop], TASKBAR_NORMAL); set_taskbar_state(&panel->taskbar[server.desktop], TASKBAR_ACTIVE); // check ALLDESKTOP task => resize taskbar Taskbar* tskbar; Task* tsk; GSList* l; if (server.nb_desktop > old_desktop) { tskbar = &panel->taskbar[old_desktop]; l = tskbar->area.list; if (taskbarname_enabled) l = l->next; for (; l; l = l->next) { tsk = l->data; if (tsk->desktop == ALLDESKTOP) { tsk->area.on_screen = 0; tskbar->area.resize = 1; panel_refresh = 1; } } } tskbar = &panel->taskbar[server.desktop]; l = tskbar->area.list; if (taskbarname_enabled) l = l->next; for (; l; l = l->next) { tsk = l->data; if (tsk->desktop == ALLDESKTOP) { tsk->area.on_screen = 1; tskbar->area.resize = 1; } } } } // Window list else if (at == server.atom._NET_CLIENT_LIST) { task_refresh_tasklist(); panel_refresh = 1; } // Change active else if (at == server.atom._NET_ACTIVE_WINDOW) { active_task(); panel_refresh = 1; } else if (at == server.atom._XROOTPMAP_ID || at == server.atom._XROOTMAP_ID) { // change Wallpaper for (i = 0; i < nb_panel; i++) { set_panel_background(&panel1[i]); } panel_refresh = 1; } } else { tsk = task_get_task(win); if (!tsk) { if (at != server.atom._NET_WM_STATE) return; else { // xfce4 sends _NET_WM_STATE after minimized to tray, so we need to // check if window is mapped // if it is mapped and not set as skip_taskbar, we must add it to our // task list XWindowAttributes wa; XGetWindowAttributes(server.dsp, win, &wa); if (wa.map_state == IsViewable && !window_is_skip_taskbar(win)) { if ((tsk = add_task(win))) panel_refresh = 1; else return; } else return; } } // Window title changed if (at == server.atom._NET_WM_VISIBLE_NAME || at == server.atom._NET_WM_NAME || at == server.atom.WM_NAME) { if (get_title(tsk)) { if (g_tooltip.mapped && (g_tooltip.area == (Area*)tsk)) { tooltip_copy_text((Area*)tsk); tooltip_update(); } panel_refresh = 1; } } // Demand attention else if (at == server.atom._NET_WM_STATE) { if (window_is_urgent(win)) { add_urgent(tsk); } if (window_is_skip_taskbar(win)) { remove_task(tsk); panel_refresh = 1; } } else if (at == server.atom.WM_STATE) { // Iconic state int state = (task_active && tsk->win == task_active->win ? TASK_ACTIVE : TASK_NORMAL); if (window_is_iconified(win)) state = TASK_ICONIFIED; set_task_state(tsk, state); panel_refresh = 1; } // Window icon changed else if (at == server.atom._NET_WM_ICON) { get_icon(tsk); panel_refresh = 1; } // Window desktop changed else if (at == server.atom._NET_WM_DESKTOP) { uint32_t desktop = window_get_desktop(win); // bug in windowmaker : send unecessary 'desktop changed' when focus // changed if (desktop != tsk->desktop) { remove_task(tsk); tsk = add_task(win); active_task(); panel_refresh = 1; } } else if (at == server.atom.WM_HINTS) { XWMHints* wmhints = XGetWMHints(server.dsp, win); if (wmhints && wmhints->flags & XUrgencyHint) { add_urgent(tsk); } XFree(wmhints); } if (!server.got_root_win) server.root_win = RootWindow(server.dsp, server.screen); } }