void svc_register_task(task_ctrl *task, int periodic) { insert_task(runnable_task_list, task); if (periodic) { insert_task(periodic_task_list, task); } }
int packet_in(struct sk_buff *packet, struct timeval tv) { struct iphdr *ip; // Create aodv message types u_int8_t aodv_type; //The packets which come in still have their headers from the IP and UDP int start_point = sizeof(struct udphdr) + sizeof(struct iphdr); //get pointers to the important parts of the message ip = ip_hdr(packet); aodv_type = (int) packet->data[start_point]; #ifdef DEBUG if ( aodv_type != HELLO_MESSAGE ) printk("packet_in: type: %d and of size %u from: %s\n", aodv_type, packet->len - start_point, inet_ntoa(ip->saddr)); #endif if (!valid_aodv_packet(packet->len - start_point, aodv_type, packet->data + start_point, tv)) { #ifdef DEBUG printk("Packet of type: %d and of size %u from: %s failed packet check!\n", aodv_type, packet->len - start_point, inet_ntoa(ip->saddr)); #endif return NF_DROP; } insert_task(aodv_type, packet); return NF_ACCEPT; }
task_api u32 create_task_queue(task_notify_routine func) { task_node* node = create_task_node(); HANDLE thread_handle; DWORD thread_id = 0; node->callback = func; thread_handle = (HANDLE)CreateThread(NULL, // Security attributes 0, // stack ThreadProc, // Thread proc (PVOID)node, // Thread param CREATE_SUSPENDED, // creation mode &thread_id); // Thread ID if ( NULL != thread_handle && INVALID_HANDLE_VALUE != thread_handle ) { node->thread_id = thread_id; insert_task(node); ResumeThread( thread_handle ); CloseHandle(thread_handle); return (u32)node; } else { return 0; } }
int insert_task_into_recycler( struct work_task *ptask) { pthread_mutex_t *tmp = ptask->wt_mutex; int rc; memset(ptask, 0, sizeof(struct work_task)); ptask->wt_mutex = tmp; pthread_mutex_lock(tr.mutex); ptask->wt_being_recycled = TRUE; if (tr.tasks.ra->num >= MAX_TASKS_IN_RECYCLER) enqueue_threadpool_request(remove_some_recycle_tasks, NULL); rc = insert_task(&tr.tasks, ptask); pthread_mutex_unlock(tr.mutex); return(rc); } /* END insert_task_into_recycler() */
int wake_up_task(void *pcb) { pcb = (pcontext *)pcb; set_task_state(pcb, READY); return insert_task(pcb); }
static void add_process_objects(hwloc_topology_t topology) { #ifdef HAVE_DIRENT_H hwloc_obj_t root; hwloc_bitmap_t cpuset; #ifdef HWLOC_LINUX_SYS hwloc_bitmap_t task_cpuset; #endif /* HWLOC_LINUX_SYS */ DIR *dir; struct dirent *dirent; const struct hwloc_topology_support *support; root = hwloc_get_root_obj(topology); support = hwloc_topology_get_support(topology); if (!support->cpubind->get_proc_cpubind) return; dir = opendir("/proc"); if (!dir) return; cpuset = hwloc_bitmap_alloc(); #ifdef HWLOC_LINUX_SYS task_cpuset = hwloc_bitmap_alloc(); #endif /* HWLOC_LINUX_SYS */ while ((dirent = readdir(dir))) { long local_pid_number; hwloc_pid_t local_pid; char *end; char name[80]; int proc_cpubind; local_pid_number = strtol(dirent->d_name, &end, 10); if (*end) /* Not a number */ continue; snprintf(name, sizeof(name), "%ld", local_pid_number); local_pid = hwloc_pid_from_number(local_pid_number, 0); proc_cpubind = hwloc_get_proc_cpubind(topology, local_pid, cpuset, 0) != -1; #ifdef HWLOC_LINUX_SYS { char comm[16]; char *path; size_t pathlen = 6 + strlen(dirent->d_name) + 1 + 7 + 1; path = malloc(pathlen); { /* Get the process name */ char cmd[64]; int file; ssize_t n; snprintf(path, pathlen, "/proc/%s/cmdline", dirent->d_name); file = open(path, O_RDONLY); if (file < 0) { /* Ignore errors */ free(path); continue; } n = read(file, cmd, sizeof(cmd)); close(file); if (n <= 0) { /* Ignore kernel threads and errors */ free(path); continue; } snprintf(path, pathlen, "/proc/%s/comm", dirent->d_name); file = open(path, O_RDONLY); if (file >= 0) { n = read(file, comm, sizeof(comm) - 1); close(file); if (n > 0) { comm[n] = 0; if (n > 1 && comm[n-1] == '\n') comm[n-1] = 0; } else { snprintf(comm, sizeof(comm), "(unknown)"); } } else { /* Old kernel, have to look at old file */ char stats[32]; char *parenl = NULL, *parenr; snprintf(path, pathlen, "/proc/%s/stat", dirent->d_name); file = open(path, O_RDONLY); if (file < 0) { /* Ignore errors */ free(path); continue; } /* "pid (comm) ..." */ n = read(file, stats, sizeof(stats) - 1); close(file); if (n > 0) { stats[n] = 0; parenl = strchr(stats, '('); parenr = strchr(stats, ')'); if (!parenr) parenr = &stats[sizeof(stats)-1]; *parenr = 0; } if (!parenl) { snprintf(comm, sizeof(comm), "(unknown)"); } else { snprintf(comm, sizeof(comm), "%s", parenl+1); } } snprintf(name, sizeof(name), "%ld %s", local_pid_number, comm); } { /* Get threads */ DIR *task_dir; struct dirent *task_dirent; snprintf(path, pathlen, "/proc/%s/task", dirent->d_name); task_dir = opendir(path); if (task_dir) { while ((task_dirent = readdir(task_dir))) { long local_tid; char *task_end; const size_t tid_len = sizeof(local_tid)*3+1; size_t task_pathlen = 6 + strlen(dirent->d_name) + 1 + 4 + 1 + strlen(task_dirent->d_name) + 1 + 4 + 1; char *task_path; int comm_file; char task_comm[16] = ""; char task_name[sizeof(name) + 1 + tid_len + 1 + sizeof(task_comm) + 1]; ssize_t n; local_tid = strtol(task_dirent->d_name, &task_end, 10); if (*task_end) /* Not a number, or the main task */ continue; task_path = malloc(task_pathlen); snprintf(task_path, task_pathlen, "/proc/%s/task/%s/comm", dirent->d_name, task_dirent->d_name); comm_file = open(task_path, O_RDONLY); free(task_path); if (comm_file >= 0) { n = read(comm_file, task_comm, sizeof(task_comm) - 1); if (n < 0) n = 0; close(comm_file); task_comm[n] = 0; if (n > 1 && task_comm[n-1] == '\n') task_comm[n-1] = 0; if (!strcmp(comm, task_comm)) /* Same as process comm, do not show it again */ n = 0; } else { n = 0; } if (hwloc_linux_get_tid_cpubind(topology, local_tid, task_cpuset)) continue; if (proc_cpubind && hwloc_bitmap_isequal(task_cpuset, cpuset)) continue; if (n) { snprintf(task_name, sizeof(task_name), "%s %li %s", name, local_tid, task_comm); } else { snprintf(task_name, sizeof(task_name), "%s %li", name, local_tid); } insert_task(topology, task_cpuset, task_name); } closedir(task_dir); } } free(path); } #endif /* HWLOC_LINUX_SYS */ if (!proc_cpubind) continue; if (hwloc_bitmap_isincluded(root->cpuset, cpuset)) continue; insert_task(topology, cpuset, name); } hwloc_bitmap_free(cpuset); #ifdef HWLOC_LINUX_SYS hwloc_bitmap_free(task_cpuset); #endif /* HWLOC_LINUX_SYS */ closedir(dir); #endif /* HAVE_DIRENT_H */ }
static void add_process_objects(hwloc_topology_t topology) { #ifdef HAVE_DIRENT_H hwloc_obj_t root; hwloc_bitmap_t cpuset; #ifdef HWLOC_LINUX_SYS hwloc_bitmap_t task_cpuset; #endif /* HWLOC_LINUX_SYS */ DIR *dir; struct dirent *dirent; const struct hwloc_topology_support *support; root = hwloc_get_root_obj(topology); support = hwloc_topology_get_support(topology); if (!support->cpubind->get_proc_cpubind) return; dir = opendir("/proc"); if (!dir) return; cpuset = hwloc_bitmap_alloc(); #ifdef HWLOC_LINUX_SYS task_cpuset = hwloc_bitmap_alloc(); #endif /* HWLOC_LINUX_SYS */ while ((dirent = readdir(dir))) { long local_pid_number; hwloc_pid_t local_pid; char *end; char name[64]; int proc_cpubind; local_pid_number = strtol(dirent->d_name, &end, 10); if (*end) /* Not a number */ continue; snprintf(name, sizeof(name), "%ld", local_pid_number); local_pid = hwloc_pid_from_number(local_pid_number, 0); proc_cpubind = hwloc_get_proc_cpubind(topology, local_pid, cpuset, 0) != -1; #ifdef HWLOC_LINUX_SYS { /* Get the process name */ char *path; unsigned pathlen = 6 + strlen(dirent->d_name) + 1 + 7 + 1; char cmd[64], *c; int file; ssize_t n; path = malloc(pathlen); snprintf(path, pathlen, "/proc/%s/cmdline", dirent->d_name); file = open(path, O_RDONLY); free(path); if (file >= 0) { n = read(file, cmd, sizeof(cmd) - 1); close(file); if (n <= 0) /* Ignore kernel threads and errors */ continue; cmd[n] = 0; if ((c = strchr(cmd, ' '))) *c = 0; snprintf(name, sizeof(name), "%ld %s", local_pid_number, cmd); } } { /* Get threads */ char *path; unsigned pathlen = 6+strlen(dirent->d_name) + 1 + 4 + 1; DIR *task_dir; struct dirent *task_dirent; path = malloc(pathlen); snprintf(path, pathlen, "/proc/%s/task", dirent->d_name); task_dir = opendir(path); free(path); if (task_dir) { while ((task_dirent = readdir(task_dir))) { long local_tid; char *task_end; char task_name[64]; local_tid = strtol(task_dirent->d_name, &task_end, 10); if (*task_end) /* Not a number, or the main task */ continue; if (hwloc_linux_get_tid_cpubind(topology, local_tid, task_cpuset)) continue; if (proc_cpubind && hwloc_bitmap_isequal(task_cpuset, cpuset)) continue; snprintf(task_name, sizeof(task_name), "%s %li", name, local_tid); insert_task(topology, task_cpuset, task_name); } closedir(task_dir); } } #endif /* HWLOC_LINUX_SYS */ if (!proc_cpubind) continue; if (hwloc_bitmap_isincluded(root->cpuset, cpuset)) continue; insert_task(topology, cpuset, name); } hwloc_bitmap_free(cpuset); #ifdef HWLOC_LINUX_SYS hwloc_bitmap_free(task_cpuset); #endif /* HWLOC_LINUX_SYS */ closedir(dir); #endif /* HAVE_DIRENT_H */ }
int packet_in(struct sk_buff *packet, struct timeval tv) { struct iphdr *ip; // Create aodv message types u_int8_t aodv_type; //The packets which come in still have their headers from the IP and UDP int start_point = sizeof(struct udphdr) + sizeof(struct iphdr); //get pointers to the important parts of the message ip = ip_hdr(packet); aodv_type = (int) packet->data[start_point]; #ifdef CaiDebug if( aodv_type == RCVP_MESSAGE) printk("It's a rcvp message\n"); #endif /*#ifdef DEBUGC char name[30]; unsigned char if_port; int ifindex; unsigned short type; unsigned short dev_id; if(aodv_type != HELLO_MESSAGE){ struct net_device *dev = packet->dev; strcpy(name,dev->name); if_port = dev->if_port; ifindex = dev->ifindex; type = dev->type; dev_id = dev->dev_id; char port[20]; switch(if_port){ case IF_PORT_UNKNOWN:strcpy(port,"UNKNOWN");break; case IF_PORT_10BASE2:strcpy(port,"10BASE2");break; case IF_PORT_10BASET:strcpy(port,"10BASET");break; case IF_PORT_AUI:strcpy(port,"AUI");break; case IF_PORT_100BASET:strcpy(port,"100BASET");break; case IF_PORT_100BASETX:strcpy(port,"100BASETX");break; case IF_PORT_100BASEFX:strcpy(port,"100BASEFX");break; } printk("------------------------------------\ndev->name:%s\ndev->ifindex:%d\ndev->type:%d\ndev->dev_id:%d\ndev->if_port:%s\n----------------------------------\n",name,ifindex,type,dev_id,port); } #endif */ #ifdef DEBUG if ( aodv_type != HELLO_MESSAGE ) printk("packet_in: type: %d and of size %u from: %s\n", aodv_type, packet->len - start_point, inet_ntoa(ip->saddr)); #endif if (!valid_aodv_packet(packet->len - start_point, aodv_type, packet->data + start_point, tv)) { #ifdef DEBUG printk("Packet of type: %d and of size %u from: %s failed packet check!\n", aodv_type, packet->len - start_point, inet_ntoa(ip->saddr)); #endif return NF_DROP; } insert_task(aodv_type, packet); return NF_ACCEPT; }
//read async animation task void read_task(FILE *stream) { char buff[BUFSIZE]; buff[BUFSIZE-1] = '\0'; LolTask *tsk = loltask_new(); //read parameters while (1) { fgets(buff, BUFSIZE-1, stream); //start of data section if (strncmp(buff, LOLD_SYM_DAT, LOLD_SYM_DAT_LEN) == 0) break; //read parameter and throw error if out of range strtok(buff," "); //param int val = atoi(strtok(NULL, " \n")); //value if (strncmp(buff, LOLD_SYM_DEL, LOLD_SYM_DEL_LEN) == 0 && val>=20 && val<=1000) tsk->delay = val; else if (strncmp(buff, LOLD_SYM_TTL, LOLD_SYM_TTL_LEN) == 0 && val>=0 && val<=600) tsk->ttl = val; else if (strncmp(buff, LOLD_SYM_PRI, LOLD_SYM_PRI_LEN) == 0 && val>=0) tsk->pri = val; else { if (DEBUG) fprintf(stderr, "> Animation invalid, discarded.\n"); loltask_free(tsk); puts_tcp_stream(LOLD_SYM_ERR"\n\0", stream); return; } } //read frames while (1) { fgets(buff, BUFSIZE-1, stream); //end of frames if (strncmp(buff, LOLD_SYM_END"\0", LOLD_SYM_END_LEN) == 0) break; char *save_ptr; strtok_r(buff,"\n", &save_ptr); //strip newline //check frame (9 comma sep ints?) DOES NOT WORK WITH NEW COMMANDS /* int commas=0; for (unsigned int i=0; i<strlen(buff); i++) if (buff[i]==',') commas++; if (commas!=8) { loltask_free(tsk); puts_tcp_stream(LOLD_SYM_ERR"\n\0", stream); return; } */ //copy frame into task char *frame = malloc(sizeof(char)*strlen(buff)+1); memcpy(frame, buff, strlen(buff)+1); tsk->frames = lollist_add(tsk->frames, frame); } //insert task into list insert_task(tsk); if (DEBUG) fprintf(stderr, "> Animation with priority %i added.\n", tsk->pri); //tcp_send_string(fd, LOLD_SYM_OK"\n\0"); puts_tcp_stream(LOLD_SYM_OK"\n\0", stream); }
struct work_task *set_task( enum work_type type, long event_id, /* I - based on type can be time of event */ void (*func)(), void *parm, int get_lock) { work_task *pnew; work_task *pold; if ((pnew = (struct work_task *)calloc(1, sizeof(struct work_task))) == NULL) { return(NULL); } pnew->wt_event = event_id; pnew->wt_type = type; pnew->wt_func = func; pnew->wt_parm1 = parm; if (type == WORK_Immed) { enqueue_threadpool_request((void *(*)(void *))func,pnew); } else { if (pnew->wt_mutex == NULL) { if ((pnew->wt_mutex = calloc(1, sizeof(pthread_mutex_t))) == NULL) { free(pnew); return(NULL); } } pthread_mutex_init(pnew->wt_mutex,NULL); pthread_mutex_lock(pnew->wt_mutex); if (type == WORK_Timed) { unsigned char inserted = FALSE; while (inserted != TRUE) { pold = find_insertion_point(&task_list_timed, pnew); if (pold != NULL) { if (insert_task_before(&task_list_timed, pnew, pold) == AFTER_IS_BEING_RECYCLED) continue; pthread_mutex_unlock(pold->wt_mutex); } else { insert_task(&task_list_timed, pnew); } inserted = TRUE; } } else { insert_task(&task_list_event, pnew); } /* only keep the lock if they want it */ if (get_lock == FALSE) pthread_mutex_unlock(pnew->wt_mutex); } return(pnew); } /* END set_task() */