Browse Source

move thread naming to util

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/1595/head
R4SAS 4 years ago
parent
commit
3100d4f902
  1. 4
      daemon/HTTPServer.cpp
  2. 4
      daemon/I2PControl.cpp
  3. 4
      daemon/UPnP.cpp
  4. 5
      libi2pd/Log.cpp
  5. 4
      libi2pd/NetDb.cpp
  6. 8
      libi2pd/SSU.cpp
  7. 5
      libi2pd/Timestamp.cpp
  8. 6
      libi2pd/Transports.cpp
  9. 4
      libi2pd/Tunnel.cpp
  10. 22
      libi2pd/util.cpp
  11. 2
      libi2pd/util.h
  12. 4
      libi2pd_client/I2PTunnel.cpp

4
daemon/HTTPServer.cpp

@ -9,7 +9,6 @@
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#include <thread> #include <thread>
#include <pthread.h>
#include <memory> #include <memory>
#include <boost/asio.hpp> #include <boost/asio.hpp>
@ -1313,7 +1312,8 @@ namespace http {
void HTTPServer::Run () void HTTPServer::Run ()
{ {
pthread_setname_np(pthread_self(), "Webconsole"); i2p::util::SetThreadName("Webconsole");
while (m_IsRunning) while (m_IsRunning)
{ {
try try

4
daemon/I2PControl.cpp

@ -7,7 +7,6 @@
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/property_tree/ini_parser.hpp> #include <boost/property_tree/ini_parser.hpp>
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <pthread.h>
#include "Crypto.h" #include "Crypto.h"
#include "FS.h" #include "FS.h"
@ -132,7 +131,8 @@ namespace client
void I2PControlService::Run () void I2PControlService::Run ()
{ {
pthread_setname_np(pthread_self(), "I2PC"); i2p::util::SetThreadName("I2PC");
while (m_IsRunning) while (m_IsRunning)
{ {
try { try {

4
daemon/UPnP.cpp

@ -1,7 +1,6 @@
#ifdef USE_UPNP #ifdef USE_UPNP
#include <string> #include <string>
#include <thread> #include <thread>
#include <pthread.h>
#include <boost/thread/thread.hpp> #include <boost/thread/thread.hpp>
#include <boost/asio.hpp> #include <boost/asio.hpp>
@ -61,7 +60,8 @@ namespace transport
void UPnP::Run () void UPnP::Run ()
{ {
pthread_setname_np(pthread_self(), "UPnP"); i2p::util::SetThreadName("UPnP");
while (m_IsRunning) while (m_IsRunning)
{ {
try try

5
libi2pd/Log.cpp

@ -7,7 +7,7 @@
*/ */
#include "Log.h" #include "Log.h"
#include <pthread.h> #include "util.h"
//for std::transform //for std::transform
#include <algorithm> #include <algorithm>
@ -180,7 +180,8 @@ namespace log {
void Log::Run () void Log::Run ()
{ {
pthread_setname_np(pthread_self(), "Logging"); i2p::util::SetThreadName("Logging");
Reopen (); Reopen ();
while (m_IsRunning) while (m_IsRunning)
{ {

4
libi2pd/NetDb.cpp

@ -11,7 +11,6 @@
#include <vector> #include <vector>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <stdexcept> #include <stdexcept>
#include <pthread.h>
#include "I2PEndian.h" #include "I2PEndian.h"
#include "Base.h" #include "Base.h"
@ -27,6 +26,7 @@
#include "ECIESX25519AEADRatchetSession.h" #include "ECIESX25519AEADRatchetSession.h"
#include "Config.h" #include "Config.h"
#include "NetDb.hpp" #include "NetDb.hpp"
#include "util.h"
using namespace i2p::transport; using namespace i2p::transport;
@ -89,7 +89,7 @@ namespace data
void NetDb::Run () void NetDb::Run ()
{ {
pthread_setname_np(pthread_self(), "NetDB"); i2p::util::SetThreadName("NetDB");
uint32_t lastSave = 0, lastPublish = 0, lastExploratory = 0, lastManageRequest = 0, lastDestinationCleanup = 0; uint32_t lastSave = 0, lastPublish = 0, lastExploratory = 0, lastManageRequest = 0, lastDestinationCleanup = 0;
while (m_IsRunning) while (m_IsRunning)

8
libi2pd/SSU.cpp

@ -7,12 +7,12 @@
*/ */
#include <string.h> #include <string.h>
#include <pthread.h>
#include "Log.h" #include "Log.h"
#include "Timestamp.h" #include "Timestamp.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "NetDb.hpp" #include "NetDb.hpp"
#include "SSU.h" #include "SSU.h"
#include "util.h"
#ifdef _WIN32 #ifdef _WIN32
#include <boost/winapi/error_codes.hpp> #include <boost/winapi/error_codes.hpp>
@ -143,7 +143,7 @@ namespace transport
void SSUServer::Run () void SSUServer::Run ()
{ {
pthread_setname_np(pthread_self(), "SSU"); i2p::util::SetThreadName("SSU");
while (m_IsRunning) while (m_IsRunning)
{ {
@ -160,7 +160,7 @@ namespace transport
void SSUServer::RunReceivers () void SSUServer::RunReceivers ()
{ {
pthread_setname_np(pthread_self(), "SSUv4"); i2p::util::SetThreadName("SSUv4");
while (m_IsRunning) while (m_IsRunning)
{ {
@ -184,7 +184,7 @@ namespace transport
void SSUServer::RunReceiversV6 () void SSUServer::RunReceiversV6 ()
{ {
pthread_setname_np(pthread_self(), "SSUv6"); i2p::util::SetThreadName("SSUv6");
while (m_IsRunning) while (m_IsRunning)
{ {

5
libi2pd/Timestamp.cpp

@ -14,11 +14,11 @@
#include <future> #include <future>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <pthread.h>
#include "Config.h" #include "Config.h"
#include "Log.h" #include "Log.h"
#include "I2PEndian.h" #include "I2PEndian.h"
#include "Timestamp.h" #include "Timestamp.h"
#include "util.h"
#ifdef _WIN32 #ifdef _WIN32
#ifndef _WIN64 #ifndef _WIN64
@ -149,7 +149,8 @@ namespace util
void NTPTimeSync::Run () void NTPTimeSync::Run ()
{ {
pthread_setname_np(pthread_self(), "Timesync"); i2p::util::SetThreadName("Timesync");
while (m_IsRunning) while (m_IsRunning)
{ {
try try

6
libi2pd/Transports.cpp

@ -6,7 +6,6 @@
* See full license text in LICENSE file at top of project tree * See full license text in LICENSE file at top of project tree
*/ */
#include <pthread.h>
#include "Log.h" #include "Log.h"
#include "Crypto.h" #include "Crypto.h"
#include "RouterContext.h" #include "RouterContext.h"
@ -15,6 +14,7 @@
#include "Transports.h" #include "Transports.h"
#include "Config.h" #include "Config.h"
#include "HTTP.h" #include "HTTP.h"
#include "util.h"
using namespace i2p::data; using namespace i2p::data;
@ -60,7 +60,7 @@ namespace transport
template<typename Keys> template<typename Keys>
void EphemeralKeysSupplier<Keys>::Run () void EphemeralKeysSupplier<Keys>::Run ()
{ {
pthread_setname_np(pthread_self(), "Ephemerals"); i2p::util::SetThreadName("Ephemerals");
while (m_IsRunning) while (m_IsRunning)
{ {
@ -275,7 +275,7 @@ namespace transport
void Transports::Run () void Transports::Run ()
{ {
pthread_setname_np(pthread_self(), "Transports"); i2p::util::SetThreadName("Transports");
while (m_IsRunning && m_Service) while (m_IsRunning && m_Service)
{ {

4
libi2pd/Tunnel.cpp

@ -10,7 +10,6 @@
#include "I2PEndian.h" #include "I2PEndian.h"
#include <random> #include <random>
#include <thread> #include <thread>
#include <pthread.h>
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include "Crypto.h" #include "Crypto.h"
@ -23,6 +22,7 @@
#include "Config.h" #include "Config.h"
#include "Tunnel.h" #include "Tunnel.h"
#include "TunnelPool.h" #include "TunnelPool.h"
#include "util.h"
namespace i2p namespace i2p
{ {
@ -473,7 +473,7 @@ namespace tunnel
void Tunnels::Run () void Tunnels::Run ()
{ {
pthread_setname_np(pthread_self(), "Tunnels"); i2p::util::SetThreadName("Tunnels");
std::this_thread::sleep_for (std::chrono::seconds(1)); // wait for other parts are ready std::this_thread::sleep_for (std::chrono::seconds(1)); // wait for other parts are ready
uint64_t lastTs = 0, lastPoolsTs = 0; uint64_t lastTs = 0, lastPoolsTs = 0;

22
libi2pd/util.cpp

@ -13,6 +13,15 @@
#include "util.h" #include "util.h"
#include "Log.h" #include "Log.h"
#if not defined (__FreeBSD__)
#include <pthread.h>
#endif
#if defined(__OpenBSD__) || defined(__FreeBSD__)
#include <pthread_np.h>
#endif
#ifdef _WIN32 #ifdef _WIN32
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -94,7 +103,8 @@ namespace util
void RunnableService::Run () void RunnableService::Run ()
{ {
pthread_setname_np(pthread_self(), m_Name.c_str()); SetThreadName(m_Name.c_str());
while (m_IsRunning) while (m_IsRunning)
{ {
try try
@ -108,6 +118,16 @@ namespace util
} }
} }
void SetThreadName (const char *name) {
#if defined (__APPLE__)
pthread_setname_np(name);
#elif defined(__FreeBSD__)
pthread_set_name_np(pthread_self(), name)
#else
pthread_setname_np(pthread_self(), name);
#endif
}
namespace net namespace net
{ {
#ifdef _WIN32 #ifdef _WIN32

2
libi2pd/util.h

@ -168,6 +168,8 @@ namespace util
boost::asio::io_service::work m_Work; boost::asio::io_service::work m_Work;
}; };
void SetThreadName (const char *name);
namespace net namespace net
{ {
int GetMTU (const boost::asio::ip::address& localAddress); int GetMTU (const boost::asio::ip::address& localAddress);

4
libi2pd_client/I2PTunnel.cpp

@ -7,12 +7,12 @@
*/ */
#include <cassert> #include <cassert>
#include <pthread.h>
#include "Base.h" #include "Base.h"
#include "Log.h" #include "Log.h"
#include "Destination.h" #include "Destination.h"
#include "ClientContext.h" #include "ClientContext.h"
#include "I2PTunnel.h" #include "I2PTunnel.h"
#include "util.h"
namespace i2p namespace i2p
{ {
@ -941,8 +941,8 @@ namespace client
} }
void I2PUDPClientTunnel::TryResolving() { void I2PUDPClientTunnel::TryResolving() {
i2p::util::SetThreadName("UDP Resolver");
LogPrint(eLogInfo, "UDP Tunnel: Trying to resolve ", m_RemoteDest); LogPrint(eLogInfo, "UDP Tunnel: Trying to resolve ", m_RemoteDest);
pthread_setname_np(pthread_self(), "UDP Resolver");
std::shared_ptr<const Address> addr; std::shared_ptr<const Address> addr;
while(!(addr = context.GetAddressBook().GetAddress(m_RemoteDest)) && !m_cancel_resolve) while(!(addr = context.GetAddressBook().GetAddress(m_RemoteDest)) && !m_cancel_resolve)

Loading…
Cancel
Save