Argus Camera Sample Argus Camera Sample

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConditionVariable.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of NVIDIA CORPORATION nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef CAMERA_COMMON_CONDITION_VARIABLE_H
30 #define CAMERA_COMMON_CONDITION_VARIABLE_H
31
32 #include <pthread.h>
33
34 namespace ArgusSamples
35 {
36
37 class Mutex;
38
39 /**
40 * Conditional
41 */
42 class ConditionVariable
43 {
44 public:
45 ConditionVariable();
46 ~ConditionVariable();
47
48 /**
49 * Create the underlying condition variable. This method must be called before any other
50 * methods.
51 */
52 bool initialize();
53
54 /**
55 * Destroy the underlying condition variable. After this call, this object can no longer be used
56 * (until and unless a future call to @c initialize()). Calling this method if the
57 * object is not initialized generates no error, but silently returns.
58 */
59 bool shutdown();
60
61 /**
62 * Broadcast the condition variable. This method is declared @c const for convenience.
63 */
64 bool broadcast() const;
65
66 /**
67 * Signal the condition variable. This method is declared @c const for convenience.
68 */
69 bool signal() const;
70
71 /**
72 * Wait on the condition variable. This method is declared @c const for convenience.
73 * @param [in] mutex The mutex that will be released while waiting. When multiple threads
74 * are waiting concurrently, they must all be using the same mutex.
75 */
76 bool wait(const Mutex& mutex) const;
77
78 private:
79 bool m_initialized;
80 /**
81 * pthread conditional variable, this is 'mutable' so that 'const' functions can be used.
82 */
83 mutable pthread_cond_t m_cond;
84
85 /**
86 * Hide copy constructor and assignment operator
87 */
88 ConditionVariable(ConditionVariable &other);
89 const ConditionVariable& operator = (const ConditionVariable&);
90 };
91
92 } // namespace ArgusSamples
93
94 #endif // CAMERA_COMMON_CONDITION_VARIABLE_H