Main Page Class List Class Members

- Main Page
- User's Guide
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# sdk/extensions/authoring/source/VHACD/inc/vhacdMutex.h

Go to the documentation of this file.

    00001
    00049 #pragma once
    00050 #ifndef VHACD_MUTEX_H
    00051 #define VHACD_MUTEX_H
    00052
    00053 #if defined(WIN32)
    00054
    00055 #ifndef _WIN32_WINNT
    00056 #define _WIN32_WINNT 0x400
    00057 #endif
    00058 #include <windows.h>
    00059 #pragma comment(lib, "winmm.lib")
    00060 #endif
    00061
    00062 #if defined(__linux__)
    00063 //#include <sys/time.h>
    00064 #include <errno.h>
    00065 #include <time.h>
    00066 #include <unistd.h>
    00067 #define __stdcall
    00068 #endif
    00069
    00070 #if defined(__APPLE__) || defined(__linux__)
    00071 #include <pthread.h>
    00072 #endif
    00073
    00074 #if defined(__APPLE__)
    00075 #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
    00076 #endif
    00077
    00078 #define VHACD_DEBUG
    00079
    00080 //#define VHACD_NDEBUG
    00081 #ifdef VHACD_NDEBUG
    00082 #define VHACD_VERIFY(x) (x)
    00083 #else
    00084 #define VHACD_VERIFY(x) assert((x))
    00085 #endif
    00086
    00087 namespace VHACD {
    00088 class Mutex {
    00089 public:
    00090     Mutex(void)
    00091     {
    00092 #if defined(WIN32) || defined(_XBOX)
    00093         InitializeCriticalSection(&m_mutex);
    00094 #elif defined(__APPLE__) || defined(__linux__)
    00095         pthread_mutexattr_t mutexAttr; // Mutex Attribute
    00096         VHACD_VERIFY(pthread_mutexattr_init(&mutexAttr) == 0);
    00097         VHACD_VERIFY(pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE_NP) == 0);
    00098         VHACD_VERIFY(pthread_mutex_init(&m_mutex, &mutexAttr) == 0);
    00099         VHACD_VERIFY(pthread_mutexattr_destroy(&mutexAttr) == 0);
    00100 #endif
    00101     }
    00102     ~Mutex(void)
    00103     {
    00104 #if defined(WIN32) || defined(_XBOX)
    00105         DeleteCriticalSection(&m_mutex);
    00106 #elif defined(__APPLE__) || defined(__linux__)
    00107         VHACD_VERIFY(pthread_mutex_destroy(&m_mutex) == 0);
    00108 #endif
    00109     }
    00110     void Lock(void)
    00111     {
    00112 #if defined(WIN32) || defined(_XBOX)
    00113         EnterCriticalSection(&m_mutex);
    00114 #elif defined(__APPLE__) || defined(__linux__)
    00115         VHACD_VERIFY(pthread_mutex_lock(&m_mutex) == 0);
    00116 #endif
    00117     }
    00118     bool TryLock(void)
    00119     {
    00120 #if defined(WIN32) || defined(_XBOX)
    00121         bool bRet = false;
    00122         //assert(("TryEnterCriticalSection seems to not work on XP???", 0));
    00123         bRet = TryEnterCriticalSection(&m_mutex) ? true : false;
    00124         return bRet;
    00125 #elif defined(__APPLE__) || defined(__linux__)
    00126         int32_t result = pthread_mutex_trylock(&m_mutex);
    00127         return (result == 0);
    00128 #endif
    00129     }
    00130
    00131     void Unlock(void)
    00132     {
    00133 #if defined(WIN32) || defined(_XBOX)
    00134         LeaveCriticalSection(&m_mutex);
    00135 #elif defined(__APPLE__) || defined(__linux__)
    00136         VHACD_VERIFY(pthread_mutex_unlock(&m_mutex) == 0);
    00137 #endif
    00138     }
    00139
    00140 private:
    00141 #if defined(WIN32) || defined(_XBOX)
    00142     CRITICAL_SECTION m_mutex;
    00143 #elif defined(__APPLE__) || defined(__linux__)
    00144     pthread_mutex_t m_mutex;
    00145 #endif
    00146 };
    00147 }
    00148 #endif // VHACD_MUTEX_H

Copyright © 2015-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com