Skip to content

Commit

Permalink
Improve hibernation/suspend (#539, #540)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaelers committed May 12, 2024
1 parent ed93f17 commit e378508
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
9 changes: 8 additions & 1 deletion changes.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
---
releases:
- version: 1.11.0-beta.13
date: 2024-05-12T17:11:00+02:00
short: |-
Workrave 1.11.0-beta.13 has been released.
changes:
- Fix hibernate/suspend (#539, #540)

- version: 1.11.0-beta.12
date: 22024-03-21T19:48:51+01:00
date: 2024-03-21T19:48:51+01:00
short: |-
Workrave 1.11.0-beta.12 has been released.
changes:
Expand Down
31 changes: 26 additions & 5 deletions libs/core/src/Core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,15 @@ Core::process_timewarp()
{
TRACE_MSG("Time warp of {} seconds because of powersave", gap);

force_idle();

TimeSource::set_real_time_sec_sync(last_process_time + 1);
monitor_state = ACTIVITY_IDLE;

process_timers();

TimeSource::sync();

// In case the windows message was lost. some people reported that
// workrave never restarted the timers...
remove_operation_mode_override("powersave");
Expand Down Expand Up @@ -1126,19 +1135,31 @@ Core::process_timewarp()

if (gap >= 30)
{
TRACE_MSG("Time warp of {} seconds. Powersae", gap);
TRACE_MSG("Time warp of {} seconds. Powersave", gap);
spdlog::info("Time warp of {} seconds. Powersave", gap);
TRACE_MSG("current time {}", current_time);
TRACE_MSG("synced time {}", TimeSource::get_real_time_sec_sync());
TRACE_MSG("last process time {}", last_process_time);

force_idle();

int64_t save_current_time = current_time;

current_time = last_process_time + 1;
TimeSource::set_real_time_sec_sync(last_process_time + 1);
monitor_state = ACTIVITY_IDLE;

process_timers();

current_time = save_current_time;
TimeSource::sync();
ret = true;

remove_operation_mode_override("powersave");
}

if (powersave && powersave_resume_time != 0 && current_time > powersave_resume_time + 30)
{
TRACE_MSG("End of time warp after powersave");

powersave = false;
powersave_resume_time = 0;
}
}

Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/Timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ Timer::get_elapsed_idle_time() const
int64_t
Timer::get_elapsed_time() const
{
TRACE_ENTRY();
TRACE_ENTRY_PAR(timer_id, timer_state);
int64_t ret = elapsed_time;

TRACE_VAR(ret, TimeSource::get_real_time_sec_sync(), last_start_time);
Expand Down
3 changes: 3 additions & 0 deletions libs/utils/include/utils/TimeSource.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ namespace workrave::utils
//! Returns the system wall-clock time synchronized with core in seconds.
static int64_t get_real_time_sec_sync();

//! Sets the system wall-clock time synchronized with core in seconds.
static void set_real_time_sec_sync(int64_t t);

//! Returns the system monotonic time synchronized with core in seconds, if available.
static int64_t get_monotonic_time_sec_sync();

Expand Down
6 changes: 6 additions & 0 deletions libs/utils/src/TimeSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ TimeSource::get_real_time_sec_sync()
return synced_real_time / TIME_USEC_PER_SEC;
}

void
TimeSource::set_real_time_sec_sync(int64_t t)
{
synced_real_time = t * TIME_USEC_PER_SEC;
}

int64_t
TimeSource::get_monotonic_time_sec_sync()
{
Expand Down

0 comments on commit e378508

Please sign in to comment.