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 
35 namespace SeExpr2 {
36 
37 __int64 Timer::time() {
38  LARGE_INTEGER perfCounter;
39  QueryPerformanceCounter(&perfCounter);
40  return perfCounter.QuadPart;
41 }
42 
43 Timer::Timer() : started(false) {
44  // get the timer frequency
45  LARGE_INTEGER frequency;
46  QueryPerformanceFrequency(&frequency);
47  ticksPerSeconds = frequency.QuadPart;
48 }
49 
50 void Timer::start() {
51  started = true;
52  startTime = this->time();
53 }
54 
55 long Timer::elapsedTime() {
56  stopTime = this->time();
57  return static_cast<long>(((stopTime - startTime) * 1000000) / ticksPerSeconds);
58 }
59 
60 }
61 
62 namespace SeExprInternal2 {
63 
64 /*
65  * Mutex/SpinLock classes
66  */
67 
69  _mutex = CreateMutex(NULL, FALSE, NULL);
70 }
71 
73  CloseHandle(_mutex);
74 }
75 
76 void _Mutex::lock() {
77  WaitForSingleObject(_mutex, INFINITE);
78 }
79 
80 void _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 
95 void _SpinLock::lock() {
96  EnterCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(_spinlock));
97 }
98 
99 void _SpinLock::unlock() {
100  LeaveCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(_spinlock));
101 }
102 
103 }
104 
105 #endif // defined(WINDOWS)
Platform.h
Platform-specific classes, functions, and includes.
SeExprInternal2::_Mutex::unlock
void unlock()
Definition: Platform.h:200
SeExpr2
Definition: Context.h:22
SeExprInternal2::_Mutex::_mutex
pthread_mutex_t _mutex
Definition: Platform.h:203
SeExprInternal2::_SpinLock::~_SpinLock
~_SpinLock()
Definition: Platform.h:221
SeExprInternal2::_Mutex::~_Mutex
~_Mutex()
Definition: Platform.h:198
SeExpr2::Timer::Timer
Timer()
Definition: Platform.h:109
SeExprInternal2::_SpinLock::lock
void lock()
Definition: Platform.h:222
SeExprInternal2::_SpinLock::_SpinLock
_SpinLock()
Definition: Platform.h:220
SeExprInternal2
Definition: Mutex.h:25
SeExprInternal2::_SpinLock::unlock
void unlock()
Definition: Platform.h:223
SeExprInternal2::_Mutex::_Mutex
_Mutex()
Definition: Platform.h:197
SeExprInternal2::_SpinLock::_spinlock
pthread_spinlock_t _spinlock
Definition: Platform.h:226
SeExprInternal2::_Mutex::lock
void lock()
Definition: Platform.h:199