Fix/posix sleep (#3705)

* fix(Thread_POSIX): sleep() poor performance #3703

* chore(vscode): add file associations

* fix(TaskManager): waits for all threads in the ThreadPool #3704

* fix(Thread): call std::this_thread::sleep_for() to sleep #3703

* fix(PollSet): wakeup fd is never read #3708

* feat(Thread): Add Thread::set/getAffinity() #3709

* doc(Thread): Thread::trySleep() assertion #3710

* fix(PollSet): wakeup fd is never read (windows portion and some other optimizations) #3708

* feat(SocketReactor): improvements #3713

* chore(ThreadTest): add missing include

* fix(PollSet): wakeup fd is never read #3708

* fix(Any): #3682 #3683 #3692 #3712

* fix(mingw): lowercase winsock2 and iphlpapi to allow cross compile #3711

* feat(Thread): Add Thread::set/getAffinity() #3709

* chore(SocketReactor): one-liners inlined, removed redundant try/catch in dospatch, remove unused onBusy()

* feat(SocketReactor): add socket to ErrorNotification

* fix(SocketReactor): pollTimeout assignment and ConnectorTest leak
This commit is contained in:
Aleksandar Fabijanic
2022-07-26 13:54:56 +02:00
committed by GitHub
parent d1b398ddc6
commit 86a4f0045e
26 changed files with 560 additions and 277 deletions

View File

@@ -21,6 +21,8 @@
#include "Poco/Foundation.h"
#include "Poco/Event.h"
#include "Poco/Mutex.h"
#include <thread>
#include <chrono>
#if defined(POCO_OS_FAMILY_WINDOWS)
@@ -207,6 +209,9 @@ public:
/// wakeUp() before calling trySleep() will prevent the next
/// trySleep() call to actually suspend the thread (which, in
/// some scenarios, may be desirable behavior).
///
/// Note that, unlike Thread::sleep(), this function can only
/// be succesfully called from a thread started as Poco::Thread.
void wakeUp();
/// Wakes up the thread which is in the state of interruptible
@@ -231,6 +236,17 @@ public:
static long currentOsTid();
/// Returns the operating system specific thread ID for the current thread.
bool setAffinity(int coreId);
/// Sets the thread affinity to the coreID.
/// Returns true if succesful.
/// Returns false if not succesful or not
/// implemented.
int getAffinity() const;
/// Returns the thread affinity.
/// Negative value means the thread has
/// no CPU core affinity.
protected:
ThreadLocalStorage& tls();
/// Returns a reference to the thread's local storage.
@@ -317,18 +333,18 @@ inline bool Thread::isRunning() const
}
inline void Thread::sleep(long milliseconds)
{
sleepImpl(milliseconds);
}
inline void Thread::yield()
{
yieldImpl();
}
inline void Thread::sleep(long milliseconds)
{
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
}
inline Thread* Thread::current()
{
return static_cast<Thread*>(currentImpl());
@@ -381,6 +397,18 @@ inline long Thread::currentOsTid()
return currentOsTidImpl();
}
inline bool Thread::setAffinity(int coreId)
{
return setAffinityImpl(coreId);
}
inline int Thread::getAffinity() const
{
return getAffinityImpl();
}
} // namespace Poco