⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tlist.c

📁 MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis的0.9.5版本的源码。
💻 C
字号:
//  This file is part of MANTIS OS, Operating System//  See http://mantis.cs.colorado.edu/////  Copyright (C) 2003,2004,2005 University of Colorado, Boulder////  This program is free software; you can redistribute it and/or//  modify it under the terms of the mos license (see file LICENSE)/*  Project Mantis  File: tlist.c  Author: Brian Shucker  Modified: Shah Bhatti, 1/1/04  Implements lists for tracking threads.*/#include "mos.h"#include "tlist.h"#include "msched.h"/*void mos_tlist_init(tlist_t *list){   list->head = NULL;   list->tail = NULL;}void mos_tlist_add(tlist_t *list, thread_t *item){   //empty list case first   if(list->head == NULL) {      list->head = item;      list->tail = item;      item->next = NULL;   } else { //list has at least one element      list->tail->next = item;      list->tail = item;      item->next = NULL;   }}*/thread_t *mos_tlist_remove(tlist_t *list){   thread_t *remove_front;   remove_front = list->head;   if(remove_front != NULL) {      list->head = remove_front->next;      remove_front->next = NULL;   }   return remove_front;}/*thread_t *mos_tlist_ptrtothread(tlist_t *list){   return list->head;}*/thread_t *mos_tlist_get_thread(tlist_t *list, uint16_t id){   if(list == NULL) return NULL;   thread_t *front = list->head;   thread_t *parent = front;   //if there is only 1 element   if(front == list->tail){      if((uint16_t)front == id){	 list->head = NULL;	 list->tail = NULL;	 return front;      }      return NULL;   }     //else, front != tail, has 2 or more elements   while((front != NULL) && ((uint16_t)front != id)) {      parent = front;      front  = front->next;     }   if(front == list->head) {      list->head = front->next;      return front;   } else if(front != NULL) {      if(front == list->tail)	 list->tail = parent;      parent->next = front->next;   }   return front;}void mos_tlist_ordadd(tlist_t *list, thread_t *item){   thread_t *before;   thread_t *after;   //empty list case first   if(list->head == NULL) {      list->head = item;      list->tail = item;      item->next = NULL;      return; //and we're done   }      //insert in order   before = NULL;   after = list->head;   while(after) {      // item will be inserted before "after"      if(item->st <= after->st) {	 after->st -= item->st;	 item->next = after;	 // need to set new head	 if (before == NULL) {	    list->head = item;	 } else { //normal insert	    before->next = item;	 }	 break;      } else {	 // pass over this one, adjusting relative time	 item->st -= after->st;	 before = after;	 after = after->next;      }   }   if(after == NULL) {      // insert at tail      before->next = item;      item->next = NULL;      list->tail = item;   }}/*void mos_tlist_adjustst(tlist_t *list, uint32_t atime){   thread_t *adjust_front = list->head;     while(adjust_front) {      if(atime > adjust_front->st) {	 atime -= adjust_front->st;	 adjust_front->st = 0;	 adjust_front = adjust_front->next;      } else {	 adjust_front->st -= atime;	 break;      }   }   //if(front) {   //  if(atime > front->st)	 //atime = front->st;	 //  front->st -= atime;	 //}}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -