mirror of
				https://github.com/Zygo/bees.git
				synced 2025-11-04 04:00:36 +01:00 
			
		
		
		
	task: replace waiting state with run/exec counter
Task::run() would schedule a new execution of Task, unless it was waiting on a queue for execution. This cannot be implemented with a bool, since a Task might be included in multiple queues, and should still be in waiting state even when executed in that case. Replace the bool with a counter. run() and append() (but not append_nolock) increment the counter, exec() decrements the counter. If the counter is non-zero when run() or append() is called, the Task is not scheduled. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
		@@ -27,17 +27,20 @@ namespace crucible {
 | 
			
		||||
		/// Create Task object containing closure and description.
 | 
			
		||||
		Task(string title, function<void()> exec_fn);
 | 
			
		||||
 | 
			
		||||
		/// Schedule Task for at least one future execution.
 | 
			
		||||
		/// Schedule Task for at most one future execution.
 | 
			
		||||
		/// May run Task in current thread or in other thread.
 | 
			
		||||
		/// May run Task before or after returning.
 | 
			
		||||
		/// Schedules Task at the end of the global execution queue.
 | 
			
		||||
		///
 | 
			
		||||
		/// Only one instance of a Task may execute at a time.
 | 
			
		||||
		/// If a Task is already scheduled, run() does nothing.
 | 
			
		||||
		/// If a Task is already running, run() reschedules the
 | 
			
		||||
		/// task after the currently running instance returns.
 | 
			
		||||
		/// If a Task is already running when a new instance reaches
 | 
			
		||||
		/// the front of the queue, the new instance will execute
 | 
			
		||||
		/// after the current instance exits.
 | 
			
		||||
		void run() const;
 | 
			
		||||
 | 
			
		||||
		/// Schedule Task to run after this task has run at least once.
 | 
			
		||||
		/// Schedule Task to run after this Task has run or
 | 
			
		||||
		/// been destroyed.
 | 
			
		||||
		void append(const Task &task) const;
 | 
			
		||||
 | 
			
		||||
		/// Describe Task as text.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user