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