예제 #1
0
void RefObject::AddRef()
{
	if (mutex_)
	{
		MUTEX_GUARD(obj, *mutex_);
		refCounts_ += 1;
	}
	else
		refCounts_ += 1;
}
예제 #2
0
//从发送队列尾部追加一条消息
int32_t CFrameNetQueue::PushSendSSQueue(NetPacket *pNetPacket)
{
	if(pNetPacket == NULL)
	{
		return E_NULLPOINTER;
	}

	MUTEX_GUARD(SendSSLock, m_stSendSSLock);
	m_stSendSSQueue.push_back(pNetPacket);

	return S_OK;
}
예제 #3
0
//从接收队列头部读取一条消息
int32_t CFrameNetQueue::PopRecvSSQueue(NetPacket *&pNetPacket)
{
	MUTEX_GUARD(RecvSSLock, m_stRecvSSLock);
	if(m_stRecvSSQueue.size() > 0)
	{
		pNetPacket = m_stRecvSSQueue.front();
		m_stRecvSSQueue.pop_front();
	}
	else
	{
		pNetPacket = NULL;
	}

	return S_OK;
}
예제 #4
0
void RefObject::ReleaseRef()
{
	if (mutex_)
	{
		MUTEX_GUARD(obj, *mutex_);
		refCounts_ -= 1;
		if (refCounts_ <= 0)
			delete this;
	}
	else
	{
		refCounts_ -= 1;
		if (refCounts_ <= 0)
			delete this;
	}
}
예제 #5
0
bool
LogSinkImpl::write(const char* s, size_t n) 
{ 
#   ifdef LINKO_LOG_THREAD
    if (_thread) return thr_write(s, n);
#   endif    

#   if defined LINKO_LOG_WRITE_WO_MUTEX && defined LINKO_LOG_MT
    // Without mutex, it's much safer to always return true (success)!
    return mx_write(s, n), true;
#   else
    // It seems that mutex lock is unnecessary here!
    // Important is O_APPEND flag on open.
    // Performance cost of this lock is very big for high congestions.
    // Mutex is only important for correct rotate() operation.
    MUTEX_GUARD(_mutex);
    return mx_write(s, n);
#   endif
}
예제 #6
0
void
LogSinkImpl::rotate(std::time_t time)
{
    if (_prog.empty()) return;
    std::time_t day = time - time % (60*60*24);
    if (day == _time) return;

    MUTEX_GUARD(_mutex);
    if (day == _time) return;
    const bool print_msg = _time;
    _time = day;

#   ifdef LINKO_LOG_THREAD
    if (_thread) {
        _queue.push(Buffer());
        _cond.notify_one();
        return;
    }
#   endif

    mx_rotate(print_msg);
}
예제 #7
0
//判读接收队列是否为空
bool CFrameNetQueue::IsRecvSSQueueEmpty()
{
	MUTEX_GUARD(RecvSSLock, m_stRecvSSLock);
	return m_stRecvSSQueue.empty();
}
예제 #8
0
//判读发送队列是否为空
bool CFrameNetQueue::IsSendCSQueueEmpty()
{
	MUTEX_GUARD(SendCSLock, m_stSendCSLock);
	return m_stSendCSQueue.empty();
}