当前位置: 首页>>代码示例>>C++>>正文


C++ InterthreadQueue类代码示例

本文整理汇总了C++中InterthreadQueue的典型用法代码示例。如果您正苦于以下问题:C++ InterthreadQueue类的具体用法?C++ InterthreadQueue怎么用?C++ InterthreadQueue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了InterthreadQueue类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mRunning

namespace GSM {


static int sMaxAge;			///< Maximum allowed age of RACH in frames, a constant computed from config options.


CCCHLogicalChannel::CCCHLogicalChannel(unsigned wCcchGroup, const TDMAMapping& wMapping)
	:mCcchGroup(wCcchGroup), mRunning(false)
{
	unsigned TN = wCcchGroup * 2; // *2 to convert from CCCH_GROUP 
	this->mL1 = new CCCHL1FEC(wMapping,TN);
	this->connect(this->mL1);
}


static void *CCCHLogicalChannelServiceLoopAdapter(CCCHLogicalChannel* chan)
{
	chan->ccchServiceLoop();
	return NULL;
}

void CCCHLogicalChannel::ccchOpen()
{
	L2LogicalChannelBase::startl1();
	if (!mRunning) {
		mRunning=true;
		mServiceThread.start((void*(*)(void*))CCCHLogicalChannelServiceLoopAdapter,this);
	}
}

// This is a specialized thread-safe queue to be used only for the paging and related queues.
// The writer thread(s) can only write to the end of the queue.
// The single reader thread can do a protected iteration using a single captive iterator in the class.
// It does not support blocking wait so it is much simpler than InterthreadQueue.
template <class ETP>	// Entry Type, which is a Pointer.
class IterableQueue {
	typedef typename std::list<ETP>::iterator itr_t;
	Mutex miqLock;
	std::list<ETP> miqList;
	typename std::list<ETP>::iterator miqIterator;
	ETP iqResult() { return miqIterator == miqList.end() ? NULL : *miqIterator; }

	public:
	int *miqLoadPointer;  // If the descendent class sets this, it will be maintained with the number of elements in the queue.
	IterableQueue() : miqLoadPointer(NULL) {}

	void push_back(ETP elt) {
		ScopedLock lock(miqLock);
		miqList.push_back(elt);
		if (miqLoadPointer) (*miqLoadPointer)++;
	}
	//ETP pop_frontr() {
	//	ScopedLock lock(miqLock);
	//	if (miqList.empty()) { return 0; }	// Hopefully 0 has some distinct meaning for type ET.
	//	ETP result = miqList.front();
	//	miqList.pop_front();
	//	if (miqLoadPointer) (*miqLoadPointer)++;
	//	return result;
	//}

	ETP itBegin() {
		ScopedLock lock(miqLock);
		miqIterator = miqList.begin();
		return iqResult();
	}
	// It is the caller's responsibility to delete the element, or enqueue it elsewhere.
	ETP itRemove(ETP thisone) {	// The argument is redundant but helps check compliance with list semantics.
		LOG(DEBUG);
		ScopedLock lock(miqLock);
		assert(*miqIterator == thisone);
		miqIterator = miqList.erase(miqIterator);
		if (miqLoadPointer) (*miqLoadPointer)--;
		return iqResult();
	}
	ETP itSkip(ETP thisone) {	// The argument is redundant but helps check compliance with list semantics.
		ScopedLock lock(miqLock);
		assert(*miqIterator == thisone);
		miqIterator++;
		return iqResult();
	}

	int getSize() {
		ScopedLock lock(miqLock);
		return miqList.size();
	}
};

class PagingQ {
	public:
	InterthreadQueue<NewPagingEntry> mPageQ;
	void addPage(NewPagingEntry *npe) { mPageQ.write(npe); }
	unsigned getPagingLoad() { return mPageQ.size(); }
} gPagingQ;

// Global linkage:
int getPCHLoad() {
	return gPagingQ.getPagingLoad();
}


//.........这里部分代码省略.........
开发者ID:ankitag9,项目名称:openbts,代码行数:101,代码来源:GSMCCCH.cpp

示例2: qWriter

void* qWriter(void*)
{
	int *p;
	for (int i=0; i<20; i++) {
		p = new int;
		*p = i;
		COUT("queue write " << *p);
		gQ.write(p);
		if (random()%2) sleep(1);
	}
	p = new int;
	*p = -1;
	gQ.write(p);
	return NULL;
}
开发者ID:57-Wolve,项目名称:OpenBTS-UMTS,代码行数:15,代码来源:InterthreadTest.cpp

示例3: qReader

void* qReader(void*)
{
	bool done = false;
	while (!done) {
		int *p = gQ.read();
		COUT("queue read " << *p);
		if (*p<0) done=true;
		delete p;
	}
	return NULL;
}
开发者ID:57-Wolve,项目名称:OpenBTS-UMTS,代码行数:11,代码来源:InterthreadTest.cpp

示例4: enqueueRach

void enqueueRach(RachInfo *rip)
{
	// TODO: Phones next to the base station will include the operator's.
	// We should service them first, even if they are just LUR.

	// This is too chatty.
	//LOG(INFO) << "**Incoming Burst**"<<LOGVAR(lur)<<LOGVAR(gprs)
			//<<LOGVAR(when)<<LOGVAR(age)<<LOGVAR2("TE",timingError)<<LOGVAR(RSSI)<<LOGHEX(RA);

	bool deleteMe = false;
	preallocateChForRach(rip,&deleteMe);
	if (deleteMe) {
		delete rip;
		return;
	}

	gRachq.write(rip);
}
开发者ID:ankitag9,项目名称:openbts,代码行数:18,代码来源:GSMCCCH.cpp

示例5: processRaches

// Return true if the CCCH frame was used.
bool CCCHLogicalChannel::processRaches()
{
	while (RachInfo *rach = gRachq.readNoBlock())
	{
		Time now = gBTS.time();
		int age = now - rach->mWhen;	// The result is number of frames and could be negative.
		if (age>sMaxAge) {
			LOG(WARNING) << "ignoring RACH burst with age " << age;
			if (rach->mChan) {
				LOG(INFO) << "BTS congestion: unable to process RACH for pre-allocated channel within expiration time";
				rach->mChan->l2sendp(L3_HARDRELEASE_REQUEST);	// (pat) added 9-6-2013
			}
			delete rach;
			continue;	// Did not use the CCCH frame yet.
		}


		ChannelType chtype = decodeChannelNeeded(rach->mRA);
		LOG(DEBUG) <<LOGVAR(*rach) <<LOGVAR(chtype) <<LOGVAR(mCcchGroup);

		if (chtype == PSingleBlock1PhaseType || chtype == PSingleBlock2PhaseType) {
			assert(rach->mChan == NULL);
			if (0 == gConfig.getNum("GPRS.Enable")) {
				// GPRS service request when the beacon advertises no beacon support.
				// This was a spurious RACH message or a stupid handset.  Ignore it.
				assert(rach->mChan == NULL);
				delete rach;
				continue;
			}
			// Regardless of the type of GPRS request, we will send a single-block uplink,
			// which the MS will (most likely) use to send us a PacketResourceRequest.
			// First request a single-block reservation from GPRS.  If GPRS resources are busy,
			// this will return NULL and we will send reject the RACH.
			L3ImmediateAssignment *iap = GPRS::makeSingleBlockImmediateAssign(rach, mCcchNextWriteTime.FN() + 4);
			if (iap) {
				L2LogicalChannelBase::l2sendm(*iap,L3_UNIT_DATA);
				delete iap;
				delete rach;
			} else {
			}
			return true;	// We processed this rach and used the CCCH, one way or another.
		}

//		L2LogicalChannel *LCH;
//		if (chtype == TCHFType) {
//			// FIXME: This blocks at L2LAPDm::sendIdle!
//			LCH = gBTS.getTCH();
//		} else if (chtype == SDCCHType) {
//			// We may reserve some SDCCH for CC and SMS.
//			if (requestingLUR(rach->mRA)) {
//				int SDCCHAvailable = gBTS.SDCCHAvailable();
//				int SDCCHReserve = gConfig.getNum("GSM.Channels.SDCCHReserve");
//				if (requestingLUR(rach->mRA) && SDCCHAvailable <= SDCCHReserve) {
//					// (pat 2-2014) Changed this message and downgraded from CRIT.
//					LOG(CRIT) << "LUR [Location Update Request] congestion, insufficient "<<LOGVAR(SDCCHAvailable) << " <= " <<LOGVAR(SDCCHReserve);
//					goto failure;
//				}
//			}
//
//			LCH = gBTS.getSDCCH();
//		} else {
//			LOG(NOTICE) << "RACH burst for unsupported service RA=" << rach->mRA;
//			LCH = gBTS.getSDCCH();	// Try anyway.
//		}
//
//
//		// Nothing available?
//		if (!LCH) {
//			failure:
#if 0
//			return false;
#endif
//		}

		if (! rach->mChan) {
			delete rach;
			continue;
		}

		// Success.  Send an ImmediateAssignment.
		int initialTA = rach->initialTA();
		assert(initialTA >= 0 && initialTA <= 62);	// enforced by AccessGrantResponder.
		//LCH->l1InitPhy(rach->RSSI(),initialTA,gBTS.clock().systime(rach->mWhen.FN()));
		gReports.incr("OpenBTS.GSM.RR.RACH.TA.Accepted",(int)(initialTA));
		L2LogicalChannel *LCH = rach->mChan;

		// TODO: Update T3101.

		L3ImmediateAssignment assign(
			L3RequestReference(rach->mRA,rach->mWhen),
			LCH->channelDescription(),
			L3TimingAdvance(initialTA)
		);
		//assign.setStartFrame(rach->mReadyTime.FN() + 104);

		if (0) {	// This was for debugging.  Adding this delay made the layer1 connection reliable.
			// Delay the channel assignment until the SACCH is known to be transmitting...
			Time sacchStart = LCH->getSACCH()->getNextWriteTime();
			now = gBTS.time();	// Must update this because getTCH blocked.
//.........这里部分代码省略.........
开发者ID:ankitag9,项目名称:openbts,代码行数:101,代码来源:GSMCCCH.cpp

示例6: getAGCHLoad

// Global linkage:
int getAGCHLoad()
{
	int result = 0;
		result += gRachq.size();
	return result + gGprsCcchMessageQ.getSize();
}
开发者ID:ankitag9,项目名称:openbts,代码行数:7,代码来源:GSMCCCH.cpp

示例7: getPagingLoad

	unsigned getPagingLoad() { return mPageQ.size(); }
开发者ID:ankitag9,项目名称:openbts,代码行数:1,代码来源:GSMCCCH.cpp

示例8: addPage

	void addPage(NewPagingEntry *npe) { mPageQ.write(npe); }
开发者ID:ankitag9,项目名称:openbts,代码行数:1,代码来源:GSMCCCH.cpp


注:本文中的InterthreadQueue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。