Skip to content

Commit

Permalink
fix thread id type bug in arm 32
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanshudong committed Oct 12, 2023
1 parent 04f433c commit 469156e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 14 deletions.
5 changes: 3 additions & 2 deletions unit-test/util/test_tc_epoller_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ TEST_F(UtilEpollServerTest, RunUdp)

for (int i = 0; i < 10; i++)
{
iRet = client.sendRecv("abc", 3, recvBuffer, recvLenth);
string buff = "abc-" + TC_Common::tostr(i);
iRet = client.sendRecv(buff.c_str(), buff.size(), recvBuffer, recvLenth);

ASSERT_TRUE(iRet == 0);
ASSERT_TRUE(string(recvBuffer, recvLenth) == "abc");
ASSERT_TRUE(string(recvBuffer, recvLenth) == buff);
}

stopServer(server);
Expand Down
2 changes: 1 addition & 1 deletion util/include/util/tc_epoll_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ class TC_EpollServer : public TC_HandleBase, public detail::LogInterface
/**
* net线程的id
*/
size_t _threadId;
uint64_t _threadId;

/**
* 线程索引
Expand Down
4 changes: 2 additions & 2 deletions util/include/util/tc_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ namespace tars
* Stained thread ID collection
*
*/
static unordered_map<size_t, string> _mapThreadID;
static unordered_map<uint64_t, string> _mapThreadID;
};

typedef TC_AutoPtr<TC_LoggerRoll> TC_LoggerRollPtr;
Expand Down Expand Up @@ -944,7 +944,7 @@ namespace tars

if (hasFlag(TC_Logger::HAS_PID))
{
n += snprintf(c + n, len - n, "%zd%s", TC_Thread::CURRENT_THREADID(), _sSepar.c_str());
n += snprintf(c + n, len - n, "%lld%s", TC_Thread::CURRENT_THREADID(), _sSepar.c_str());
}

if (hasFlag(TC_Logger::HAS_LEVEL))
Expand Down
3 changes: 2 additions & 1 deletion util/include/util/tc_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ class TC_Thread : public TC_Runable
*
* @return
*/
static size_t CURRENT_THREADID();
static uint64_t CURRENT_THREADID();

protected:

/**
Expand Down
15 changes: 11 additions & 4 deletions util/src/tc_epoll_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ void TC_EpollServer::DataBuffer::insertRecvQueue(const deque<shared_ptr<RecvCont

_iRecvBufferSize += recv.size();


if(_epollServer->getOpenCoroutine() == TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD || _epollServer->getOpenCoroutine() == TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO)
{
//协程模式本身也是队列模式
Expand Down Expand Up @@ -752,6 +751,8 @@ void TC_EpollServer::Connection::onRequestCallback(TC_Transceiver *trans)
{
auto it = _messages.begin();

// LOG_CONSOLE_DEBUG << string((*it)->buffer()->buffer(), (*it)->buffer()->length()) << ", message:" << _messages.size() << endl;

TC_Transceiver::ReturnStatus iRet = _trans->sendRequest((*it)->buffer(), (*it)->getRecvContext()->addr());

if (iRet == TC_Transceiver::eRetError)
Expand Down Expand Up @@ -978,6 +979,8 @@ int TC_EpollServer::Connection::sendBuffer()
//计算还有多少数据没有发送出去
size_t lastLeftBufferSize = _messageSize + sendBuffer.getBufferLength();

// LOG_CONSOLE_DEBUG << "buff size:" << sendBuffer.getBufferLength() << ", " << sendBuffer.getBuffersString() << endl;

_trans->doRequest();

//需要关闭链接
Expand All @@ -1000,7 +1003,9 @@ int TC_EpollServer::Connection::send(const shared_ptr<SendContext> &sc)
//队列不为空, 直接进队列
const shared_ptr<TC_NetWorkBuffer::Buffer>& buff = sc->buffer();

if(_messages.empty())
// LOG_CONSOLE_DEBUG << string(buff->buffer(), buff->length()) << ", message:" << _messages.size() << endl;

if(_messages.empty())
{
_trans->sendRequest(buff, sc->getRecvContext()->addr());
}
Expand All @@ -1014,11 +1019,13 @@ int TC_EpollServer::Connection::send(const shared_ptr<SendContext> &sc)
//数据没有发送完
if(!buff->empty())
{
_messageSize += sc->buffer()->length();
_messageSize += buff->length();

_messages.push_back(sc);
}


// LOG_CONSOLE_DEBUG << "buff size:" << buff->length() << ", message:" << _messages.size() << endl;

auto cl = _connList.lock();
if(cl)
{
Expand Down
2 changes: 1 addition & 1 deletion util/src/tc_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static int __global_logger_debug_init__ = init_global_debug_log();

bool TC_LoggerRoll::_bDyeingFlag = false;
TC_SpinLock TC_LoggerRoll::_mutexDyeing;
unordered_map<size_t, string> TC_LoggerRoll::_mapThreadID;
unordered_map<uint64_t, string> TC_LoggerRoll::_mapThreadID;

const string LogByDay::FORMAT = "%Y%m%d";
const string LogByHour::FORMAT = "%Y%m%d%H";
Expand Down
6 changes: 3 additions & 3 deletions util/src/tc_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ bool TC_Thread::isAlive() const
return _running;
}

size_t TC_Thread::CURRENT_THREADID()
uint64_t TC_Thread::CURRENT_THREADID()
{
static thread_local size_t threadId = 0;
static thread_local uint64_t threadId = 0;
if(threadId == 0 )
{
std::stringstream ss;
ss << std::this_thread::get_id();
threadId = strtol(ss.str().c_str(), NULL, 0);
threadId = TC_Common::strto<uint64_t>(ss.str().c_str());
}
return threadId;
}
Expand Down
2 changes: 2 additions & 0 deletions util/src/tc_transceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@ void TC_Transceiver::doRequest()
auto data = _sendBuffer.getBufferPointer();
assert(data.first != NULL && data.second != 0);

// LOG_CONSOLE_DEBUG << "doRequest buff :" << string(data.first, (uint32_t)data.second) << endl;

int iRet = this->send(data.first, (uint32_t)data.second, 0);

if (iRet <= 0)
Expand Down

0 comments on commit 469156e

Please sign in to comment.