1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "threadengines/threadengine_pthread.h"
19 PThreadEngine::PThreadEngine(InspIRCd* Instance) : ThreadEngine(Instance)
23 static void* entry_point(void* parameter)
25 /* Recommended by nenolod, signal safety on a per-thread basis */
28 sigaddset(&set, SIGPIPE);
29 pthread_sigmask(SIG_BLOCK, &set, NULL);
31 Thread* pt = reinterpret_cast<Thread*>(parameter);
37 void PThreadEngine::Start(Thread* thread)
39 PThreadData* data = new PThreadData;
42 if (pthread_create(&data->pthread_id, NULL, entry_point, thread) != 0)
46 throw CoreException("Unable to create new PThreadEngine: " + std::string(strerror(errno)));
50 PThreadEngine::~PThreadEngine()
54 void PThreadData::FreeThread(Thread* thread)
56 thread->SetExitFlag(true);
57 pthread_join(pthread_id, NULL);
60 MutexFactory::MutexFactory(InspIRCd* Instance) : ServerInstance(Instance)
64 Mutex* MutexFactory::CreateMutex()
66 return new PosixMutex();
69 PosixMutex::PosixMutex() : Mutex()
71 pthread_mutex_init(&putex, NULL);
74 PosixMutex::~PosixMutex()
76 pthread_mutex_destroy(&putex);
79 void PosixMutex::Enable(bool enable)
82 pthread_mutex_lock(&putex);
84 pthread_mutex_unlock(&putex);