亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? system.cpp

?? 小型的操作系統開發的原代碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
//***********************************************************************/
//    Author                    : Garry
//    Original Date             : Nov,06 2004
//    Module Name               : system.cpp
//    Module Funciton           : 
//                                This module countains system mechanism releated objects's
//                                implementation..
//                                Including the following aspect:
//                                1. Interrupt object and interrupt management code;
//                                2. Timer object and timer management code;
//                                3. System level parameters management coee,such as
//                                   physical memory,system time,etc;
//                                4. Other system mechanism releated objects.
//
//                                ************
//                                This file is one of the most important file of Hello China.
//                                ************
//    Last modified Author      :
//    Last modified Date        :
//    Last modified Content     :
//                                1.
//                                2.
//    Lines number              :
//***********************************************************************/

#ifndef __STDAFX_H__
#include "..\INCLUDE\StdAfx.h"
#endif

__PERF_RECORDER  TimerIntPr = {
	U64_ZERO,
	U64_ZERO,
	U64_ZERO,
	U64_ZERO};                  //Performance recorder object used to mesure
                                //the performance of timer interrupt.

//
//TimerInterruptHandler routine.
//The following routine is the most CRITICAL routine of kernel of Hello China.
//The routine does the following:
// 1. Schedule timer object;
// 2. Update the system level variables,such as dwClockTickCounter;
// 3. Schedule kernel thread(s).
//

static BOOL TimerInterruptHandler(LPVOID lpEsp,LPVOID)
{
	DWORD                     dwPriority        = 0L;
	__TIMER_OBJECT*           lpTimerObject     = 0L;
	__KERNEL_THREAD_MESSAGE   Msg                   ;
	__PRIORITY_QUEUE*         lpTimerQueue      = NULL;
	__PRIORITY_QUEUE*         lpSleepingQueue   = NULL;
	__KERNEL_THREAD_OBJECT*   lpKernelThread    = NULL;
	DWORD                     dwFlags           = 0L;

	if(NULL == lpEsp)    //Parameter check.
		return TRUE;

	if(System.dwClockTickCounter == System.dwNextTimerTick)     //Should schedule timer.
	{
		lpTimerQueue = System.lpTimerQueue;
		lpTimerObject = (__TIMER_OBJECT*)lpTimerQueue->GetHeaderElement(
			(__COMMON_OBJECT*)lpTimerQueue,
			&dwPriority);
		if(NULL == lpTimerObject)
			goto __CONTINUE_1;
		dwPriority = MAX_DWORD_VALUE - dwPriority;
		while(dwPriority <= System.dwNextTimerTick)    //Strictly speaking,the dwPriority
			                                           //variable must EQUAL System.dw-
													   //NextTimerTick,but in the implement-
													   //ing of the current version,there
													   //may be some error exists,so we assume
													   //dwPriority equal or less than dwNext-
													   //TimerTic.
		{
			if(NULL == lpTimerObject->DirectTimerHandler)  //Send a message to the kernel thread.
			{
				Msg.wCommand = KERNEL_MESSAGE_TIMER;
				Msg.dwParam  = lpTimerObject->dwTimerID;
				KernelThreadManager.SendMessage(
					(__COMMON_OBJECT*)lpTimerObject->lpKernelThread,
					&Msg);
				//PrintLine("Send a timer message to kernel thread.");
			}
			else
			{
				lpTimerObject->DirectTimerHandler(
					lpTimerObject->lpHandlerParam);    //Call the associated handler.
			}

			switch(lpTimerObject->dwTimerFlags)
			{
			case TIMER_FLAGS_ONCE:        //Delete the timer object processed just now.
				ObjectManager.DestroyObject(&ObjectManager,
					(__COMMON_OBJECT*)lpTimerObject);
				break;
			case TIMER_FLAGS_ALWAYS:    //Re-insert the timer object into timer queue.
				dwPriority  = lpTimerObject->dwTimeSpan;
				dwPriority /= SYSTEM_TIME_SLICE;
				dwPriority += System.dwClockTickCounter;
				dwPriority  = MAX_DWORD_VALUE - dwPriority;
				lpTimerQueue->InsertIntoQueue((__COMMON_OBJECT*)lpTimerQueue,
					(__COMMON_OBJECT*)lpTimerObject,
					dwPriority);
				break;
			default:
				break;
			}

			lpTimerObject = (__TIMER_OBJECT*)lpTimerQueue->GetHeaderElement(
				(__COMMON_OBJECT*)lpTimerQueue,
				&dwPriority);    //Check another timer object.
			if(NULL == lpTimerObject)
				break;
			dwPriority = MAX_DWORD_VALUE - dwPriority;
		}

		if(NULL == lpTimerObject)  //There is no timer object in queue.
		{
			__ENTER_CRITICAL_SECTION(NULL,dwFlags);
			System.dwNextTimerTick = 0L;
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
		}
		else
		{
			__ENTER_CRITICAL_SECTION(NULL,dwFlags);
			System.dwNextTimerTick = dwPriority;    //Update the next timer tick counter.
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
			dwPriority = MAX_DWORD_VALUE - dwPriority;
			lpTimerQueue->InsertIntoQueue((__COMMON_OBJECT*)lpTimerQueue,
				(__COMMON_OBJECT*)lpTimerObject,
				dwPriority);
		}
	}

__CONTINUE_1:

	//
	//The following code wakes up all kernel thread(s) whose status is SLEEPING and
	//the time it(then) set is out.
	//
	if(System.dwClockTickCounter == KernelThreadManager.dwNextWakeupTick)  //There must existes
		                                                                   //kernel thread(s) to
																		   //be wake up.
	{
		lpSleepingQueue = KernelThreadManager.lpSleepingQueue;
		lpKernelThread  = (__KERNEL_THREAD_OBJECT*)lpSleepingQueue->GetHeaderElement(
			(__COMMON_OBJECT*)lpSleepingQueue,
			&dwPriority);
		while(lpKernelThread)
		{
			dwPriority = MAX_DWORD_VALUE - dwPriority;  //Now,dwPriority countains the tick
			                                            //counter value.
			if(dwPriority > System.dwClockTickCounter)
				break;    //This kernel thread should not be wake up.
			lpKernelThread->dwThreadStatus = KERNEL_THREAD_STATUS_READY;
			KernelThreadManager.AddReadyKernelThread(
				(__COMMON_OBJECT*)&KernelThreadManager,
				lpKernelThread);  //Insert the waked up kernel thread into ready queue.

			lpKernelThread = (__KERNEL_THREAD_OBJECT*)lpSleepingQueue->GetHeaderElement(
				(__COMMON_OBJECT*)lpSleepingQueue,
				&dwPriority);  //Check next kernel thread in sleeping queue.
		}
		if(NULL == lpKernelThread)
		{
			__ENTER_CRITICAL_SECTION(NULL,dwFlags);
			KernelThreadManager.dwNextWakeupTick = 0L;
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
		}
		else
		{
			__ENTER_CRITICAL_SECTION(NULL,dwFlags);
			KernelThreadManager.dwNextWakeupTick = dwPriority;
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
			dwPriority = MAX_DWORD_VALUE - dwPriority;
			lpSleepingQueue->InsertIntoQueue((__COMMON_OBJECT*)lpSleepingQueue,
				(__COMMON_OBJECT*)lpKernelThread,
				dwPriority);
		}
	}

	goto __TERMINAL;

__TERMINAL:
	__ENTER_CRITICAL_SECTION(NULL,dwFlags);
	System.dwClockTickCounter ++;    //Update the system clock interrupt counter.
	__LEAVE_CRITICAL_SECTION(NULL,dwFlags);

	//KernelThreadManager.ScheduleFromInt((__COMMON_OBJECT*)&KernelThreadManager,
	//	lpEsp);

	return TRUE;
}


//
//The implementation of ConnectInterrupt routine of Interrupt Object.
//The routine do the following:
// 1. Insert the current object into interrupt object array(maintenanced by system object);
// 2. Set the object's data members correctly.
//

__COMMON_OBJECT* BOOL ConnectInterrupt(__COMMON_OBJECT*     lpThis,
							 __INTERRUPT_HANDLER  lpInterruptHandler,
							 LPVOID               lpHandlerParam,
							 UCHAR                ucVector,
							 UCHAR                ucReserved1,
							 UCHAR                ucReserved2,
							 UCHAR                ucInterruptMode,
							 BOOL                 bIfShared,
							 DWORD                dwCPUMask)
{
	__INTERRUPT_OBJECT*      lpInterrupt          = NULL;
	__INTERRUPT_OBJECT*      lpObjectRoot         = NULL;
	__SYSTEM*                lpSystem             = NULL;
	DWORD                    dwFlags              = 0L;

	if((NULL == lpThis) || (NULL == lpInterruptHandler))    //Parameters valid check.
		return NULL;

	if(ucVector >= MAX_INTERRUPT_VECTOR)                    //Impossible!!!
		return NULL;

	lpInterrupt = (__INTERRUPT_OBJECT*)
		ObjectManager.CreateObject(&ObjectManager,NULL,OBJECT_TYPE_INTERRUPT);
	if(NULL == lpInterrupt)    //Failed to create interrupt object.
		return FALSE;
	if(!lpInterrupt->Initialize((__COMMON_OBJECT*)lpInterrupt))  //Failed to initialize.
		return FALSE;

	lpInterrupt->lpPrevInterruptObject = NULL;
	lpInterrupt->lpNextInterruptObject = NULL;
	lpInterrupt->InterruptHandler      = lpInterruptHandler;
	lpInterrupt->lpHandlerParam        = lpHandlerParam;
	lpInterrupt->ucVector              = ucVector;

	__ENTER_CRITICAL_SECTION(NULL,dwFlags);
	lpObjectRoot = lpSystem->lpInterruptVector[ucVector];
	if(NULL == lpObjectRoot)    //If this is the first interrupt object of the vector.
	{
		System.lpInterruptVector[ucVector]  = lpInterrupt;
	}
	else
	{
		lpInterrupt->lpNextInterruptObject  = lpObjectRoot;
		lpObjectRoot->lpPrevInterruptObject = lpInterrupt;
		System.lpInterruptVector[ucVector]  = lpInterrupt;
	}
	//LEAVE_CRITICAL_SECTION();
	__LEAVE_CRITICAL_SECTION(NULL,dwFlags);

	return (__COMMON_OBJECT*)lpInterrupt;
}

//
//The implementation of DisconnectInterrupt.
//

static VOID DisconnectInterrupt(__COMMON_OBJECT* lpThis,
								__COMMON_OBJECT* lpInterrupt)
{
	__INTERRUPT_OBJECT*   lpIntObject    = NULL;
	__SYSTEM*             lpSystem       = NULL;
	UCHAR                 ucVector       = NULL;
	DWORD                 dwFlags        = 0L;

	if((NULL == lpThis) || (NULL == lpInterrupt)) //Parameters check.
		return;

	lpSystem = (__SYSTEM*)lpThis;
	lpIntObject = (__INTERRUPT_OBJECT*)lpInterrupt;
	ucVector    = lpIntObject->ucVector;

	//ENTER_CRITICAL_SECTION();
	__ENTER_CRITICAL_SECTION(NULL,dwFlags);
	if(NULL == lpIntObject->lpPrevInterruptObject)  //This is the first interrupt object.
	{
		lpSystem->lpInterruptVector[ucVector] = lpIntObject->lpNextInterruptObject;
		if(NULL != lpIntObject->lpNextInterruptObject) //Is not the last object.
		{
			lpIntObject->lpNextInterruptObject->lpPrevInterruptObject = NULL;
		}
	}
	else    //This is not the first object.
	{
		lpIntObject->lpPrevInterruptObject->lpNextInterruptObject = lpIntObject->lpNextInterruptObject;
		if(NULL != lpIntObject->lpNextInterruptObject)
		{
			lpIntObject->lpNextInterruptObject->lpPrevInterruptObject = lpIntObject->lpPrevInterruptObject;
		}
	}
	//LEAVE_CRITICAL_SECTION();
	__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
	return;
}

//
//The implementation of Initialize routine of interrupt object.
//

BOOL InterruptInitialize(__COMMON_OBJECT* lpThis)
{
	__INTERRUPT_OBJECT*    lpInterrupt = NULL;

	if(NULL == lpThis)
		return FALSE;

	lpInterrupt = (__INTERRUPT_OBJECT*)lpThis;
	lpInterrupt->lpPrevInterruptObject = NULL;
	lpInterrupt->lpNextInterruptObject = NULL;
	lpInterrupt->InterruptHandler      = NULL;
	lpInterrupt->lpHandlerParam        = NULL;
	lpInterrupt->ucVector              = 0L;
	return TRUE;
}

//
//The implementation of Uninitialize of interrupt object.
//This routine does nothing.
//

VOID InterruptUninitialize(__COMMON_OBJECT* lpThis)
{
	return;
}


//
//The implementation of timer object.
//

BOOL TimerInitialize(__COMMON_OBJECT* lpThis)    //Initializing routine of timer object.
{
	__TIMER_OBJECT*     lpTimer  = NULL;
	
	if(NULL == lpThis)
		return FALSE;

	lpTimer = (__TIMER_OBJECT*)lpThis;
	lpTimer->dwTimerID    = 0L;
	lpTimer->dwTimeSpan   = 0L;
	lpTimer->lpKernelThread      = NULL;
	lpTimer->lpHandlerParam      = NULL;
	lpTimer->DirectTimerHandler  = NULL;

	return TRUE;
}

//
//Uninitializing routine of timer object.
//

VOID TimerUninitialize(__COMMON_OBJECT* lpThis)
{
	return;
}

//-----------------------------------------------------------------------------------
//
//              The implementation of system object.
//
//------------------------------------------------------------------------------------

//
//Initializing routine of system object.
//The routine do the following:
// 1. Create a priority queue,to be used as lpTimerQueue,countains the timer object;
// 2. Create an interrupt object,as TIMER interrupt object;
// 3. Initialize system level variables,such as dwPhysicalMemorySize,etc.
//

static BOOL SystemInitialize(__COMMON_OBJECT* lpThis)
{
	__SYSTEM*            lpSystem         = NULL;
	__PRIORITY_QUEUE*    lpPriorityQueue  = NULL;
	__INTERRUPT_OBJECT*  lpIntObject      = NULL;
	BOOL                 bResult          = FALSE;
	DWORD                dwFlags          = 0L;

	if(NULL == lpThis)
		return FALSE;

	lpSystem = (__SYSTEM*)lpThis;
	lpPriorityQueue = (__PRIORITY_QUEUE*)ObjectManager.CreateObject(&ObjectManager,
		NULL,
		OBJECT_TYPE_PRIORITY_QUEUE);

	if(NULL == lpPriorityQueue)  //Failed to create priority queue.
		return FALSE;

	if(!lpPriorityQueue->Initialize((__COMMON_OBJECT*)lpPriorityQueue))  //Failed to initialize
		                                                                 //priority queue.
		goto __TERMINAL;
	lpSystem->lpTimerQueue = lpPriorityQueue;

	lpIntObject = (__INTERRUPT_OBJECT*)ObjectManager.CreateObject(
		&ObjectManager,
		NULL,
		OBJECT_TYPE_INTERRUPT);
	if(NULL == lpIntObject)
		goto __TERMINAL;

	bResult = lpIntObject->Initialize((__COMMON_OBJECT*)lpIntObject);
	if(!bResult)
		goto __TERMINAL;

	lpIntObject->ucVector = INTERRUPT_VECTOR_TIMER;
	lpIntObject->lpHandlerParam = NULL;
	lpIntObject->InterruptHandler = TimerInterruptHandler;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色美美综合视频| 久久久精品黄色| 亚洲国产精品久久久男人的天堂| 成人免费观看av| 国产精品免费网站在线观看| 国产精品中文字幕一区二区三区| 精品99久久久久久| 国产91在线观看| 亚洲欧洲在线观看av| 97久久精品人人做人人爽50路| 欧美国产一区视频在线观看| 91在线免费看| 亚洲一区成人在线| 欧美电影免费观看高清完整版在线观看| 五月天一区二区| 日韩欧美激情四射| 国产成人免费xxxxxxxx| 亚洲色图清纯唯美| 欧美丰满一区二区免费视频| 激情国产一区二区| 亚洲精选免费视频| 日韩一区二区在线播放| 99久精品国产| 日韩国产欧美视频| 国产精品久久久久久久久动漫| 色狠狠色狠狠综合| 美女精品自拍一二三四| 亚洲一区二区三区小说| 精品福利av导航| 欧美日韩在线免费视频| 91一区二区在线| 久久精品99国产精品日本| 亚洲精选免费视频| 国产日韩欧美在线一区| 91精品麻豆日日躁夜夜躁| va亚洲va日韩不卡在线观看| 激情成人综合网| 日韩av在线播放中文字幕| 一区二区三区中文字幕在线观看| 久久免费的精品国产v∧| 日韩区在线观看| 日韩欧美一二区| 精品国产污网站| 精品国产亚洲一区二区三区在线观看| 欧美日韩一区二区三区在线| 成人免费高清在线| av高清久久久| 色偷偷一区二区三区| 在线区一区二视频| 欧美性受xxxx| 在线不卡免费av| 91精品免费在线观看| 制服视频三区第一页精品| 综合色天天鬼久久鬼色| 亚洲最新视频在线观看| 亚洲大尺度视频在线观看| 免费成人在线观看视频| 国产乱码精品一品二品| 国产福利精品导航| 日本高清不卡一区| 日韩欧美一级片| 国产精品二三区| 免费人成在线不卡| 成人性生交大片免费看在线播放 | 欧美日韩在线观看一区二区 | 国产欧美日本一区二区三区| 国产精品初高中害羞小美女文| 夜色激情一区二区| 国产在线不卡一卡二卡三卡四卡| av激情综合网| 精品1区2区在线观看| 亚洲风情在线资源站| 国产不卡一区视频| 欧美高清性hdvideosex| 亚洲天天做日日做天天谢日日欢 | 久久久五月婷婷| 亚洲成人7777| 91丝袜美腿高跟国产极品老师 | 亚洲欧美日韩在线播放| 国产suv一区二区三区88区| 5566中文字幕一区二区电影| 国产精品欧美经典| 国产中文一区二区三区| 欧美日本一区二区三区| 亚洲视频在线观看一区| 国产真实精品久久二三区| 欧美三级资源在线| 亚洲午夜在线视频| 91国在线观看| 国产精品成人一区二区三区夜夜夜 | 欧美午夜精品一区二区蜜桃| 国产精品久久久久一区二区三区共| 精品中文av资源站在线观看| 69堂成人精品免费视频| 亚洲成av人影院| 91.xcao| 国产一区二区在线免费观看| 欧美sm极限捆绑bd| 国产麻豆视频精品| 久久久久久久av麻豆果冻| 激情欧美日韩一区二区| 欧美高清一级片在线观看| 成人午夜激情片| 亚洲视频中文字幕| 欧美日韩免费高清一区色橹橹 | 亚洲国产视频在线| 欧美一区二区日韩一区二区| 日本色综合中文字幕| 久久久久青草大香线综合精品| 国产不卡在线一区| 亚洲国产日韩一区二区| 精品少妇一区二区三区免费观看 | 色综合久久久久久久| 免费人成黄页网站在线一区二区| 欧美大片一区二区| 99re热这里只有精品视频| 日韩精彩视频在线观看| 国产精品久久午夜| 91麻豆精品国产91久久久使用方法| 免费欧美高清视频| 一区二区三区在线免费| 久久综合九色综合欧美98| 欧洲一区在线观看| 国内外成人在线视频| 日韩理论片在线| 久久综合国产精品| 欧美美女激情18p| 91久久精品国产91性色tv| 久久99九九99精品| 午夜精品视频一区| 亚洲最大的成人av| 成人欧美一区二区三区白人| 亚洲精品一区二区三区四区高清| 欧美精品少妇一区二区三区| 97久久久精品综合88久久| 国产v日产∨综合v精品视频| 麻豆一区二区99久久久久| 亚洲123区在线观看| 亚洲特黄一级片| 亚洲美女偷拍久久| 成人欧美一区二区三区视频网页| 国产精品少妇自拍| 中文字幕欧美一区| 亚洲视频网在线直播| 亚洲特黄一级片| 亚洲国产精品久久人人爱| 亚洲国产精品影院| 综合欧美亚洲日本| 尤物av一区二区| 亚洲一区中文日韩| 丝袜诱惑亚洲看片| 久久97超碰国产精品超碰| 国产成人一区在线| 91香蕉国产在线观看软件| 在线国产电影不卡| 日韩欧美国产综合| 国产精品区一区二区三| 亚洲免费电影在线| 免费人成精品欧美精品| 成人午夜碰碰视频| 欧美日韩激情在线| 久久品道一品道久久精品| 国产精品乱码久久久久久| 亚洲精品免费在线| 美女爽到高潮91| 91麻豆精品一区二区三区| 日韩欧美国产综合| 尤物av一区二区| 成人亚洲精品久久久久软件| 欧美久久久久中文字幕| 久久精品视频免费观看| 亚洲成人精品在线观看| 国产成人高清在线| 欧美日韩高清影院| 日韩美女啊v在线免费观看| 六月丁香综合在线视频| 欧美日韩免费视频| 日韩美女精品在线| 韩国理伦片一区二区三区在线播放| 日本道色综合久久| 亚洲三级电影全部在线观看高清| 国产在线一区二区| 日韩欧美国产小视频| 奇米影视在线99精品| 欧美日韩一区二区在线观看视频| 亚洲欧美视频在线观看视频| 97精品国产97久久久久久久久久久久| 91麻豆精品国产自产在线| 中文字幕中文在线不卡住| 久久国产人妖系列| 国产欧美日韩麻豆91| 色噜噜狠狠一区二区三区果冻| 亚洲电影一级片| 欧美成人性战久久| 成人白浆超碰人人人人| 亚洲视频在线观看三级| 欧美日韩国产123区| 国产精品99久久不卡二区| 亚洲色图一区二区三区| 欧美日韩精品一区二区在线播放 |