/[svn]/gigedit/trunk/src/gigedit/mainwindow.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/mainwindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3471 by persson, Sat Feb 16 19:13:37 2019 UTC revision 3472 by persson, Sat Feb 16 19:56:56 2019 UTC
# Line 21  Line 21 
21  #include <cstring>  #include <cstring>
22    
23  #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  
24    
25  #include <glibmm/convert.h>  #include <glibmm/convert.h>
26  #include <glibmm/dispatcher.h>  #include <glibmm/dispatcher.h>
# Line 1894  void MainWindow::on_sel_change() Line 1888  void MainWindow::on_sel_change()
1888    
1889    
1890  LoaderSaverBase::LoaderSaverBase(const Glib::ustring filename, gig::File* gig) :  LoaderSaverBase::LoaderSaverBase(const Glib::ustring filename, gig::File* gig) :
1891      filename(filename), gig(gig), thread(0), progress(0.f)      filename(filename), gig(gig),
1892    #ifdef GLIB_THREADS
1893        thread(0),
1894    #endif
1895        progress(0.f)
1896  {  {
1897  }  }
1898    
# Line 1907  void loader_progress_callback(gig::progr Line 1905  void loader_progress_callback(gig::progr
1905  void LoaderSaverBase::progress_callback(float fraction)  void LoaderSaverBase::progress_callback(float fraction)
1906  {  {
1907      {      {
1908    #ifdef GLIB_THREADS
1909          Glib::Threads::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
1910    #else
1911            std::lock_guard<std::mutex> lock(progressMutex);
1912    #endif
1913          progress = fraction;          progress = fraction;
1914      }      }
1915      progress_dispatcher();      progress_dispatcher();
# Line 1919  __attribute__((force_align_arg_pointer)) Line 1921  __attribute__((force_align_arg_pointer))
1921  #endif  #endif
1922  void LoaderSaverBase::thread_function()  void LoaderSaverBase::thread_function()
1923  {  {
1924    #ifdef GLIB_THREADS
1925      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
1926             static_cast<void*>(Glib::Threads::Thread::self()));             static_cast<void*>(Glib::Threads::Thread::self()));
1927    #else
1928        std::cout << "thread_function self=" << std::this_thread::get_id() << "\n";
1929    #endif
1930      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1931      try {      try {
1932          gig::progress_t progress;          gig::progress_t progress;
# Line 1941  void LoaderSaverBase::thread_function() Line 1947  void LoaderSaverBase::thread_function()
1947    
1948  void LoaderSaverBase::launch()  void LoaderSaverBase::launch()
1949  {  {
1950    #ifdef GLIB_THREADS
1951  #ifdef OLD_THREADS  #ifdef OLD_THREADS
1952      thread = Glib::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function), true);
1953  #else  #else
1954      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function));
1955  #endif  #endif
1956      printf("launch thread=%p\n", static_cast<void*>(thread));      printf("launch thread=%p\n", static_cast<void*>(thread));
1957    #else
1958        thread = std::thread([this](){ thread_function(); });
1959        std::cout << "launch thread=" << thread.get_id() << "\n";
1960    #endif
1961  }  }
1962    
1963  float LoaderSaverBase::get_progress()  float LoaderSaverBase::get_progress()
1964  {  {
1965    #ifdef GLIB_THREADS
1966      Glib::Threads::Mutex::Lock lock(progressMutex);      Glib::Threads::Mutex::Lock lock(progressMutex);
1967    #else
1968        std::lock_guard<std::mutex> lock(progressMutex);
1969    #endif
1970      return progress;      return progress;
1971  }  }
1972    
# Line 1971  Glib::Dispatcher& LoaderSaverBase::signa Line 1986  Glib::Dispatcher& LoaderSaverBase::signa
1986  }  }
1987    
1988  void LoaderSaverBase::join() {  void LoaderSaverBase::join() {
1989    #ifdef GLIB_THREADS
1990      thread->join();      thread->join();
1991    #else
1992        thread.join();
1993    #endif
1994  }  }
1995    
1996    
# Line 2188  void MainWindow::on_action_file_open() Line 2207  void MainWindow::on_action_file_open()
2207      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
2208          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
2209          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
2210    #ifdef GLIB_THREADS
2211          printf("on_action_file_open self=%p\n",          printf("on_action_file_open self=%p\n",
2212                 static_cast<void*>(Glib::Threads::Thread::self()));                 static_cast<void*>(Glib::Threads::Thread::self()));
2213    #else
2214            std::cout << "on_action_file_open self=" <<
2215                std::this_thread::get_id() << "\n";
2216    #endif
2217          load_file(filename.c_str());          load_file(filename.c_str());
2218          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
2219      }      }
# Line 2264  void MainWindow::on_loader_finished() Line 2288  void MainWindow::on_loader_finished()
2288  {  {
2289      loader->join();      loader->join();
2290      printf("Loader finished!\n");      printf("Loader finished!\n");
2291    #ifdef GLIB_THREADS
2292      printf("on_loader_finished self=%p\n",      printf("on_loader_finished self=%p\n",
2293             static_cast<void*>(Glib::Threads::Thread::self()));             static_cast<void*>(Glib::Threads::Thread::self()));
2294    #else
2295        std::cout << "on_loader_finished self=" <<
2296            std::this_thread::get_id() << "\n";
2297    #endif
2298      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
2299      progress_dialog->hide();      progress_dialog->hide();
2300  }  }
# Line 4988  void MainWindow::on_action_merge_files() Line 5017  void MainWindow::on_action_merge_files()
5017  #endif  #endif
5018    
5019      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
5020    #ifdef GLIB_THREADS
5021          printf("on_action_merge_files self=%p\n",          printf("on_action_merge_files self=%p\n",
5022                 static_cast<void*>(Glib::Threads::Thread::self()));                 static_cast<void*>(Glib::Threads::Thread::self()));
5023    #else
5024            std::cout << "on_action_merge_files self=" <<
5025                std::this_thread::get_id() << "\n";
5026    #endif
5027          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
5028    
5029          // merge the selected files to the currently open .gig file          // merge the selected files to the currently open .gig file

Legend:
Removed from v.3471  
changed lines
  Added in v.3472

  ViewVC Help
Powered by ViewVC