Ptex: PtexPlatform.h Source File

Ptex

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

PtexPlatform.h
Go to the documentation of this file.
1 #ifndef PtexPlatform_h
2 #define PtexPlatform_h
3 #define PtexPlatform_h
4 /*
5 PTEX SOFTWARE
6 Copyright 2009 Disney Enterprises, Inc. All rights reserved
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are
10 met:
11
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15 * Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in
17 the documentation and/or other materials provided with the
18 distribution.
19
20 * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
21 Studios" or the names of its contributors may NOT be used to
22 endorse or promote products derived from this software without
23 specific prior written permission from Walt Disney Pictures.
24
25 Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
26 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
27 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
28 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
29 IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
30 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37 */
38
43 // platform-specific includes
44 #if defined(_WIN32) || defined(_WINDOWS) || defined(_MSC_VER)
45 #ifndef WINDOWS
46 #define WINDOWS
47 #endif
48 #define _CRT_NONSTDC_NO_DEPRECATE 1
49 #define _CRT_SECURE_NO_DEPRECATE 1
50 #define NOMINMAX 1
51
52 // windows - defined for both Win32 and Win64
53 #include <Windows.h>
54 #include <malloc.h>
55 #include <io.h>
56 #include <tchar.h>
57 #include <process.h>
58
59 #else
60
61 // linux/unix/posix
62 #include <stdlib.h>
63 #include <alloca.h>
64 #include <string.h>
65 #include <pthread.h>
66 // OS for spinlock
67 #ifdef __APPLE__
68 #include <libkern/OSAtomic.h>
69 #include <sys/types.h>
70 #endif
71 #endif
72
73 // general includes
74 #include <stdio.h>
75 #include <math.h>
76 #include <assert.h>
77
78 // missing functions on Windows
79 #ifdef WINDOWS
80 typedef __int64 FilePos;
81 #define fseeko _fseeki64
82 #define ftello _ftelli64
83
84 #else
85 typedef off_t FilePos;
86 #endif
87
88
89 namespace PtexInternal {
90
91 /*
92 * Mutex/SpinLock classes
93 */
94
95 #ifdef WINDOWS
96
97 class _Mutex {
98 public:
99 _Mutex() { _mutex = CreateMutex(NULL, FALSE, NULL); }
100 ~_Mutex() { CloseHandle(_mutex); }
101 void lock() { WaitForSingleObject(_mutex, INFINITE); }
102 void unlock() { ReleaseMutex(_mutex); }
103 private:
104 HANDLE _mutex;
105 };
106
107 class _SpinLock {
108 public:
109 _SpinLock() { InitializeCriticalSection(&_spinlock); }
110 ~_SpinLock() { DeleteCriticalSection(&_spinlock); }
111 void lock() { EnterCriticalSection(&_spinlock); }
112 void unlock() { LeaveCriticalSection(&_spinlock); }
113 private:
114 CRITICAL_SECTION _spinlock;
115 };
116
117 #else
118 // assume linux/unix/posix
119
120 class _Mutex {
121 public:
122 _Mutex() { pthread_mutex_init(&_mutex, 0); }
123 ~_Mutex() { pthread_mutex_destroy(&_mutex); }
124 void lock() { pthread_mutex_lock(&_mutex); }
125 void unlock() { pthread_mutex_unlock(&_mutex); }
126 private:
127 pthread_mutex_t _mutex;
128 };
129
130 #ifdef __APPLE__
131 class _SpinLock {
132 public:
133 _SpinLock() { _spinlock = 0; }
134 ~_SpinLock() { }
135 void lock() { OSSpinLockLock(&_spinlock); }
136 void unlock() { OSSpinLockUnlock(&_spinlock); }
137 private:
138 OSSpinLock _spinlock;
139 };
140 #else
141 class _SpinLock {
142 public:
143 _SpinLock() { pthread_spin_init(&_spinlock, PTHREAD_PROCESS_PRIVATE); }
144 ~_SpinLock() { pthread_spin_destroy(&_spinlock); }
145 void lock() { pthread_spin_lock(&_spinlock); }
146 void unlock() { pthread_spin_unlock(&_spinlock); }
147 private:
148 pthread_spinlock_t _spinlock;
149 };
150 #endif // __APPLE__
151 #endif
152 }
153
154 #endif // PtexPlatform_h
PtexInternal::_Mutex::unlock
void unlock()
Definition: PtexPlatform.h:125
PtexInternal::_Mutex::lock
void lock()
Definition: PtexPlatform.h:124
PtexInternal::_SpinLock::~_SpinLock
~_SpinLock()
Definition: PtexPlatform.h:144
PtexInternal::_Mutex::_Mutex
_Mutex()
Definition: PtexPlatform.h:122
PtexInternal::_Mutex::~_Mutex
~_Mutex()
Definition: PtexPlatform.h:123
PtexInternal::_Mutex
Definition: PtexPlatform.h:120
FilePos
off_t FilePos
Definition: PtexPlatform.h:85
PtexInternal::_SpinLock::unlock
void unlock()
Definition: PtexPlatform.h:146
PtexInternal::_SpinLock::lock
void lock()
Definition: PtexPlatform.h:145
PtexInternal
For internal use only.
Definition: PtexCache.h:48
PtexInternal::_SpinLock
Definition: PtexPlatform.h:141
PtexInternal::_Mutex::_mutex
pthread_mutex_t _mutex
Definition: PtexPlatform.h:127
PtexInternal::_SpinLock::_SpinLock
_SpinLock()
Definition: PtexPlatform.h:143
PtexInternal::_SpinLock::_spinlock
pthread_spinlock_t _spinlock
Definition: PtexPlatform.h:148