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

📄 shmobjqueue.h

📁 uclinux的进程间通信例子
💻 H
字号:
/*
 * this file provide obj queue in share memory realization
 * composed by antony 
 * 2003-3-17
 * copyright reserved
 */

#ifndef __SHMBOJQUEUE_H_
#define __SHMBOJQUEUE_H_
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include "../include/msg_struct.h"

template <class st> class shmobjqueue
{

	private:
		char *m_pShm;
		int m_iSemid;
		int m_iObjSize;
		int *m_piPoolSize;
		int *m_piMaxPoolSize;

		st *m_pMemStart;   //memory m_pMemStart
		st *m_pMemEnd;     //memorr m_pMemEnd;


		st **m_ppObjFirst;  //m_ppObjFirst  node;
		st **m_ppObjLast;   //m_ppObjLast  node;
	union semun {
    		int val;
    		struct semid_ds *buf;
    		ushort *array;
  	} arg;

		char *shmcreate(int ipckey, unsigned long size);
		void asynInit(int ipckey);
		void asynStart();
		void asynEnd();

	public:
		//create memory to contain num st obj
		shmobjqueue(int ipckey, int num = 5000 );
		~shmobjqueue();
		//get a obj from pool
		bool get(st *);
		//put a obj to pool
		bool put(st *);
		//clear up all objs in pool
		void clearup();
		//detach from shm
		void detach();
		//return true if empty
		bool isEmpty();
		//return pool size
		int getSize();
		//return is full
		bool isFull();
		int m_ipckey;
};
/*
 * just realize the following class
 */
template class shmobjqueue<char>;
template class shmobjqueue<int>;
template class shmobjqueue<recv_node_stru>;
template class shmobjqueue<submit_node_stru>;
#endif

⌨️ 快捷键说明

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