Skip to content

Commit

Permalink
revert lockfree queue
Browse files Browse the repository at this point in the history
  • Loading branch information
tarstest committed Jun 29, 2018
1 parent 60e033b commit 0517be1
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 316 deletions.
29 changes: 11 additions & 18 deletions cpp/servant/libservant/ServantHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,24 @@ void ServantHandle::run()
void ServantHandle::handleRequest()
{
bool bYield = false;

__sync_fetch_and_add(&(_handleGroup->handleCount), 1);
__sync_fetch_and_add(&(_handleGroup->runningCount), 1);

struct timespec ts;

while (!getEpollServer()->isTerminate())
{
bool bServerReqEmpty = false;

uint64_t inow = TNOWMS + 3000;
ts.tv_sec = inow / 1000;
ts.tv_nsec = inow % 1000 * 1000 * 1000;
if (_handleGroup->recvCount <= 0)
{
__sync_fetch_and_sub(&(_handleGroup->runningCount), 1);
if(_coroSched->getResponseCoroSize() > 0)
{
bServerReqEmpty = true;
}
else
TC_ThreadLock::Lock lock(_handleGroup->monitor);

if (allAdapterIsEmpty() && allFilterIsEmpty())
{
sem_timedwait(&(_handleGroup->sem), &ts);
if(_coroSched->getResponseCoroSize() > 0)
{
bServerReqEmpty = true;
}
else
{
_handleGroup->monitor.timedWait(3000);
}
}
__sync_fetch_and_add(&(_handleGroup->runningCount), 1);
}

//上报心跳
Expand Down
16 changes: 3 additions & 13 deletions cpp/util/include/util/tc_epoll_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <list>
#include <algorithm>
#include <functional>
#include <semaphore.h>
#include "util/tc_epoller.h"
#include "util/tc_thread.h"
#include "util/tc_clientsocket.h"
Expand All @@ -37,7 +36,6 @@
#include "util/tc_fifo.h"
#include "util/tc_buffer.h"
#include "util/tc_buffer_pool.h"
#include "util/tc_lockfree_queue.h"

using namespace std;

Expand Down Expand Up @@ -153,16 +151,8 @@ class TC_EpollServer : public TC_ThreadLock, public TC_HandleBase
*/
struct HandleGroup : public TC_HandleBase
{
HandleGroup():runningCount(0), handleCount(0), recvCount(0)
{
sem_init(&sem,0,0);
}
volatile int runningCount;
volatile int handleCount;
volatile int recvCount;
sem_t sem;

string name;
TC_ThreadLock monitor;
vector<HandlePtr> handles;
map<string, BindAdapterPtr> adapters;
};
Expand Down Expand Up @@ -789,7 +779,7 @@ class TC_EpollServer : public TC_ThreadLock, public TC_HandleBase
/**
* 接收的数据队列
*/
LockFreeQueue<tagRecvData*> _rBufQueue;
recv_queue _rbuffer;

/**
* 队列最大容量
Expand Down Expand Up @@ -1557,7 +1547,7 @@ class TC_EpollServer : public TC_ThreadLock, public TC_HandleBase
/**
* 发送队列
*/
LockFreeQueue<tagSendData*> _sBufQueue;
send_queue _sbuffer;

/**
* BindAdapter是否有udp监听
Expand Down
211 changes: 0 additions & 211 deletions cpp/util/include/util/tc_lockfree_queue.h

This file was deleted.

Loading

0 comments on commit 0517be1

Please sign in to comment.