msgobject.cpp

来自「一个更为先进的嵌入式操作系统.采用RMS线程调度算法,具有信号量等同步对象.亦包」· C++ 代码 · 共 89 行

CPP
89
字号
#include "GOS.h"
#include "msgobject.h"

LRESULT CMsgObject::SendMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
	PTHREAD pThread=GetMQThread();
	PTHREAD pCur=GetCurrentThread();

	if(pThread==pCur)
		return MsgProc(message,wParam,lParam);
	else
	{
		CMutex lock(pThread);
		MSG msg={this,message,wParam,lParam};
		pThread->InsertMessage(NULL,msgSendMessage,WPARAM(&lock),LPARAM(&msg));
		lock.LockEx(pCur,INFINITE);
		SwitchToThread();
		return msg.wParam;
	}
}

HANDLE CMsgObject::PostMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
	return GetMQThread()->InsertMessage(this,message,wParam,lParam);
}

void CMsgObject::PulseMessageEvent(HANDLE hMsg,WPARAM wParam, LPARAM lParam)
{
	PMSG pMsg=&(PMSGLE(hMsg)->msg);
	pMsg->pObj=this;
	pMsg->wParam=wParam;
	pMsg->lParam=lParam;
	GetMQThread()->PulseMessage(hMsg);
}

HANDLE CMsgObject::SetMessageEvent(int nPriority)
{
	if(!nPriority)
		nPriority=PriorityNormal;
	return GetMQThread()->InsertMessage(this,
		MakeEventMessage(nPriority),0,0);
}

BOOL CMsgObject::RemoveMessage(HANDLE hMsg)
{
	return GetMQThread()->RemoveMessage(hMsg,hMsg);
}

BOOL CMsgObject::RemoveMessage(UINT nMessage)
{
	return GetMQThread()->RemoveMessage(this,nMessage);
}

BOOL CMsgObject::RemoveAllMessage()
{
	return GetMQThread()->RemoveMessage(this);
}

HANDLE CMsgObject::SetTimer(UINT nIDEvent,UINT nElapse,int nPriority)
{
	return GetMQThread()->InsertMessage(this,
		MakeTimerMessage(nPriority),GetTickCount()+nElapse,MAKELONG(nIDEvent,nElapse));
}

void CMsgObject::SetTimer(HANDLE hMsg,UINT nElapse)
{
	MSG& msg=PMSGLE(hMsg)->msg;
	msg.wParam=GetTickCount()+nElapse;
	msg.lParam=MAKELONG(LOWORD(msg.lParam),nElapse);
}

BOOL CMsgObject::KillTimer(UINT nIDEvent)
{
	return GetMQThread()->RemoveTimerMessage(this,nIDEvent);
}

LRESULT CMsgObject::MsgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case msgGetMQThread:
		wParam=WPARAM(&g_pKernel);
	default:
		wParam=0;
	}	
	return wParam;
}

⌨️ 快捷键说明

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