-
Notifications
You must be signed in to change notification settings - Fork 0
/
sudoku_linux.cpp
76 lines (64 loc) · 2.23 KB
/
sudoku_linux.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// solver with SSE 4.2 / AVX
// Copyright (C) 2012-2016 Zettsu Tatsuya
// Linux dependent implementation
#include <time.h>
#include <sched.h>
#include "sudoku_os_dependent.h"
namespace Sudoku {
// Need to instantiate this template before being used, or compilation errors occur.
template <> void Timer<TimerPlatform::LINUX, timespec>::reset(void) {
constexpr decltype(startTimestamp_) zeroTimeStamp {0, 0};
startTimestamp_ = zeroTimeStamp;
stopTimestamp_ = zeroTimeStamp;
BaseTimer::reset();
return;
}
template <> Timer<TimerPlatform::LINUX, timespec>::Timer(void) {
reset();
return;
}
template <> void Timer<TimerPlatform::LINUX, timespec>::Reset(void) {
reset();
return;
}
template <> void Timer<TimerPlatform::LINUX, timespec>::getTimeOfSys(timespec& timestamp) {
clock_gettime(CLOCK_MONOTONIC, ×tamp);
return;
}
template <> SudokuTime Timer<TimerPlatform::LINUX, timespec>::convertTimeToNum(const timespec& timestamp) {
SudokuTime timeIn100nsec = timestamp.tv_sec;
timeIn100nsec *= SudokuTimeUsecPerSec;
timeIn100nsec *= SudokuTimeUnitInUsec;
using TimeUnitInUsec = decltype(SudokuTimeUnitInUsec);
constexpr TimeUnitInUsec unitDividend = 1000;
constexpr TimeUnitInUsec unit = unitDividend / SudokuTimeUnitInUsec;
timeIn100nsec += timestamp.tv_nsec / unit;
return timeIn100nsec;
}
template <> ProcessorBinder<TimerPlatform::LINUX>::ProcessorBinder(void) {
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(0, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask)) {
std::cout << "SetProcessAffinityMask failed\n";
failed_ = true;
}
return;
}
std::unique_ptr<ITimer> CreateTimerInstance(void) {
std::unique_ptr<ITimer> pObj(new Timer<TimerPlatform::LINUX, timespec>);
return pObj;
}
std::unique_ptr<IProcessorBinder> CreateProcessorBinder(void) {
std::unique_ptr<IProcessorBinder> pObj(new ProcessorBinder<TimerPlatform::LINUX>);
return pObj;
}
}
/*
Local Variables:
mode: c++
coding: utf-8-unix
tab-width: nil
c-file-style: "stroustrup"
End:
*/