X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fthreadengines%2Fthreadengine_pthread.cpp;h=59ab8f4021b804280d1b0a3e05886ef800d38921;hb=6d03943426dcce76ba66567a9b18425a5ebb4c0c;hp=f5de69a6a71301c20ff7850ec48f42b2688b7886;hpb=f9e6de5284aaacd55aa389445cd595bdcaa8339e;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/threadengines/threadengine_pthread.cpp b/src/threadengines/threadengine_pthread.cpp index f5de69a6a..59ab8f402 100644 --- a/src/threadengines/threadengine_pthread.cpp +++ b/src/threadengines/threadengine_pthread.cpp @@ -15,8 +15,9 @@ #include "threadengines/threadengine_pthread.h" #include #include +#include -ThreadEngine::ThreadEngine(InspIRCd* Instance) +ThreadEngine::ThreadEngine() { } @@ -28,7 +29,7 @@ static void* entry_point(void* parameter) sigaddset(&set, SIGPIPE); pthread_sigmask(SIG_BLOCK, &set, NULL); - Thread* pt = reinterpret_cast(parameter); + Thread* pt = static_cast(parameter); pt->Run(); return parameter; } @@ -53,6 +54,92 @@ ThreadEngine::~ThreadEngine() void ThreadData::FreeThread(Thread* thread) { - thread->SetExitFlag(true); + thread->SetExitFlag(); pthread_join(pthread_id, NULL); } + +#ifdef HAS_EVENTFD +#include + +class ThreadSignalSocket : public BufferedSocket +{ + SocketThread* parent; + public: + ThreadSignalSocket(SocketThread* p, int newfd) : BufferedSocket(newfd), parent(p) {} + + ~ThreadSignalSocket() + { + } + + void Notify() + { + eventfd_write(fd, 1); + } + + void OnDataReady() + { + recvq.clear(); + parent->OnNotify(); + } + + void OnError(BufferedSocketError) + { + } +}; + +SocketThread::SocketThread() +{ + int fd = eventfd(0, O_NONBLOCK); + if (fd < 0) + throw new CoreException("Could not create pipe " + std::string(strerror(errno))); + signal.sock = new ThreadSignalSocket(this, fd); +} +#else + +class ThreadSignalSocket : public BufferedSocket +{ + SocketThread* parent; + int send_fd; + public: + ThreadSignalSocket(SocketThread* p, int recvfd, int sendfd) : + BufferedSocket(recvfd), parent(p), send_fd(sendfd) {} + + ~ThreadSignalSocket() + { + close(send_fd); + } + + void Notify() + { + char dummy = '*'; + write(send_fd, &dummy, 1); + } + + void OnDataReady() + { + recvq.clear(); + parent->OnNotify(); + } + + void OnError(BufferedSocketError) + { + } +}; + +SocketThread::SocketThread() +{ + int fds[2]; + if (pipe(fds)) + throw new CoreException("Could not create pipe " + std::string(strerror(errno))); + signal.sock = new ThreadSignalSocket(this, fds[0], fds[1]); +} +#endif + +void SocketThread::NotifyParent() +{ + signal.sock->Notify(); +} + +SocketThread::~SocketThread() +{ +}