"Fossies" - the Fresh Open Source Software Archive

Member "src/Platform/Mutex.h" (10 Oct 2018, 1390 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Mutex.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #ifndef TC_HEADER_Platform_Mutex
   14 #define TC_HEADER_Platform_Mutex
   15 
   16 #ifdef TC_WINDOWS
   17 #   include "System.h"
   18 #else
   19 #   include <pthread.h>
   20 #endif
   21 #include "PlatformBase.h"
   22 
   23 namespace VeraCrypt
   24 {
   25     class Mutex
   26     {
   27 #ifdef TC_WINDOWS
   28         typedef CRITICAL_SECTION SystemMutex_t;
   29 #else
   30         typedef pthread_mutex_t SystemMutex_t;
   31 #endif
   32 
   33     public:
   34         Mutex ();
   35         ~Mutex ();
   36 
   37         SystemMutex_t *GetSystemHandle () { return &SystemMutex; }
   38         void Lock ();
   39         void Unlock ();
   40 
   41     protected:
   42         bool Initialized;
   43         SystemMutex_t SystemMutex;
   44 
   45     private:
   46         Mutex (const Mutex &);
   47         Mutex &operator= (const Mutex &);
   48     };
   49 
   50     class ScopeLock
   51     {
   52     public:
   53         ScopeLock (Mutex &mutex) : ScopeMutex (mutex) { mutex.Lock(); }
   54         ~ScopeLock () { ScopeMutex.Unlock(); }
   55 
   56     protected:
   57         Mutex &ScopeMutex;
   58 
   59     private:
   60         ScopeLock (const ScopeLock &);
   61         ScopeLock &operator= (const ScopeLock &);
   62     };
   63 }
   64 
   65 #endif // TC_HEADER_Platform_Mutex