AJA NTV2 SDK  18.0.0.2122
NTV2 SDK 18.0.0.2122
lock.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #include "ajabase/system/lock.h"
9 #if defined(AJA_USE_CPLUSPLUS11) && !defined(AJA_BAREMETAL)
10  #include <chrono>
11  using namespace std;
12 #else
13  // include the system dependent implementation class
14  #if defined(AJA_WINDOWS)
16  #elif defined(AJA_LINUX)
18  #elif defined(AJA_MAC)
20  #elif defined(AJA_BAREMETAL)
22  #endif
23 #endif
24 
25 
26 AJALock::AJALock(const char* pName)
27 {
28 #if defined(AJA_USE_CPLUSPLUS11) && !defined(AJA_BAREMETAL)
29  mpMutex = new recursive_timed_mutex;
30  if (pName != nullptr)
31  mName = pName;
32 #else
33  mpImpl = NULL;
34  mpImpl = new AJALockImpl(pName);
35 #endif
36 }
37 
38 AJALock::AJALock (const AJALock & inLock)
39 { // Copy constructor -- only name is copied...
40 #if defined(AJA_USE_CPLUSPLUS11) && !defined(AJA_BAREMETAL)
41  mpMutex = new recursive_timed_mutex;
42  mName = inLock.mName;
43 #else
44  mpImpl = NULL;
45  mpImpl = new AJALockImpl(NULL); // FOR NOW, NAME NOT COPIED -- TBD: inLock.mpImpl->mName);
46 #endif
47 }
48 
50 { // Assignment operator -- no-op
51  (void) inLock;
52  return *this;
53 }
54 
55 
57 {
58 #if defined(AJA_USE_CPLUSPLUS11) && !defined(AJA_BAREMETAL)
59  delete mpMutex;
60  mpMutex = nullptr;
61 #else
62  if(mpImpl)
63  delete mpImpl;
64 #endif
65 }
66 
67 // interface to the implementation class
68 
70 AJALock::Lock(uint32_t timeout)
71 {
72 #if defined(AJA_USE_CPLUSPLUS11) && !defined(AJA_BAREMETAL)
73  if (timeout != LOCK_TIME_INFINITE)
74  {
75  bool success = mpMutex->try_lock_for(std::chrono::milliseconds(timeout));
76  return success ? AJA_STATUS_SUCCESS : AJA_STATUS_TIMEOUT;
77  }
78  else
79  {
80  mpMutex->lock();
81  return AJA_STATUS_SUCCESS;
82  }
83 #else
84  return mpImpl->Lock(timeout);
85 #endif
86 }
87 
88 
91 {
92 #if defined(AJA_USE_CPLUSPLUS11) && !defined(AJA_BAREMETAL)
93  mpMutex->unlock();
94  return AJA_STATUS_SUCCESS;
95 #else
96  return mpImpl->Unlock();
97 #endif
98 }
99 
100 
102 {
103  mpLock = pLock;
104  if (mpLock)
105  {
106  mpLock->Lock();
107  }
108 }
109 
110 
112 {
113  if (mpLock)
114  {
115  mpLock->Unlock();
116  }
117 }
Declares the AJALock class.
virtual ~AJAAutoLock()
Definition: lock.cpp:111
#define NULL
virtual AJAStatus Lock(uint32_t timeout=0xffffffff)
Definition: lock.cpp:70
CHAR * pName
Definition: amvideo.cpp:26
Declares the AJALockImpl class.
AJAStatus
Definition: types.h:380
virtual ~AJALock()
Definition: lock.cpp:56
Declares the AJALockImpl class.
Definition: lock.h:28
Definition: json.hpp:5362
virtual AJAStatus Unlock()
Definition: lock.cpp:90
Declares the AJALockImpl class.
#define LOCK_TIME_INFINITE
Definition: lock.h:18
AJAAutoLock(AJALock *pLock=NULL)
Definition: lock.cpp:101
virtual AJALock & operator=(const AJALock &inLock)
Definition: lock.cpp:49
AJALock(const char *pName=NULL)
Definition: lock.cpp:26