18 |
*/ |
*/ |
19 |
|
|
20 |
#include "compat.h" |
#include "compat.h" |
|
// threads.h must be included first to be able to build with |
|
|
// G_DISABLE_DEPRECATED |
|
|
#if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \ |
|
|
(GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2 |
|
|
#include <glibmm/threads.h> |
|
|
#endif |
|
|
|
|
21 |
#include "gigedit.h" |
#include "gigedit.h" |
22 |
|
|
23 |
|
#ifdef GLIB_THREADS |
24 |
|
#ifndef OLD_THREADS |
25 |
|
#include <glibmm/threads.h> |
26 |
|
#endif |
27 |
|
#else |
28 |
|
#include <thread> |
29 |
|
#include <mutex> |
30 |
|
#include <condition_variable> |
31 |
|
#endif |
32 |
#if GTKMM_MAJOR_VERSION < 3 |
#if GTKMM_MAJOR_VERSION < 3 |
33 |
#include <gdkmm/region.h> |
#include <gdkmm/region.h> |
34 |
#endif |
#endif |
87 |
class Cond { |
class Cond { |
88 |
private: |
private: |
89 |
bool pred; |
bool pred; |
90 |
|
#ifdef GLIB_THREADS |
91 |
Glib::Threads::Mutex mutex; |
Glib::Threads::Mutex mutex; |
92 |
Glib::Threads::Cond cond; |
Glib::Threads::Cond cond; |
93 |
|
#else |
94 |
|
std::mutex mutex; |
95 |
|
std::condition_variable cond; |
96 |
|
#endif |
97 |
public: |
public: |
98 |
Cond() : pred(false) { } |
Cond() : pred(false) { } |
99 |
void signal() { |
void signal() { |
100 |
|
#ifdef GLIB_THREADS |
101 |
Glib::Threads::Mutex::Lock lock(mutex); |
Glib::Threads::Mutex::Lock lock(mutex); |
102 |
pred = true; |
pred = true; |
103 |
cond.signal(); |
cond.signal(); |
104 |
|
#else |
105 |
|
std::lock_guard<std::mutex> lock(mutex); |
106 |
|
pred = true; |
107 |
|
cond.notify_one(); |
108 |
|
#endif |
109 |
} |
} |
110 |
void wait() { |
void wait() { |
111 |
|
#ifdef GLIB_THREADS |
112 |
Glib::Threads::Mutex::Lock lock(mutex); |
Glib::Threads::Mutex::Lock lock(mutex); |
113 |
while (!pred) cond.wait(mutex); |
while (!pred) cond.wait(mutex); |
114 |
|
#else |
115 |
|
std::unique_lock<std::mutex> lock(mutex); |
116 |
|
while (!pred) cond.wait(lock); |
117 |
|
#endif |
118 |
} |
} |
119 |
}; |
}; |
120 |
|
|
121 |
#ifdef OLD_THREADS |
#ifdef OLD_THREADS |
122 |
static Glib::StaticMutex mutex; |
static Glib::StaticMutex mutex; |
123 |
#else |
#elif defined(GLIB_THREADS) |
124 |
static Glib::Threads::Mutex mutex; |
static Glib::Threads::Mutex mutex; |
125 |
|
#else |
126 |
|
static std::mutex mutex; |
127 |
#endif |
#endif |
128 |
static Glib::Dispatcher* dispatcher; |
static Glib::Dispatcher* dispatcher; |
129 |
static GigEditState* current; |
static GigEditState* current; |
432 |
|
|
433 |
#ifdef OLD_THREADS |
#ifdef OLD_THREADS |
434 |
Glib::StaticMutex GigEditState::mutex = GLIBMM_STATIC_MUTEX_INIT; |
Glib::StaticMutex GigEditState::mutex = GLIBMM_STATIC_MUTEX_INIT; |
435 |
#else |
#elif defined(GLIB_THREADS) |
436 |
Glib::Threads::Mutex GigEditState::mutex; |
Glib::Threads::Mutex GigEditState::mutex; |
437 |
|
#else |
438 |
|
std::mutex GigEditState::mutex; |
439 |
#endif |
#endif |
440 |
Glib::Dispatcher* GigEditState::dispatcher = 0; |
Glib::Dispatcher* GigEditState::dispatcher = 0; |
441 |
GigEditState* GigEditState::current = 0; |
GigEditState* GigEditState::current = 0; |
558 |
sigc::bind(sigc::ptr_fun(&GigEditState::main_loop_run), |
sigc::bind(sigc::ptr_fun(&GigEditState::main_loop_run), |
559 |
&initialized), |
&initialized), |
560 |
false); |
false); |
561 |
#else |
#elif defined(GLIB_THREADS) |
562 |
Glib::Threads::Thread::create( |
Glib::Threads::Thread::create( |
563 |
sigc::bind(sigc::ptr_fun(&GigEditState::main_loop_run), |
sigc::bind(sigc::ptr_fun(&GigEditState::main_loop_run), |
564 |
&initialized)); |
&initialized)); |
565 |
|
#else |
566 |
|
new std::thread([this]() { main_loop_run(&initialized); }); |
567 |
#endif |
#endif |
568 |
#endif |
#endif |
569 |
printf("Waiting for GUI being initialized (on main thread) ....\n"); fflush(stdout); |
printf("Waiting for GUI being initialized (on main thread) ....\n"); fflush(stdout); |