SeExpr
Platform.cpp
Go to the documentation of this file.
1/*
2 Copyright Disney Enterprises, Inc. All rights reserved.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License
6 and the following modification to it: Section 6 Trademarks.
7 deleted and replaced with:
8
9 6. Trademarks. This License does not grant permission to use the
10 trade names, trademarks, service marks, or product names of the
11 Licensor and its affiliates, except as required for reproducing
12 the content of the NOTICE file.
13
14 You may obtain a copy of the License at
15 http://www.apache.org/licenses/LICENSE-2.0
16*/
17
22#include "Platform.h"
23
24#if defined(WINDOWS)
25
26#define _CRT_NONSTDC_NO_DEPRECATE 1
27#define _CRT_SECURE_NO_DEPRECATE 1
28#define NOMINMAX 1
29
30// windows - defined for both Win32 and Win64
31#define WIN32_LEAN_AND_MEAN
32#define VC_EXTRALEAN
33#include <Windows.h>
34
35namespace SeExpr2 {
36
37__int64 Timer::time() {
38 LARGE_INTEGER perfCounter;
39 QueryPerformanceCounter(&perfCounter);
40 return perfCounter.QuadPart;
41}
42
43Timer::Timer() : started(false) {
44 // get the timer frequency
45 LARGE_INTEGER frequency;
46 QueryPerformanceFrequency(&frequency);
47 ticksPerSeconds = frequency.QuadPart;
48}
49
50void Timer::start() {
51 started = true;
52 startTime = this->time();
53}
54
55long Timer::elapsedTime() {
56 stopTime = this->time();
57 return static_cast<long>(((stopTime - startTime) * 1000000) / ticksPerSeconds);
58}
59
60}
61
62namespace SeExprInternal2 {
63
64/*
65 * Mutex/SpinLock classes
66 */
67
69 _mutex = CreateMutex(NULL, FALSE, NULL);
70}
71
73 CloseHandle(_mutex);
74}
75
76void _Mutex::lock() {
77 WaitForSingleObject(_mutex, INFINITE);
78}
79
80void _Mutex::unlock() {
81 ReleaseMutex(_mutex);
82}
83
85 _spinlock = new CRITICAL_SECTION;
86 InitializeCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(_spinlock));
87}
88
90 DeleteCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(_spinlock));
91 delete _spinlock;
92 _spinlock = nullptr;
93}
94
95void _SpinLock::lock() {
96 EnterCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(_spinlock));
97}
98
99void _SpinLock::unlock() {
100 LeaveCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(_spinlock));
101}
102
103}
104
105#endif // defined(WINDOWS)
Platform-specific classes, functions, and includes.
pthread_mutex_t _mutex
Definition Platform.h:203
pthread_spinlock_t _spinlock
Definition Platform.h:226