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

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

?? mailbox.cpp

?? 小型的操作系統開發的原代碼
?? CPP
字號:
//***********************************************************************/
//    Author                    : Garry
//    Original Date             : Jul,24 2005
//    Module Name               : MAILBOX.CPP
//    Module Funciton           : 
//                                This module countains mailbox's implementation code.
//    Last modified Author      :
//    Last modified Date        :
//    Last modified Content     :
//                                1.
//                                2.
//    Lines number              :
//***********************************************************************/

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

//#include ".\NetCore\NETBUFF.H"

//
//Pre-declaration of static routines.
//

static DWORD GetMail(__COMMON_OBJECT*,LPVOID*,DWORD);
static DWORD SendMail(__COMMON_OBJECT*,LPVOID,DWORD);
static DWORD MailBoxTimerHandler(LPVOID);

//
//Defines a parameter object,to be used by timer handler.
//

BEGIN_DEFINE_OBJECT(__MAILBOX_TIMERH_PARAM)
    __MAILBOX*               lpMailBox;               //Point to mailbox object.
    __KERNEL_THREAD_OBJECT*  lpKernelThread;          //Point to kernel thread object who
	                                                  //set the timer.
	DWORD                    dwWakeupReason;          //Wake up reason.
	DWORD                    dwSetReason;             //Timer set reason,why set a timer.
END_DEFINE_OBJECT()

#define WAKE_UP_REASON_HAVE_MESSAGE    0x00000001     //The kernel thread is waken up by SendMail routine.
#define WAKE_UP_REASON_TIMEOUT         0x00000002     //The kernel thread is waken up by timer.

#define TIMER_SET_REASON_GETTING       0x00000003     //If a timer is set by a kernel thread wanting
                                                      //to get a mail,but the mailbox is empty,then
													  //it set this value.
#define TIMER_SET_REASON_SENDING       0x00000004     //If a timer is set by a kernel thread wanting
													  //to send a mail,but the mailbox is full,then
													  //it set a timer,and set this value.

#define MAILBOX_TIMEOUT_TIMER_ID       1024

//
//The implementation of Initialize routine.
//This routine does the following:
// 1. Set all member variables to NULL or zero;
// 2. Create two queues,getting queue and sending queue;
// 3. Initializes the queue variables to the two queues.
//

BOOL MailBoxInitialize(__COMMON_OBJECT* lpThis)
{
	__PRIORITY_QUEUE*       lpGettingQueue       = NULL;
	__PRIORITY_QUEUE*       lpSendingQueue       = NULL;
	__MAILBOX*              lpMailBox            = NULL;
	BOOL                    bResult              = FALSE;

	if(NULL == lpThis)    //Parameter check.
		return FALSE;

	lpMailBox = (__MAILBOX*)lpThis;

	lpGettingQueue = (__PRIORITY_QUEUE*)ObjectManager.CreateObject(&ObjectManager,
		NULL,
		OBJECT_TYPE_PRIORITY_QUEUE);    //Create getting queue.
	if(NULL == lpGettingQueue)          //Can not create getting queue,may has not enough memory.
		goto __TERMINAL;
	if(!lpGettingQueue->Initialize((__COMMON_OBJECT*)lpGettingQueue))  //Can not initialize it.
		goto __TERMINAL;

	lpSendingQueue = (__PRIORITY_QUEUE*)ObjectManager.CreateObject(&ObjectManager,
		NULL,
		OBJECT_TYPE_PRIORITY_QUEUE);    //Create sending queue.
	if(NULL == lpSendingQueue)
		goto __TERMINAL;
	if(!lpSendingQueue->Initialize((__COMMON_OBJECT*)lpGettingQueue))  //Initialize it.
		goto __TERMINAL;

	lpMailBox->lpMsg            = NULL;
	lpMailBox->lpGettingQueue   = lpGettingQueue;
	lpMailBox->lpSendingQueue   = lpSendingQueue;
	lpMailBox->GetMail          = GetMail;
	lpMailBox->SendMail         = SendMail;

	bResult = TRUE;


__TERMINAL:
	if(!bResult)    //The initializing process is fail.
	{
		if(NULL == lpGettingQueue)
			ObjectManager.DestroyObject(&ObjectManager,
			(__COMMON_OBJECT*)lpGettingQueue);    //Destroy getting queue.
		if(NULL == lpSendingQueue)
			ObjectManager.DestroyObject(&ObjectManager,
			(__COMMON_OBJECT*)lpSendingQueue);    //Destroy sending queue.
	}
	return bResult;
}

//
//The implementation of Uninitialize routine.
//This routine only destory the queue objects of mail box.
//

VOID MailBoxUninitialize(__COMMON_OBJECT* lpThis)
{
	__MAILBOX*                lpMailBox        = NULL;

	if(NULL == lpThis)
		return;

	lpMailBox = (__MAILBOX*)lpThis;
	ObjectManager.DestroyObject(&ObjectManager,
		(__COMMON_OBJECT*)lpMailBox->lpGettingQueue);    //Destroy the getting queue.
	ObjectManager.DestroyObject(&ObjectManager,
		(__COMMON_OBJECT*)lpMailBox->lpSendingQueue);    //Destroy the sending queue.

	return;
}

//
//The implementation of GetMail routine.
//This routine does the following:
// 1. Check if the mail box is empty;
// 2. If not empty,then get the mail,and check if there are kernel threads waiting to send mail;
// 3. If there are kernel threads waiting to send mail,then wake up the first one;
// 4. return success;
// 5. If the mail box is empty,then block the current kenrel thread;
// 6. If the dwTimeOut parameter is not zero,then set a timer;
// 7. Reschedule all kernel threads of the system;
// 8. After been waken up,check the wake up reason;
// 9. If waken up by timer,then return MAILBOX_TIMEOUT;
// 10. If waken up by SendMail routine,then get the mail,and cancel timer if
//     set;
// 11. Return appropriate value.
//

static DWORD GetMail(__COMMON_OBJECT* lpThis,LPVOID* llpMsg,DWORD dwTimeOut)
{
	__MAILBOX*                           lpMailBox                = NULL;
	__KERNEL_THREAD_OBJECT*              lpKernelThread           = NULL;
	__TIMER_OBJECT*                      lpTimerObject            = NULL;
	__MAILBOX_TIMERH_PARAM*              lpHandlerParam           = NULL;
	DWORD                                dwFlags                  = 0L;

	if((NULL == lpThis) || (NULL == llpMsg))    //Parameter check.
		return MAILBOX_FAILED;

	lpMailBox = (__MAILBOX*)lpThis;

	//ENTER_CRITICAL_SECTION();
	__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
	if(NULL != lpMailBox->lpMsg)
	{
		*llpMsg = lpMailBox->lpMsg;           //Get the message.
		lpMailBox->lpMsg = NULL;              //Clear the mailbox.
		lpKernelThread = (__KERNEL_THREAD_OBJECT*)
			lpMailBox->lpSendingQueue->GetHeaderElement(
			(__COMMON_OBJECT*)lpMailBox->lpSendingQueue,
			NULL);
		if(NULL == lpKernelThread)    //There is not any kernel thread waiting to send message.
		{
			//LEAVE_CRITICAL_SECTION();
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
			return MAILBOX_SUCCESS;
		}
		else    //There at lease one kernel thread waiting to send a mail,so wake up it.
		{
			lpKernelThread->dwThreadStatus = KERNEL_THREAD_STATUS_READY;
			KernelThreadManager.lpReadyQueue->InsertIntoQueue(
				(__COMMON_OBJECT*)KernelThreadManager.lpReadyQueue,
				(__COMMON_OBJECT*)lpKernelThread,
				lpKernelThread->dwScheduleCounter);    //Insert it into ready queue.
			//LEAVE_CRITICAL_SECTION();
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
			return MAILBOX_SUCCESS;
		}
	}
	else    //There is not any message,so must block the kernel thread.
	{
		lpKernelThread = KernelThreadManager.lpCurrentKernelThread;
		lpKernelThread->dwThreadStatus = KERNEL_THREAD_STATUS_BLOCKED;
		//LEAVE_CRITICAL_SECTION();
		if(dwTimeOut)    //Should set a timeout timer.
		{
			lpHandlerParam = (__MAILBOX_TIMERH_PARAM*)KMemAlloc(sizeof(__MAILBOX_TIMERH_PARAM),
				KMEM_SIZE_TYPE_ANY);
			if(NULL == lpHandlerParam)    //Can not allocate memory.
			{
				lpKernelThread->dwThreadStatus = KERNEL_THREAD_STATUS_RUNNING;
				//LEAVE_CRITICAL_SECTION();
				__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
				return MAILBOX_NO_RESOURCE;
			}
			lpHandlerParam->lpMailBox        = lpMailBox;
			lpHandlerParam->lpKernelThread   = lpKernelThread;
			lpHandlerParam->dwWakeupReason   = WAKE_UP_REASON_HAVE_MESSAGE;
			lpHandlerParam->dwSetReason      = TIMER_SET_REASON_GETTING;

			lpTimerObject = (__TIMER_OBJECT*)System.SetTimer((__COMMON_OBJECT*)&System,
				lpKernelThread,
				MAILBOX_TIMEOUT_TIMER_ID,
				dwTimeOut,
				MailBoxTimerHandler,
				lpHandlerParam,
				TIMER_FLAGS_ONCE);

			if(NULL == lpTimerObject)    //Can not set a timer,maybe has not enough memory.
			{
				lpKernelThread->dwThreadStatus = KERNEL_THREAD_STATUS_RUNNING;
				//LEAVE_CRITICAL_SECTION();
				__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
				KMemFree((LPVOID)lpHandlerParam,KMEM_SIZE_TYPE_ANY,0L);
				return MAILBOX_NO_RESOURCE;
			}
		}
		lpMailBox->lpGettingQueue->InsertIntoQueue((__COMMON_OBJECT*)lpMailBox->lpGettingQueue,
			(__COMMON_OBJECT*)lpKernelThread,
			0L);    //Insert into the getting queue.
		//LEAVE_CRITICAL_SECTION();
		__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
		KernelThreadManager.ScheduleFromProc(&lpKernelThread->KernelThreadContext);

		//
		//The following code is executed after this kernel thread is waken up.
		//
		//ENTER_CRITICAL_SECTION();
		__ENTER_CRITICAL_SECTION(NULL,dwFlags);
		if(!dwTimeOut)    //Have not set a timer.
		{
			*llpMsg = lpMailBox->lpMsg;
			lpMailBox->lpMsg = NULL;
			//LEAVE_CRITICAL_SECTION();
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
			return MAILBOX_SUCCESS;
		}
		//
		//The following code deals with the situation that a timer has been set.
		//

		switch (lpHandlerParam->dwWakeupReason)
		{
		case WAKE_UP_REASON_HAVE_MESSAGE:  //In this case,we should cancel timer first.
			*llpMsg = lpMailBox->lpMsg;
			lpMailBox->lpMsg = NULL;
			System.CancelTimer((__COMMON_OBJECT*)&System,
				(__COMMON_OBJECT*)lpTimerObject);
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);  //NOTE : This is modified later.
			KMemFree((LPVOID)lpHandlerParam,KMEM_SIZE_TYPE_ANY,0L);
			return MAILBOX_SUCCESS;
			break;
		case WAKE_UP_REASON_TIMEOUT:
			//LEAVE_CRITICAL_SECTION();
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
			KMemFree((LPVOID)lpHandlerParam,KMEM_SIZE_TYPE_ANY,0L);
			return MAILBOX_TIMEOUT;
		default:
			//LEAVE_CRITICAL_SECTION();
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
			KMemFree((LPVOID)lpHandlerParam,KMEM_SIZE_TYPE_ANY,0L);
			return MAILBOX_FAILED;
		}
	}
	return 0L;
}

//
//The implementation of SendMail.
//This routine does the following:
// 1.
// 

static DWORD SendMail(__COMMON_OBJECT* lpThis,LPVOID lpMsg,DWORD dwTimeOut)
{
	__MAILBOX*                           lpMailBox       = NULL;
	__KERNEL_THREAD_OBJECT*              lpKernelThread  = NULL;
	DWORD                                dwFlags         = 0L;

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

	lpMailBox = (__MAILBOX*)lpThis;
	//ENTER_CRITICAL_SECTION();
	__ENTER_CRITICAL_SECTION(NULL,dwFlags);
	if(NULL == lpMailBox->lpMsg)
	{
		lpMailBox->lpMsg = lpMsg;    //Send the mail.
		lpKernelThread = (__KERNEL_THREAD_OBJECT*)
			lpMailBox->lpGettingQueue->GetHeaderElement(
			(__COMMON_OBJECT*)lpMailBox->lpGettingQueue,
			NULL);
		if(NULL == lpKernelThread)    //There is not any kernel thread waiting for message.
		{
			//LEAVE_CRITICAL_SECTION();
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
			return MAILBOX_SUCCESS;
		}
		else               //There is one kernel thread waiting for message at least.
		{
			lpKernelThread->dwThreadStatus = KERNEL_THREAD_STATUS_READY;
			KernelThreadManager.lpReadyQueue->InsertIntoQueue(
				(__COMMON_OBJECT*)KernelThreadManager.lpReadyQueue,
				(__COMMON_OBJECT*)lpKernelThread,
				lpKernelThread->dwScheduleCounter);    //Wake up the kernel thread.
			//LEAVE_CRITICAL_SECTION();
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
			return MAILBOX_SUCCESS;
		}
	}
	else    //The mailbox is full.
	{
		//LEAVE_CRITICAL_SECTION();
		__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
		return MAILBOX_FAILED;
	}
}

//
//The implementation of MailBoxTimerHandler.
//This routine is called by timer object,to indicate the timeout event,and this routine
//runs at the interrupt context.
//It does the following:
// 1. Check the reason that kernel thread set a timer;
// 2. If the reason is to timeout the send event,then try to wake up the sending thread;
// 3. If the reason is to timeout the get event,then try to wake up a getting thread;
// 4. Set the wake up reason correctly,to tell the target kernel thread proper reason
//    that it waken up.
//

static DWORD MailBoxTimerHandler(LPVOID lpParam)
{
	__MAILBOX_TIMERH_PARAM*             lpHandlerParam      = NULL;
	__PRIORITY_QUEUE*                   lpWaitingQueue      = NULL;
	__KERNEL_THREAD_OBJECT*             lpKernelThread      = NULL;
	
	if(NULL == lpParam)
		return 0L;
	lpHandlerParam = (__MAILBOX_TIMERH_PARAM*)lpParam;
	switch(lpHandlerParam->dwSetReason)
	{
	case TIMER_SET_REASON_GETTING:
		lpWaitingQueue = lpHandlerParam->lpMailBox->lpGettingQueue;
		lpKernelThread = lpHandlerParam->lpKernelThread;
		if(!lpWaitingQueue->DeleteFromQueue((__COMMON_OBJECT*)lpWaitingQueue,
			(__COMMON_OBJECT*)lpKernelThread))    //The kernel thread maybe waken up.
			return 0L;
		lpKernelThread->dwThreadStatus = KERNEL_THREAD_STATUS_READY;  //Wake up the thread.
		KernelThreadManager.lpReadyQueue->InsertIntoQueue(
			(__COMMON_OBJECT*)KernelThreadManager.lpReadyQueue,
			(__COMMON_OBJECT*)lpKernelThread,
			lpKernelThread->dwScheduleCounter);
		lpHandlerParam->dwWakeupReason = WAKE_UP_REASON_TIMEOUT;
		return 1L;
		break;
	case TIMER_SET_REASON_SENDING:
		break;
	default:
		return 0L;
	}
	return 0L;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美电视剧免费全集观看| 亚洲成精国产精品女| 91在线一区二区三区| 亚洲美女在线一区| 欧美在线播放高清精品| 亚洲va国产va欧美va观看| 欧美一区二区播放| 国产在线播精品第三| 国产精品三级av| 一本到不卡免费一区二区| 午夜亚洲福利老司机| 日韩亚洲电影在线| 国产精品亚洲视频| 亚洲猫色日本管| 欧美精品第一页| 狠狠色丁香久久婷婷综合_中 | 美美哒免费高清在线观看视频一区二区| 日韩欧美在线不卡| 国产99久久久久| 亚洲综合在线观看视频| 制服丝袜亚洲网站| 国产精品1区二区.| 一区二区在线观看视频在线观看| 欧美老肥妇做.爰bbww| 激情深爱一区二区| 亚洲精品国产精品乱码不99| 777久久久精品| 成人久久18免费网站麻豆| 亚洲一区二区av在线| 久久―日本道色综合久久| 色综合色综合色综合| 免费人成网站在线观看欧美高清| 国产三级一区二区| 欧美午夜在线观看| 激情综合色综合久久综合| 中文字幕视频一区| 欧美大胆人体bbbb| 色综合久久66| 国产一区二区调教| 亚洲午夜免费视频| 国产午夜久久久久| 欧美三电影在线| 国产精品1区2区| 首页欧美精品中文字幕| 中文字幕一区二区视频| 欧美一区二区三区免费视频| 99视频一区二区| 黄色小说综合网站| 亚洲高清免费在线| 国产精品国产三级国产普通话蜜臀 | 中文一区二区完整视频在线观看| 欧美日韩中文一区| 成人涩涩免费视频| 麻豆国产精品一区二区三区| 亚洲人成7777| 国产午夜亚洲精品不卡| 欧美一区二区三区在线| 色综合视频在线观看| 国产精品1区二区.| 免费观看成人鲁鲁鲁鲁鲁视频| 亚洲精品中文在线| 国产拍欧美日韩视频二区| 宅男噜噜噜66一区二区66| 91麻豆精品一区二区三区| 久久99久国产精品黄毛片色诱| 亚洲一区二区偷拍精品| 国产精品天天看| 精品国产一区二区三区久久影院| 欧美喷潮久久久xxxxx| 一本色道久久综合亚洲精品按摩| 成人午夜视频在线| 极品少妇xxxx精品少妇偷拍| 亚洲h在线观看| 亚洲啪啪综合av一区二区三区| 国产午夜精品一区二区三区视频 | 精品99一区二区三区| 欧美喷水一区二区| 欧美亚洲国产一卡| 99久久精品国产精品久久| 豆国产96在线|亚洲| 国产一区二区导航在线播放| 免费观看在线综合| 日韩精品一区第一页| 亚洲一区精品在线| 亚洲欧洲综合另类在线| 亚洲欧洲精品成人久久奇米网| 久久久久久久综合色一本| 精品国产91九色蝌蚪| 欧美一区二区日韩| 在线播放91灌醉迷j高跟美女 | 2020国产精品| 欧美一区二区三区免费大片| 在线播放国产精品二区一二区四区| 在线看不卡av| 91久久精品国产91性色tv| 91网上在线视频| 99国产精品国产精品久久| 成人午夜私人影院| 成人精品在线视频观看| 成人丝袜18视频在线观看| 成人午夜视频在线| 成人av电影在线| 99久久综合狠狠综合久久| av在线这里只有精品| 北岛玲一区二区三区四区| a美女胸又www黄视频久久| 99久久免费精品| 91蜜桃免费观看视频| 欧美自拍偷拍一区| 欧美午夜片在线看| 777xxx欧美| 精品少妇一区二区三区免费观看 | 久久久国产午夜精品| 国产亚洲一区二区三区在线观看| 久久精品网站免费观看| 日本一二三四高清不卡| 国产精品美女久久久久aⅴ| 国产精品家庭影院| 一区二区三区在线视频播放| 亚洲制服丝袜一区| 日本不卡在线视频| 狠狠色综合日日| 成人毛片在线观看| 色妹子一区二区| 欧美美女bb生活片| 日韩三级高清在线| 久久精品欧美日韩精品| 中文字幕一区二区三区色视频| 18欧美亚洲精品| 亚洲香蕉伊在人在线观| 日韩国产高清在线| 国内外成人在线视频| 丁香六月久久综合狠狠色| 91在线国产观看| 欧美日韩国产首页在线观看| 日韩欧美色电影| 国产亲近乱来精品视频| 亚洲欧美日韩国产综合在线 | 成人av网站免费观看| 在线视频国内自拍亚洲视频| 91麻豆精品国产91久久久| 久久女同性恋中文字幕| 亚洲欧洲另类国产综合| 天天综合日日夜夜精品| 美女视频黄 久久| 岛国精品一区二区| 91成人免费在线视频| 日韩欧美在线观看一区二区三区| 欧美激情综合网| 亚洲午夜免费福利视频| 久久国产精品一区二区| 菠萝蜜视频在线观看一区| 欧美日韩情趣电影| 国产日韩欧美制服另类| 一区二区三区免费看视频| 久久精品国产99国产精品| 99视频一区二区| 日韩免费视频一区二区| 国产精品久久久久7777按摩| 日韩国产欧美在线播放| 国产不卡在线一区| 欧美日韩精品欧美日韩精品一综合| 精品国产sm最大网站免费看| 樱桃视频在线观看一区| 久久er99热精品一区二区| 99v久久综合狠狠综合久久| 69av一区二区三区| 国产精品卡一卡二| 美国三级日本三级久久99| 91老师片黄在线观看| 日韩欧美一区电影| 亚洲女人的天堂| 国产一二精品视频| 欧美日韩一区高清| 国产精品拍天天在线| 蜜桃精品视频在线| 色综合色综合色综合| 国产亚洲短视频| 日韩精品欧美成人高清一区二区| 成人免费视频免费观看| 欧美一区二区三区在| 亚洲精品你懂的| 国产精品一区一区三区| 欧美高清精品3d| 亚洲人一二三区| 国产又粗又猛又爽又黄91精品| 欧美日韩成人在线| 中文字幕亚洲精品在线观看| 国产专区综合网| 欧美精品在线视频| 亚洲日本免费电影| 国产精品996| 欧美www视频| 三级不卡在线观看| 在线观看av一区| 国产精品久久久久一区| 国内外成人在线| 日韩丝袜情趣美女图片| 亚洲成人免费观看| 色综合久久综合网97色综合 |