mirror of https://github.com/Icinga/icinga2.git
Implement global mutex (for use by scripting languages).
This commit is contained in:
parent
49576d3a82
commit
c91191e701
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
boost::mutex Application::m_Mutex;
|
||||||
Application *Application::m_Instance = NULL;
|
Application *Application::m_Instance = NULL;
|
||||||
bool Application::m_ShuttingDown = false;
|
bool Application::m_ShuttingDown = false;
|
||||||
bool Application::m_Debugging = false;
|
bool Application::m_Debugging = false;
|
||||||
|
@ -113,6 +114,8 @@ bool Application::ProcessEvents(void)
|
||||||
*/
|
*/
|
||||||
void Application::RunEventLoop(void) const
|
void Application::RunEventLoop(void) const
|
||||||
{
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
double nextProfile = 0;
|
double nextProfile = 0;
|
||||||
#endif /* _DEBUG */
|
#endif /* _DEBUG */
|
||||||
|
@ -565,3 +568,13 @@ void Application::SetPkgDataDir(const String& path)
|
||||||
{
|
{
|
||||||
m_PkgDataDir = path;
|
m_PkgDataDir = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the global mutex for the main thread.
|
||||||
|
*
|
||||||
|
* @returns The mutex.
|
||||||
|
*/
|
||||||
|
boost::mutex& Application::GetMutex(void)
|
||||||
|
{
|
||||||
|
return m_Mutex;
|
||||||
|
}
|
||||||
|
|
|
@ -78,10 +78,13 @@ public:
|
||||||
|
|
||||||
static bool ProcessEvents(void);
|
static bool ProcessEvents(void);
|
||||||
|
|
||||||
|
static boost::mutex& GetMutex(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void RunEventLoop(void) const;
|
void RunEventLoop(void) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static boost::mutex m_Mutex; /**< The main thread mutex. */
|
||||||
static Application *m_Instance; /**< The application instance. */
|
static Application *m_Instance; /**< The application instance. */
|
||||||
|
|
||||||
static bool m_ShuttingDown; /**< Whether the application is in the process of
|
static bool m_ShuttingDown; /**< Whether the application is in the process of
|
||||||
|
|
|
@ -46,6 +46,8 @@ void Event::ProcessEvents(millisec timeout)
|
||||||
|
|
||||||
assert(Application::IsMainThread());
|
assert(Application::IsMainThread());
|
||||||
|
|
||||||
|
Application::GetMutex().unlock();
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_Mutex);
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
|
|
||||||
|
@ -57,6 +59,8 @@ void Event::ProcessEvents(millisec timeout)
|
||||||
events.swap(m_Events);
|
events.swap(m_Events);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Application::GetMutex().lock();
|
||||||
|
|
||||||
BOOST_FOREACH(const Event& ev, events) {
|
BOOST_FOREACH(const Event& ev, events) {
|
||||||
double st = Utility::GetTime();
|
double st = Utility::GetTime();
|
||||||
|
|
||||||
|
|
|
@ -398,11 +398,17 @@ pid_t Utility::GetPid(void)
|
||||||
*/
|
*/
|
||||||
void Utility::Sleep(double timeout)
|
void Utility::Sleep(double timeout)
|
||||||
{
|
{
|
||||||
|
if (Application::IsMainThread())
|
||||||
|
Application::GetMutex().unlock();
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
usleep(timeout * 1000 * 1000);
|
usleep(timeout * 1000 * 1000);
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
::Sleep(timeout * 1000);
|
::Sleep(timeout * 1000);
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
if (Application::IsMainThread())
|
||||||
|
Application::GetMutex().lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue