Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert <fix>(timer) #108

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions bcos-boostssl/utility/NewTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
*/
#pragma once
#include "bcos-utilities/BoostLog.h"
#include "bcos-utilities/Common.h"
#include <boost/asio.hpp>
#include <boost/asio/steady_timer.hpp>
#include "bcos-utilities/Common.h"
#include <exception>

namespace bcos
Expand Down Expand Up @@ -90,11 +90,6 @@ class Timer : public std::enable_shared_from_this<Timer>
return;
}

if (m_ioService)
{
m_ioService->stop();
}

if (m_delayHandler)
{
m_delayHandler->cancel();
Expand All @@ -104,8 +99,6 @@ class Timer : public std::enable_shared_from_this<Timer>
{
m_timerHandler->cancel();
}

m_running = false;
}

private:
Expand Down Expand Up @@ -208,9 +201,10 @@ class TimerFactory
return timer;
}

private:
void startThread()
{
if (m_worker || !m_running)
if (m_worker)
{
return;
}
Expand Down Expand Up @@ -254,9 +248,7 @@ class TimerFactory
m_running = false;
BCOS_LOG(INFO) << LOG_BADGE("stopThread") << LOG_DESC("stop the timer thread");

// must stop ioService, otherwise thread won't stop
m_ioService->stop();

if (m_worker->get_id() != std::this_thread::get_id())
{
m_worker->join();
Expand All @@ -268,7 +260,6 @@ class TimerFactory
}
}

private:
std::atomic_bool m_running = {false};
std::string m_threadName = "timerFactory";
std::unique_ptr<std::thread> m_worker = nullptr;
Expand Down
18 changes: 6 additions & 12 deletions bcos-boostssl/websocket/WsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ void WsService::start()
{
m_timerFactory = std::make_shared<timer::TimerFactory>();
}
m_timerFactory->startThread();

// start ioc thread
if (m_ioservicePool)
Expand Down Expand Up @@ -138,6 +137,12 @@ void WsService::stop()
}
m_running = false;

// stop ioc thread
if (m_ioservicePool)
{
m_ioservicePool->stop();
}

if (m_statTimer)
{
m_statTimer->stop();
Expand All @@ -148,17 +153,6 @@ void WsService::stop()
m_reconnectTimer->stop();
}

// stop ioc thread
if (m_ioservicePool)
{
m_ioservicePool->stop();
}

if (m_timerFactory)
{
m_timerFactory->stopThread();
}

WEBSOCKET_SERVICE(INFO) << LOG_BADGE("stop") << LOG_DESC("stop websocket service successfully");
}

Expand Down
Loading