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;
|
||||
|
||||
boost::mutex Application::m_Mutex;
|
||||
Application *Application::m_Instance = NULL;
|
||||
bool Application::m_ShuttingDown = false;
|
||||
bool Application::m_Debugging = false;
|
||||
|
@ -113,6 +114,8 @@ bool Application::ProcessEvents(void)
|
|||
*/
|
||||
void Application::RunEventLoop(void) const
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_Mutex);
|
||||
|
||||
#ifdef _DEBUG
|
||||
double nextProfile = 0;
|
||||
#endif /* _DEBUG */
|
||||
|
@ -565,3 +568,13 @@ void Application::SetPkgDataDir(const String& 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 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
|
||||
|
|
|
@ -46,6 +46,8 @@ void Event::ProcessEvents(millisec timeout)
|
|||
|
||||
assert(Application::IsMainThread());
|
||||
|
||||
Application::GetMutex().unlock();
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_Mutex);
|
||||
|
||||
|
@ -57,6 +59,8 @@ void Event::ProcessEvents(millisec timeout)
|
|||
events.swap(m_Events);
|
||||
}
|
||||
|
||||
Application::GetMutex().lock();
|
||||
|
||||
BOOST_FOREACH(const Event& ev, events) {
|
||||
double st = Utility::GetTime();
|
||||
|
||||
|
|
|
@ -398,11 +398,17 @@ pid_t Utility::GetPid(void)
|
|||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue