msgque.h

来自「VC++ 串口通信的dll. MsgQue 和SerialBase中重要的数据结」· C头文件 代码 · 共 56 行

H
56
字号
// MsgQue.h: interface for the MsgQue class.
//
//////////////////////////////////////////////////////////////////////
//File Name: MsgQue.h: implementation of the MsgQue and SafeMsgQue structure.
//References: MSDN
//Purpose: To implement a Safe Message Queue and some functions about it.

//History
//*Data          *Name      *comments.
//2008-Feb-03    Rock Li    Initialization

#if !defined(AFX_MSGQUE_H__28076F41_8497_451E_B1E2_8765051DF2AC__INCLUDED_)
#define AFX_MSGQUE_H__28076F41_8497_451E_B1E2_8765051DF2AC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#pragma pack(1)
// message queue ;pragma pack(1) means align is 1 byte;
struct tag_MsgQue
{
	unsigned char Buf[256];
	struct tag_MsgQue* next;
} ;
#pragma pack()

typedef struct tag_MsgQue* pMsgQue;
typedef struct tag_MsgQue  MsgQue;
typedef struct tag_MsgQue  MsgNode;

struct tag_SafeMsgQue
{
	pMsgQue pMsg;         //Message queue
	pMsgQue pHead;        //the head of the Message queue
	pMsgQue pTail;		  //the tail of the Message queue	
	
	HANDLE hProExitEvn;   // program exit event; it should be passed by the caller.
	HANDLE hOpSem;        // Operation semaphore; 0/1 semaphore
	HANDLE hMsgSem;       // Message(s) exits. if there is one or more messages in the queue, the falg of hMsgSem is ture.
};

typedef struct tag_SafeMsgQue* pSafeMsgQue;
typedef struct tag_SafeMsgQue  SafeMsgQue;

bool SafeMsgQueInit(HANDLE hProExit, pSafeMsgQue pSafeQue);

bool ReadOneMsg(pMsgQue* pMsg, pSafeMsgQue pSafeQue);
bool InsertOneMsg(pMsgQue pMsg, pSafeMsgQue pSafeQue);

bool LockQue(pSafeMsgQue pSafeQue);
bool UnlockQue(pSafeMsgQue pSafeQue);

#endif // !defined(AFX_MSGQUE_H__28076F41_8497_451E_B1E2_8765051DF2AC__INCLUDED_)

⌨️ 快捷键说明

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