src/Pure/System/progress.scala
changeset 78356 974dbe256a37
parent 78266 d8c99a497502
child 78382 6c211e1c94d5
equal deleted inserted replaced
78355:9fbc6a043268 78356:974dbe256a37
   257   private var _seen: Long = 0
   257   private var _seen: Long = 0
   258 
   258 
   259   def agent_uuid: String = synchronized { _agent_uuid }
   259   def agent_uuid: String = synchronized { _agent_uuid }
   260 
   260 
   261   private def init(): Unit = synchronized {
   261   private def init(): Unit = synchronized {
   262     Progress.Data.transaction_lock(db, create = true) {
   262     Progress.Data.transaction_lock(db, create = true, label = "Database_Progress.init") {
   263       Progress.Data.read_progress_context(db, context_uuid) match {
   263       Progress.Data.read_progress_context(db, context_uuid) match {
   264         case Some(context) =>
   264         case Some(context) =>
   265           _context = context
   265           _context = context
   266           _agent_uuid = UUID.random().toString
   266           _agent_uuid = UUID.random().toString
   267         case None =>
   267         case None =>
   294     if (context_uuid == _agent_uuid) db.vacuum(Progress.Data.tables)
   294     if (context_uuid == _agent_uuid) db.vacuum(Progress.Data.tables)
   295   }
   295   }
   296 
   296 
   297   def exit(close: Boolean = false): Unit = synchronized {
   297   def exit(close: Boolean = false): Unit = synchronized {
   298     if (_context > 0) {
   298     if (_context > 0) {
   299       Progress.Data.transaction_lock(db) {
   299       Progress.Data.transaction_lock(db, label = "Database_Progress.exit") {
   300         Progress.Data.update_agent(db, _agent_uuid, _seen, stop_now = true)
   300         Progress.Data.update_agent(db, _agent_uuid, _seen, stop_now = true)
   301       }
   301       }
   302       _context = 0
   302       _context = 0
   303     }
   303     }
   304     if (close) db.close()
   304     if (close) db.close()
   305   }
   305   }
   306 
   306 
   307   private def sync_database[A](body: => A): A = synchronized {
   307   private def sync_database[A](body: => A): A = synchronized {
   308     require(_context > 0)
   308     require(_context > 0)
   309     Progress.Data.transaction_lock(db) {
   309     Progress.Data.transaction_lock(db, label = "Database_Progress.sync") {
   310       val stopped_db = Progress.Data.read_progress_stopped(db, _context)
   310       val stopped_db = Progress.Data.read_progress_stopped(db, _context)
   311       val stopped = base_progress.stopped
   311       val stopped = base_progress.stopped
   312 
   312 
   313       if (stopped_db && !stopped) base_progress.stop()
   313       if (stopped_db && !stopped) base_progress.stop()
   314       if (stopped && !stopped_db) Progress.Data.write_progress_stopped(db, _context, true)
   314       if (stopped && !stopped_db) Progress.Data.write_progress_stopped(db, _context, true)