Skip to content

Commit 0517be1

Browse files
committed
revert lockfree queue
1 parent 60e033b commit 0517be1

File tree

4 files changed

+69
-316
lines changed

4 files changed

+69
-316
lines changed

cpp/servant/libservant/ServantHandle.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,31 +108,24 @@ void ServantHandle::run()
108108
void ServantHandle::handleRequest()
109109
{
110110
bool bYield = false;
111-
112-
__sync_fetch_and_add(&(_handleGroup->handleCount), 1);
113-
__sync_fetch_and_add(&(_handleGroup->runningCount), 1);
114-
115-
struct timespec ts;
116-
117111
while (!getEpollServer()->isTerminate())
118112
{
119113
bool bServerReqEmpty = false;
120114

121-
uint64_t inow = TNOWMS + 3000;
122-
ts.tv_sec = inow / 1000;
123-
ts.tv_nsec = inow % 1000 * 1000 * 1000;
124-
if (_handleGroup->recvCount <= 0)
125115
{
126-
__sync_fetch_and_sub(&(_handleGroup->runningCount), 1);
127-
if(_coroSched->getResponseCoroSize() > 0)
128-
{
129-
bServerReqEmpty = true;
130-
}
131-
else
116+
TC_ThreadLock::Lock lock(_handleGroup->monitor);
117+
118+
if (allAdapterIsEmpty() && allFilterIsEmpty())
132119
{
133-
sem_timedwait(&(_handleGroup->sem), &ts);
120+
if(_coroSched->getResponseCoroSize() > 0)
121+
{
122+
bServerReqEmpty = true;
123+
}
124+
else
125+
{
126+
_handleGroup->monitor.timedWait(3000);
127+
}
134128
}
135-
__sync_fetch_and_add(&(_handleGroup->runningCount), 1);
136129
}
137130

138131
//上报心跳

cpp/util/include/util/tc_epoll_server.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <list>
2525
#include <algorithm>
2626
#include <functional>
27-
#include <semaphore.h>
2827
#include "util/tc_epoller.h"
2928
#include "util/tc_thread.h"
3029
#include "util/tc_clientsocket.h"
@@ -37,7 +36,6 @@
3736
#include "util/tc_fifo.h"
3837
#include "util/tc_buffer.h"
3938
#include "util/tc_buffer_pool.h"
40-
#include "util/tc_lockfree_queue.h"
4139

4240
using namespace std;
4341

@@ -153,16 +151,8 @@ class TC_EpollServer : public TC_ThreadLock, public TC_HandleBase
153151
*/
154152
struct HandleGroup : public TC_HandleBase
155153
{
156-
HandleGroup():runningCount(0), handleCount(0), recvCount(0)
157-
{
158-
sem_init(&sem,0,0);
159-
}
160-
volatile int runningCount;
161-
volatile int handleCount;
162-
volatile int recvCount;
163-
sem_t sem;
164-
165154
string name;
155+
TC_ThreadLock monitor;
166156
vector<HandlePtr> handles;
167157
map<string, BindAdapterPtr> adapters;
168158
};
@@ -789,7 +779,7 @@ class TC_EpollServer : public TC_ThreadLock, public TC_HandleBase
789779
/**
790780
* 接收的数据队列
791781
*/
792-
LockFreeQueue<tagRecvData*> _rBufQueue;
782+
recv_queue _rbuffer;
793783

794784
/**
795785
* 队列最大容量
@@ -1557,7 +1547,7 @@ class TC_EpollServer : public TC_ThreadLock, public TC_HandleBase
15571547
/**
15581548
* 发送队列
15591549
*/
1560-
LockFreeQueue<tagSendData*> _sBufQueue;
1550+
send_queue _sbuffer;
15611551

15621552
/**
15631553
* BindAdapter是否有udp监听

cpp/util/include/util/tc_lockfree_queue.h

Lines changed: 0 additions & 211 deletions
This file was deleted.

0 commit comments

Comments
 (0)