--- gigedit/trunk/src/gigedit/mainwindow.cpp 2019/02/16 19:13:37 3471 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2019/02/16 19:56:56 3472 @@ -21,12 +21,6 @@ #include #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 -#endif #include #include @@ -1894,7 +1888,11 @@ LoaderSaverBase::LoaderSaverBase(const Glib::ustring filename, gig::File* gig) : - filename(filename), gig(gig), thread(0), progress(0.f) + filename(filename), gig(gig), +#ifdef GLIB_THREADS + thread(0), +#endif + progress(0.f) { } @@ -1907,7 +1905,11 @@ void LoaderSaverBase::progress_callback(float fraction) { { +#ifdef GLIB_THREADS Glib::Threads::Mutex::Lock lock(progressMutex); +#else + std::lock_guard lock(progressMutex); +#endif progress = fraction; } progress_dispatcher(); @@ -1919,8 +1921,12 @@ #endif void LoaderSaverBase::thread_function() { +#ifdef GLIB_THREADS printf("thread_function self=%p\n", static_cast(Glib::Threads::Thread::self())); +#else + std::cout << "thread_function self=" << std::this_thread::get_id() << "\n"; +#endif printf("Start %s\n", filename.c_str()); try { gig::progress_t progress; @@ -1941,17 +1947,26 @@ void LoaderSaverBase::launch() { +#ifdef GLIB_THREADS #ifdef OLD_THREADS thread = Glib::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function), true); #else thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function)); #endif printf("launch thread=%p\n", static_cast(thread)); +#else + thread = std::thread([this](){ thread_function(); }); + std::cout << "launch thread=" << thread.get_id() << "\n"; +#endif } float LoaderSaverBase::get_progress() { +#ifdef GLIB_THREADS Glib::Threads::Mutex::Lock lock(progressMutex); +#else + std::lock_guard lock(progressMutex); +#endif return progress; } @@ -1971,7 +1986,11 @@ } void LoaderSaverBase::join() { +#ifdef GLIB_THREADS thread->join(); +#else + thread.join(); +#endif } @@ -2188,8 +2207,13 @@ if (dialog.run() == Gtk::RESPONSE_OK) { std::string filename = dialog.get_filename(); printf("filename=%s\n", filename.c_str()); +#ifdef GLIB_THREADS printf("on_action_file_open self=%p\n", static_cast(Glib::Threads::Thread::self())); +#else + std::cout << "on_action_file_open self=" << + std::this_thread::get_id() << "\n"; +#endif load_file(filename.c_str()); current_gig_dir = Glib::path_get_dirname(filename); } @@ -2264,8 +2288,13 @@ { loader->join(); printf("Loader finished!\n"); +#ifdef GLIB_THREADS printf("on_loader_finished self=%p\n", static_cast(Glib::Threads::Thread::self())); +#else + std::cout << "on_loader_finished self=" << + std::this_thread::get_id() << "\n"; +#endif load_gig(loader->gig, loader->filename.c_str()); progress_dialog->hide(); } @@ -4988,8 +5017,13 @@ #endif if (dialog.run() == Gtk::RESPONSE_OK) { +#ifdef GLIB_THREADS printf("on_action_merge_files self=%p\n", static_cast(Glib::Threads::Thread::self())); +#else + std::cout << "on_action_merge_files self=" << + std::this_thread::get_id() << "\n"; +#endif std::vector filenames = dialog.get_filenames(); // merge the selected files to the currently open .gig file