?? task_queue.c
字號:
/*************************************************************************** task_queue.c - description ------------------- begin : Tue Jul 8 2003 copyright : (C) 2003 by Luke Klein-Berndt email : kleinb@nist.gov ***************************************************************************/#include "task_queue.h"spinlock_t task_queue_lock = SPIN_LOCK_UNLOCKED;task *task_q;task *task_end;void queue_lock(){ spin_lock_bh(&task_queue_lock);}void queue_unlock(){ spin_unlock_bh(&task_queue_lock);}void init_task_queue(){ task_q=NULL; task_end=NULL;}void cleanup_task_queue(){task *dead_task, *tmp_task;queue_lock(); tmp_task = task_q; task_q=NULL;while(tmp_task){ dead_task = tmp_task;tmp_task = tmp_task->next;kfree(dead_task->data);kfree(dead_task);} queue_unlock();}task *create_task(int type){ task *new_task; new_task = (task *) kmalloc(sizeof(task), GFP_ATOMIC); if ( new_task == NULL) { printk(KERN_WARNING "AODV: Not enough memory to create Event Queue Entry\n"); return NULL; } new_task->time = getcurrtime(); new_task->type = type; new_task->src_ip = 0; new_task->dst_ip = 0; new_task->ttl = 0; new_task->retries = 0; new_task->data = NULL; new_task->data_len = 0; new_task->next = NULL; new_task->prev = NULL; new_task->dev = NULL; return new_task;}int queue_aodv_task(task * new_entry){ /*lock table */ queue_lock(); //Set all the variables new_entry->next = task_q; new_entry->prev = NULL; if (task_q != NULL) { task_q->prev = new_entry; } if (task_end == NULL) { task_end = new_entry; } task_q = new_entry; //unlock table queue_unlock(); //wake up the AODV thread kick_aodv(); return 0;}task *get_task(){ task *tmp_task = NULL; queue_lock(); if (task_end) { tmp_task = task_end; if (task_end == task_q) { task_q = NULL; task_end = NULL; } else { task_end = task_end->prev; } queue_unlock(); return tmp_task; } if (task_q != NULL) { printk(KERN_ERR "TASK_QUEUE: Error with task queue\n"); } queue_unlock(); return NULL; }int insert_task(int type, struct sk_buff *packet){ task *new_task; struct iphdr *ip; int start_point = sizeof(struct udphdr) + sizeof(struct iphdr); new_task = create_task(type); if (!new_task) { printk(KERN_WARNING "AODV: Not enough memory to create Task\n"); return -ENOMEM; } if (type < 100) { ip = packet->nh.iph; new_task->src_ip = ip->saddr; new_task->dst_ip = ip->daddr; new_task->ttl = ip->ttl; new_task->dev = packet->dev; new_task->data_len = packet->len - start_point; //create space for the data and copy it there new_task->data = kmalloc(new_task->data_len, GFP_ATOMIC); if (!new_task->data) { kfree(new_task); printk(KERN_WARNING "AODV: Not enough memory to create Event Queue Data Entry\n"); return -ENOMEM; } memcpy(new_task->data, packet->data + start_point, new_task->data_len); } switch (type) { //RREP case TASK_RREP: memcpy(&(new_task->src_hw_addr), &(packet->mac.ethernet->h_source), sizeof(unsigned char) * ETH_ALEN); break; default: break; } queue_aodv_task(new_task);}int insert_task_from_timer(task * timer_task){ if (!timer_task) { printk(KERN_WARNING "AODV: Passed a Null task Task\n"); return -ENOMEM; } queue_aodv_task(timer_task);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -