Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 22:38:16 +00:00
|
|
|
/*
|
2017-03-24 22:13:54 +00:00
|
|
|
* Copyright (c) 2013, 2016, 2017 Jonas 'Sortie' Termansen.
|
Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 22:38:16 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* sortix/kernel/clock.h
|
|
|
|
* A virtual clock that can be measured and waited upon.
|
|
|
|
*/
|
2013-10-13 21:56:58 +00:00
|
|
|
|
2022-07-07 23:09:15 +00:00
|
|
|
#ifndef _INCLUDE_SORTIX_KERNEL_CLOCK_H
|
|
|
|
#define _INCLUDE_SORTIX_KERNEL_CLOCK_H
|
2013-10-13 21:56:58 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <sortix/timespec.h>
|
|
|
|
|
|
|
|
#include <sortix/kernel/kthread.h>
|
2017-03-24 22:13:54 +00:00
|
|
|
#include <sortix/kernel/interrupt.h>
|
2013-10-13 21:56:58 +00:00
|
|
|
|
|
|
|
namespace Sortix {
|
|
|
|
|
|
|
|
class Clock;
|
|
|
|
class Timer;
|
|
|
|
|
|
|
|
class Clock
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Clock();
|
|
|
|
~Clock();
|
|
|
|
|
|
|
|
public:
|
|
|
|
Timer* delay_timer;
|
|
|
|
Timer* absolute_timer;
|
2017-03-24 22:13:54 +00:00
|
|
|
Timer* first_interrupt_timer;
|
|
|
|
Timer* last_interrupt_timer;
|
|
|
|
struct interrupt_work interrupt_work;
|
2013-10-13 21:56:58 +00:00
|
|
|
struct timespec current_time;
|
2013-05-14 16:41:49 +00:00
|
|
|
struct timespec current_advancement;
|
2013-10-13 21:56:58 +00:00
|
|
|
struct timespec resolution;
|
|
|
|
kthread_mutex_t clock_mutex;
|
|
|
|
bool clock_callable_from_interrupt;
|
|
|
|
bool we_disabled_interrupts;
|
2017-03-24 22:13:54 +00:00
|
|
|
bool interrupt_work_scheduled;
|
2013-10-13 21:56:58 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
void SetCallableFromInterrupts(bool callable_from_interrupts);
|
|
|
|
void Set(struct timespec* now, struct timespec* res);
|
|
|
|
void Get(struct timespec* now, struct timespec* res);
|
|
|
|
void Advance(struct timespec duration);
|
|
|
|
void Register(Timer* timer);
|
|
|
|
void Unlink(Timer* timer);
|
|
|
|
void Cancel(Timer* timer);
|
2016-12-03 17:10:52 +00:00
|
|
|
bool TryCancel(Timer* timer);
|
2013-10-13 21:56:58 +00:00
|
|
|
void LockClock();
|
|
|
|
void UnlockClock();
|
2013-05-14 16:41:49 +00:00
|
|
|
struct timespec SleepDelay(struct timespec duration);
|
|
|
|
struct timespec SleepUntil(struct timespec expiration);
|
2013-10-13 21:56:58 +00:00
|
|
|
|
|
|
|
public: // These should only be called if the clock is locked.
|
|
|
|
void RegisterAbsolute(Timer* timer);
|
|
|
|
void RegisterDelay(Timer* timer);
|
|
|
|
void UnlinkAbsolute(Timer* timer);
|
|
|
|
void UnlinkDelay(Timer* timer);
|
|
|
|
|
|
|
|
private: // These should only be called if the clock is locked.
|
|
|
|
void FireTimer(Timer* timer);
|
|
|
|
void TriggerDelay(struct timespec unaccounted);
|
|
|
|
void TriggerAbsolute();
|
|
|
|
|
2017-03-24 22:13:54 +00:00
|
|
|
public: // Only for use by Clock__InterruptWork.
|
|
|
|
void InterruptWork();
|
|
|
|
|
2013-10-13 21:56:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Sortix
|
|
|
|
|
|
|
|
#endif
|