AJA NTV2 SDK  17.5.0.1492
NTV2 SDK 17.5.0.1492
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 }
lockimpl.h
Declares the AJALockImpl class.
LOCK_TIME_INFINITE
#define LOCK_TIME_INFINITE
Definition: lock.h:18
lockimpl.h
Declares the AJALockImpl class.
NULL
#define NULL
Definition: ntv2caption608types.h:19
AJA_STATUS_SUCCESS
@ AJA_STATUS_SUCCESS
Definition: types.h:381
AJALockImpl
Definition: lockimpl.h:18
nlohmann::json_abiNLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON_v3_11_NLOHMANN_JSON_VERSION_PATCH::detail::void
j template void())
Definition: json.hpp:4893
AJAStatus
AJAStatus
Definition: types.h:378
lock.h
Declares the AJALock class.
AJAAutoLock::~AJAAutoLock
virtual ~AJAAutoLock()
Definition: lock.cpp:111
AJALock::AJALock
AJALock(const char *pName=NULL)
Definition: lock.cpp:26
AJALock::Lock
virtual AJAStatus Lock(uint32_t timeout=0xffffffff)
Definition: lock.cpp:70
AJALock
Definition: lock.h:28
lockimpl.h
Declares the AJALockImpl class.
AJA_STATUS_TIMEOUT
@ AJA_STATUS_TIMEOUT
Definition: types.h:384
std
Definition: json.hpp:5362
AJALock::operator=
virtual AJALock & operator=(const AJALock &inLock)
Definition: lock.cpp:49
AJAAutoLock::AJAAutoLock
AJAAutoLock(AJALock *pLock=NULL)
Definition: lock.cpp:101
AJALock::Unlock
virtual AJAStatus Unlock()
Definition: lock.cpp:90
AJALock::~AJALock
virtual ~AJALock()
Definition: lock.cpp:56
lockimpl.h