APEX Framework: Lock.h Source File

NVIDIA APEX

Lock.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008-2017, NVIDIA CORPORATION.  All rights reserved.
00003  *
00004  * NVIDIA CORPORATION and its licensors retain all intellectual property
00005  * and proprietary rights in and to this software, related documentation
00006  * and any modifications thereto.  Any use, reproduction, disclosure or
00007  * distribution of this software and related documentation without an express
00008  * license agreement from NVIDIA CORPORATION is strictly prohibited.
00009  */
00010 
00011 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00012 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  
00013 
00014 
00015 #ifndef LOCK_H
00016 #define LOCK_H
00017 
00023 #include "ApexInterface.h"
00024 
00025 namespace nvidia
00026 {
00027 namespace apex
00028 {
00029 
00040 class ReadLock
00041 {
00042     ReadLock(const ReadLock&);
00043     ReadLock& operator=(const ReadLock&);
00044 
00045 public:
00046     
00053     ReadLock(const ApexInterface& lockable, const char* file=NULL, uint32_t line=0)
00054         : mLockable(lockable)
00055     {
00056         mLockable.acquireReadLock(file, line);
00057     }
00058 
00059     ~ReadLock()
00060     {
00061         mLockable.releaseReadLock();
00062     }
00063 
00064 private:
00065 
00066     const ApexInterface& mLockable;
00067 };
00068 
00079 class WriteLock
00080 {
00081     WriteLock(const WriteLock&);
00082     WriteLock& operator=(const WriteLock&);
00083 
00084 public:
00085 
00092     WriteLock(const ApexInterface& lockable, const char* file=NULL, uint32_t line=0)
00093         : mLockable(lockable)
00094     {
00095         mLockable.acquireWriteLock(file, line);
00096     }
00097 
00098     ~WriteLock()
00099     {
00100         mLockable.releaseWriteLock();
00101     }
00102 
00103 private:
00104     const ApexInterface& mLockable;
00105 };
00106 
00107 
00108 } // namespace apex
00109 } // namespace nvidia
00110 
00114 #define WRITE_LOCK(LOCKABLE) nvidia::apex::WriteLock __WriteLock(LOCKABLE, __FILE__, __LINE__);
00115 
00118 #define READ_LOCK(LOCKABLE) nvidia::apex::ReadLock __ReadLock(LOCKABLE, __FILE__, __LINE__);
00119 
00121 #endif

Generated on Fri Dec 15 2017 13:58:35
Copyright © 2012-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.