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

📄 msgque.h

📁 这是实际项目中的一个串口通信程序. Makefile通过开关, 可使此程序适用于 Linux 和嵌入式 ARM Linux. 代码注释较多. 是学习UART或Serail Port 通信的一个好例子.
💻 H
字号:
#ifdef __cplusplus
extern {
#endif


// MsgQue.h: interface for the MsgQue class.

//////////////////////////////////////////////////////////////////////
//File Name: MsgQue.h: implementation of the MsgQue and SafeMsgQue structure.
//References: man in linux
//Purpose: To implement a Safe Message Queue and some functions about it.

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

#ifndef  _MSGQUE_H
#define  _MSGQUE_H

#include <semaphore.h>
#include <time.h>
#include <errno.h>
#include <signal.h>
#include <pthread.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>

#define DEBUG  1

#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.
    pthread_mutex_t hOpLock;  //for operation
    sem_t hMsgSem;             //means there are some message(s).  
};

typedef struct tag_SafeMsgQue* pSafeMsgQue;
typedef struct tag_SafeMsgQue  SafeMsgQue;

int SafeMsgQueInit(pSafeMsgQue pSafeQue);

//int ReadOneMsg(pMsgQue* pMsg, pSafeMsgQue pSafeQue);
int ReadOneMsg(pMsgQue* pMsg, pSafeMsgQue pSafeQue, unsigned int nTimeout);

int InsertOneMsg(pMsgQue pMsg, pSafeMsgQue pSafeQue);

int LockQue(pSafeMsgQue pSafeQue);
int UnlockQue(pSafeMsgQue pSafeQue);

#endif 

#ifdef __cplusplus
}
#endif

⌨️ 快捷键说明

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