using namespace icinga;
+boost::mutex Application::m_Mutex;
Application *Application::m_Instance = NULL;
bool Application::m_ShuttingDown = false;
bool Application::m_Debugging = false;
*/
void Application::RunEventLoop(void) const
{
+ boost::mutex::scoped_lock lock(m_Mutex);
+
#ifdef _DEBUG
double nextProfile = 0;
#endif /* _DEBUG */
{
m_PkgDataDir = path;
}
+
+/**
+ * Returns the global mutex for the main thread.
+ *
+ * @returns The mutex.
+ */
+boost::mutex& Application::GetMutex(void)
+{
+ return m_Mutex;
+}
static bool ProcessEvents(void);
+ static boost::mutex& GetMutex(void);
+
protected:
void RunEventLoop(void) const;
private:
+ static boost::mutex m_Mutex; /**< The main thread mutex. */
static Application *m_Instance; /**< The application instance. */
static bool m_ShuttingDown; /**< Whether the application is in the process of
assert(Application::IsMainThread());
+ Application::GetMutex().unlock();
+
{
boost::mutex::scoped_lock lock(m_Mutex);
events.swap(m_Events);
}
+ Application::GetMutex().lock();
+
BOOST_FOREACH(const Event& ev, events) {
double st = Utility::GetTime();
*/
void Utility::Sleep(double timeout)
{
+ if (Application::IsMainThread())
+ Application::GetMutex().unlock();
+
#ifndef _WIN32
usleep(timeout * 1000 * 1000);
#else /* _WIN32 */
::Sleep(timeout * 1000);
#endif /* _WIN32 */
+
+ if (Application::IsMainThread())
+ Application::GetMutex().lock();
}
/**