The Pedigree Project 0.1
TickSource.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef KERNEL_MACHINE_HOSTED_TICKSOURCE_H
21#define KERNEL_MACHINE_HOSTED_TICKSOURCE_H
22#include <config.h>
23#include <pthread.h>
24#include <signal.h>
25#include <stddef.h>
26#include <stdint.h>
27#include <time.h>
28
31 public:
32 enum class TakeResult {
33 NotSource,
34 Expirations,
35 Invalid,
36 };
37
40
41 bool prepare(int signal, void* owner);
42 bool arm(uint64_t intervalNanoseconds);
43 bool disarm();
44 void destroy();
45
46 TakeResult takeExpirations(const siginfo_t* info, size_t& expirations);
47
48#if HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS
50 bool queueExpirationForTest();
51#endif
52
53 private:
54 HostedTickSource(const HostedTickSource&) = delete;
55 HostedTickSource& operator=(const HostedTickSource&) = delete;
56
57#if defined(__linux__)
58 timer_t m_Timer;
59#else
60 static void* helperEntry(void* source);
61 void helper();
62 bool recordExpirations(size_t expirations);
63
64 pthread_t m_TargetThread;
65 pthread_t m_HelperThread;
66 pthread_mutex_t m_Mutex;
67 pthread_cond_t m_Condition;
68 uint64_t m_IntervalNanoseconds;
69 size_t m_PendingExpirations;
70 size_t m_Generation;
71 bool m_Armed;
72 bool m_Delivering;
73 bool m_Stop;
74 bool m_Failed;
75 bool m_HelperStarted;
76#endif
77
78#if HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS && defined(__linux__)
79 size_t m_InjectedExpirations;
80#endif
81 int m_Signal;
82 void* m_Owner;
83 bool m_Prepared;
84};
85
86#endif