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

📄 modify_pri.c

📁 虚拟地址空间基于文件的操作系统
💻 C
字号:
#include"kernel.h"

void modify_thread_priority(int thread_id,int new_priority)
{
	int ready_id,run_id;
	struct thread *t,*ready_t,*run_t;

	if((thread_id<0)||(thread_id>=THREAD_NUMBER))
		return;
	t=&(os->thread[thread_id]);
	switch(t->state){
	case READY:
		if(os->thread_heap.run_thread_number>0){
			run_id=os->thread_heap.run_heap[0].thread;
			run_t=&(os->thread[run_id]);
			if(new_priority<run_t->priority){
				remove_from_heap(thread_id);
				t->priority=new_priority;
				insert_into_heap(thread_id);
				break;
			}
		}
		if(new_priority>t->priority){
			t->priority=new_priority;
			ready_heap_down_deal(thread_id);
			break;
		}
		 if(new_priority<t->priority){
			t->priority=new_priority;
			ready_heap_up_deal(thread_id);
			break;
		}
		break;
	case RUN:
		if(os->thread_heap.ready_thread_number>0){
			ready_id=os->thread_heap.ready_heap[0].thread;
			ready_t=&(os->thread[ready_id]);
			if(new_priority>ready_t->priority){
				remove_from_heap(thread_id);
				t->priority=new_priority;
				insert_into_heap(thread_id);
				break;
			}
		}
		if(new_priority>t->priority){
			t->priority=new_priority;
			run_heap_up_deal(thread_id);
			break;
		}
		if(new_priority<t->priority){
			t->priority=new_priority;
			run_heap_down_deal(thread_id);
			break;
		}
		break;
	default:
		t->priority=new_priority;
		break;
	}
	return;
}

⌨️ 快捷键说明

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