Logo Search packages:      
Sourcecode: djvulibre version File versions

void DjVuFile::stop_decode ( bool  sync  ) 

Stops decode. If sync# is 1 then the function will not return until the decoding thread actually dies. Otherwise it will just signal the thread to stop and will return immediately. Decoding of all included files will be stopped too.

Definition at line 1391 of file DjVuFile.cpp.

References wait_for_finish().

Referenced by DjVuDocument::~DjVuDocument().

{
  check();
  
  DEBUG_MSG("DjVuFile::stop_decode(), url='" << url <<
    "', sync=" << (int) sync << "\n");
  DEBUG_MAKE_INDENT(3);
  
  G_TRY
  {
    flags|=DONT_START_DECODE;
    
    // Don't stop SYNCHRONOUSLY from the thread where the decoding is going!!!
    {
      // First - ask every included child to stop in async mode
      GCriticalSectionLock lock(&inc_files_lock);
      for(GPosition pos=inc_files_list;pos;++pos)
        inc_files_list[pos]->stop_decode(0);
      
//      if (decode_data_pool) decode_data_pool->stop();
    }
    
    if (sync)
    {
      while(1)
      {
        GP<DjVuFile> file;
        {
          GCriticalSectionLock lock(&inc_files_lock);
          for(GPosition pos=inc_files_list;pos;++pos)
          {
            GP<DjVuFile> & f=inc_files_list[pos];
            if (f->is_decoding())
            {
              file=f; break;
            }
          }
        }
        if (!file) break;
        
        file->stop_decode(1);
      }
      
      wait_for_finish(1);     // Wait for self termination
      
      // Don't delete the thread here. Until GPBase::preserve() is
      // reimplemented somehow at the GThread level.
      // delete decode_thread; decode_thread=0;
    }
    flags&=~(DONT_START_DECODE);
  } G_CATCH_ALL {
    flags&=~(DONT_START_DECODE);
    G_RETHROW;
  } G_ENDCATCH;
}


Generated by  Doxygen 1.6.0   Back to index