mirror of
				https://github.com/rad4day/Waybar.git
				synced 2025-10-28 23:12:29 +01:00 
			
		
		
		
	Merge pull request #1500 from RobertMueller2/clock-thread-sleep
Replace sleep_until with sleep_for to prevent clock from getting stuck with system time adjustment
This commit is contained in:
		| @@ -75,9 +75,10 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) | ||||
|   thread_ = [this] { | ||||
|     dp.emit(); | ||||
|     auto now = std::chrono::system_clock::now(); | ||||
|     auto timeout = std::chrono::floor<std::chrono::seconds>(now + interval_); | ||||
|     auto diff = std::chrono::seconds(timeout.time_since_epoch().count() % interval_.count()); | ||||
|     thread_.sleep_until(timeout - diff); | ||||
|     /* difference with projected wakeup time */ | ||||
|     auto diff = now.time_since_epoch() % interval_; | ||||
|     /* sleep until the next projected time */ | ||||
|     thread_.sleep_for(interval_ - diff); | ||||
|   }; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -7,9 +7,10 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) | ||||
|   thread_ = [this] { | ||||
|     dp.emit(); | ||||
|     auto now = std::chrono::system_clock::now(); | ||||
|     auto timeout = std::chrono::floor<std::chrono::seconds>(now + interval_); | ||||
|     auto diff = std::chrono::seconds(timeout.time_since_epoch().count() % interval_.count()); | ||||
|     thread_.sleep_until(timeout - diff); | ||||
|     /* difference with projected wakeup time */ | ||||
|     auto diff = now.time_since_epoch() % interval_; | ||||
|     /* sleep until the next projected time */ | ||||
|     thread_.sleep_for(interval_ - diff); | ||||
|   }; | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Alex
					Alex