mirror of https://github.com/adamdruppe/arsd.git
Implement Timer.changeTime() for Linux targets
This commit is contained in:
parent
7bd2675b1f
commit
8ffc0b327d
|
@ -5605,12 +5605,7 @@ class Timer {
|
||||||
|
|
||||||
mapping[fd] = this;
|
mapping[fd] = this;
|
||||||
|
|
||||||
itimerspec value;
|
itimerspec value = makeItimerspec(intervalInMilliseconds);
|
||||||
value.it_value.tv_sec = cast(int) (intervalInMilliseconds / 1000);
|
|
||||||
value.it_value.tv_nsec = (intervalInMilliseconds % 1000) * 1000_000;
|
|
||||||
|
|
||||||
value.it_interval.tv_sec = cast(int) (intervalInMilliseconds / 1000);
|
|
||||||
value.it_interval.tv_nsec = (intervalInMilliseconds % 1000) * 1000_000;
|
|
||||||
|
|
||||||
if(timerfd_settime(fd, 0, &value, null) == -1)
|
if(timerfd_settime(fd, 0, &value, null) == -1)
|
||||||
throw new Exception("couldn't make pulse timer");
|
throw new Exception("couldn't make pulse timer");
|
||||||
|
@ -5683,7 +5678,6 @@ class Timer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void changeTime(int intervalInMilliseconds)
|
void changeTime(int intervalInMilliseconds)
|
||||||
{
|
{
|
||||||
this.intervalInMilliseconds = intervalInMilliseconds;
|
this.intervalInMilliseconds = intervalInMilliseconds;
|
||||||
|
@ -5696,6 +5690,15 @@ class Timer {
|
||||||
if(handle is null || !SetWaitableTimer(handle, cast(LARGE_INTEGER*)&initialTime, intervalInMilliseconds, &timerCallback, handle, false))
|
if(handle is null || !SetWaitableTimer(handle, cast(LARGE_INTEGER*)&initialTime, intervalInMilliseconds, &timerCallback, handle, false))
|
||||||
throw new WindowsApiException("couldn't change pulse timer", GetLastError());
|
throw new WindowsApiException("couldn't change pulse timer", GetLastError());
|
||||||
}
|
}
|
||||||
|
} else version(linux) {
|
||||||
|
import core.sys.linux.timerfd;
|
||||||
|
|
||||||
|
itimerspec value = makeItimerspec(intervalInMilliseconds);
|
||||||
|
if(timerfd_settime(fd, 0, &value, null) == -1) {
|
||||||
|
throw new Exception("couldn't change pulse timer");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
assert(false, "Timer.changeTime(int) is not implemented for this platform");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5706,6 +5709,21 @@ class Timer {
|
||||||
|
|
||||||
int lastEventLoopRoundTriggered;
|
int lastEventLoopRoundTriggered;
|
||||||
|
|
||||||
|
version(linux) {
|
||||||
|
static auto makeItimerspec(int intervalInMilliseconds) {
|
||||||
|
import core.sys.linux.timerfd;
|
||||||
|
|
||||||
|
itimerspec value;
|
||||||
|
value.it_value.tv_sec = cast(int) (intervalInMilliseconds / 1000);
|
||||||
|
value.it_value.tv_nsec = (intervalInMilliseconds % 1000) * 1000_000;
|
||||||
|
|
||||||
|
value.it_interval.tv_sec = cast(int) (intervalInMilliseconds / 1000);
|
||||||
|
value.it_interval.tv_nsec = (intervalInMilliseconds % 1000) * 1000_000;
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void trigger() {
|
void trigger() {
|
||||||
version(linux) {
|
version(linux) {
|
||||||
import unix = core.sys.posix.unistd;
|
import unix = core.sys.posix.unistd;
|
||||||
|
|
Loading…
Reference in New Issue