src/Pure/Tools/build_process.scala
changeset 77513 43bfb65ee9b3
parent 77511 3d6db917bd1b
child 77514 acaa89cb977b
equal deleted inserted replaced
77512:9853251b958e 77513:43bfb65ee9b3
   145   object State {
   145   object State {
   146     type Sessions = Map[String, Build_Job.Session_Context]
   146     type Sessions = Map[String, Build_Job.Session_Context]
   147     type Pending = List[Entry]
   147     type Pending = List[Entry]
   148     type Running = Map[String, Build_Job]
   148     type Running = Map[String, Build_Job]
   149     type Results = Map[String, Result]
   149     type Results = Map[String, Result]
       
   150 
       
   151     def inc_serial(serial: Long): Long = {
       
   152       require(serial < java.lang.Long.MAX_VALUE, "serial overflow")
       
   153       serial + 1
       
   154     }
   150   }
   155   }
   151 
   156 
   152   // dynamic state of various instances, distinguished by uuid
   157   // dynamic state of various instances, distinguished by uuid
   153   sealed case class State(
   158   sealed case class State(
   154     serial: Long = 0,
   159     serial: Long = 0,
   157     sessions: State.Sessions = Map.empty,   // static build targets
   162     sessions: State.Sessions = Map.empty,   // static build targets
   158     pending: State.Pending = Nil,           // dynamic build "queue"
   163     pending: State.Pending = Nil,           // dynamic build "queue"
   159     running: State.Running = Map.empty,     // presently running jobs
   164     running: State.Running = Map.empty,     // presently running jobs
   160     results: State.Results = Map.empty      // finished results
   165     results: State.Results = Map.empty      // finished results
   161   ) {
   166   ) {
       
   167     require(serial >= 0, "serial underflow")
       
   168     def inc_serial: State = copy(serial = State.inc_serial(serial))
       
   169     def set_serial(i: Long): State = {
       
   170       require(serial <= i, "non-monotonic change of serial")
       
   171       copy(serial = i)
       
   172     }
       
   173 
   162     def echo(progress: Progress, message_serial: Long, message: Progress.Message): State =
   174     def echo(progress: Progress, message_serial: Long, message: Progress.Message): State =
   163       if (message_serial > progress_seen) {
   175       if (message_serial > progress_seen) {
   164         progress.output(message)
   176         progress.output(message)
   165         copy(progress_seen = message_serial)
   177         copy(progress_seen = message_serial)
   166       }
   178       }
   562           update_running(db, state.running),
   574           update_running(db, state.running),
   563           update_results(db, state.results),
   575           update_results(db, state.results),
   564           Host.Data.update_numa_index(db, hostname, state.numa_index))
   576           Host.Data.update_numa_index(db, hostname, state.numa_index))
   565 
   577 
   566       val serial0 = get_serial(db)
   578       val serial0 = get_serial(db)
   567       val serial = if (changed.exists(identity)) serial0 + 1 else serial0
   579       val serial = if (changed.exists(identity)) State.inc_serial(serial0) else serial0
   568 
   580 
   569       set_serial(db, serial)
   581       set_serial(db, serial)
   570       state.copy(serial = serial)
   582       state.set_serial(serial)
   571     }
   583     }
   572   }
   584   }
   573 }
   585 }
   574 
   586 
   575 
   587 
   636   object progress extends Progress {
   648   object progress extends Progress {
   637     override def verbose: Boolean = build_progress.verbose
   649     override def verbose: Boolean = build_progress.verbose
   638 
   650 
   639     override def output(message: Progress.Message): Unit =
   651     override def output(message: Progress.Message): Unit =
   640       synchronized_database {
   652       synchronized_database {
   641         val state1 = _state.copy(serial = _state.serial + 1)
   653         val state1 = _state.inc_serial
   642         for (db <- _database) {
   654         for (db <- _database) {
   643           Build_Process.Data.write_progress(db, state1.serial, message, build_context.uuid)
   655           Build_Process.Data.write_progress(db, state1.serial, message, build_context.uuid)
   644           Build_Process.Data.set_serial(db, state1.serial)
   656           Build_Process.Data.set_serial(db, state1.serial)
   645         }
   657         }
   646         _state =
   658         _state =