]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/threadengines/threadengine_pthread.cpp
Remove useless vector copy
[user/henk/code/inspircd.git] / src / threadengines / threadengine_pthread.cpp
index 5aef0f2477f343916a2e203c5617ad9db3c3bec0..6e32634c5c4c0050bc2037a25c3123941446d777 100644 (file)
@@ -15,6 +15,7 @@
 #include "threadengines/threadengine_pthread.h"
 #include <pthread.h>
 #include <signal.h>
+#include <fcntl.h>
 
 ThreadEngine::ThreadEngine(InspIRCd* Instance)
 {
@@ -28,7 +29,7 @@ static void* entry_point(void* parameter)
        sigaddset(&set, SIGPIPE);
        pthread_sigmask(SIG_BLOCK, &set, NULL);
 
-       Thread* pt = reinterpret_cast<Thread*>(parameter);
+       Thread* pt = static_cast<Thread*>(parameter);
        pt->Run();
        return parameter;
 }
@@ -57,11 +58,7 @@ void ThreadData::FreeThread(Thread* thread)
        pthread_join(pthread_id, NULL);
 }
 
-#if 0
-/* TODO this is a linux-specific syscall that allows signals to be
- * sent using a single file descriptor, rather than 2 for a pipe.
- * Requires glibc 2.8, kernel 2.6.22+
- */
+#ifdef HAS_EVENTFD
 #include <sys/eventfd.h>
 
 class ThreadSignalSocket : public BufferedSocket
@@ -92,7 +89,7 @@ class ThreadSignalSocket : public BufferedSocket
 
 SocketThread::SocketThread(InspIRCd* SI)
 {
-       int fd = eventfd(0, 0); // TODO nonblock
+       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, SI, fd);
@@ -115,13 +112,13 @@ class ThreadSignalSocket : public BufferedSocket
        void Notify()
        {
                char dummy = '*';
-               send(send_fd, &dummy, 1, 0);
+               write(send_fd, &dummy, 1);
        }
 
        virtual bool OnDataReady()
        {
                char data;
-               if (ServerInstance->SE->Recv(this, &data, 1, 0) <= 0)
+               if (read(this->fd, &data, 1) <= 0)
                        return false;
                parent->OnNotify();
                return true;
@@ -144,5 +141,4 @@ void SocketThread::NotifyParent()
 
 SocketThread::~SocketThread()
 {
-       delete signal.sock;
 }