Jetson Inference
DNN Vision Library
Event.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __MULTITHREAD_EVENT_H_
24 #define __MULTITHREAD_EVENT_H_
25 
26 #include "Mutex.h"
27 #include "timespec.h"
28 
33 class Event
34 {
35 public:
40  Event( bool auto_reset=true );
41 
45  ~Event();
46 
50  void Wake();
51 
55  inline void Reset() { mQueryMutex.Lock(); mQuery = false; mQueryMutex.Unlock(); }
56 
61  bool Query();
62 
67  bool Wait();
68 
73  bool Wait( const timespec& timeout );
74 
79  inline bool Wait( uint64_t timeout ) { return (timeout == UINT64_MAX) ? Wait() : Wait(timeNew(timeout*1000*1000)); }
80 
85  inline bool WaitNs( uint64_t timeout ) { return (timeout == UINT64_MAX) ? Wait() : Wait(timeNew(timeout)); }
86 
91  inline bool WaitUs( uint64_t timeout ) { return (timeout == UINT64_MAX) ? Wait() : Wait(timeNew(timeout*1000)); }
92 
96  inline pthread_cond_t* GetID() { return &mID; }
97 
98 protected:
99 
100  pthread_cond_t mID;
101 
103  bool mQuery;
105 };
106 
107 
108 #endif
~Event()
Destructor.
pthread_cond_t * GetID()
Get the Event object.
Definition: Event.h:96
A lightweight mutual exclusion lock.
Definition: Mutex.h:35
void Lock()
Aquire the lock, whenever it becomes available.
Definition: Mutex.h:58
bool Query()
Query the status of this event.
void Wake()
Raise the event.
bool Wait(uint64_t timeout)
Wait for a specified number of milliseconds until this event is raised or timeout occurs...
Definition: Event.h:79
Mutex mQueryMutex
Definition: Event.h:102
bool WaitNs(uint64_t timeout)
Wait for a specified number of nanoseconds until this event is raised or timeout occurs.
Definition: Event.h:85
pthread_cond_t mID
Definition: Event.h:100
void Unlock()
Release the lock.
Definition: Mutex.h:63
timespec timeNew(time_t seconds, long int nanoseconds)
Return an initialized timespec
Definition: timespec.h:57
bool WaitUs(uint64_t timeout)
Wait for a specified number of microseconds until this event is raised or timeout occurs...
Definition: Event.h:91
Event(bool auto_reset=true)
Event constructor.
void Reset()
Reset the event status to un-raised.
Definition: Event.h:55
Event object for signalling other threads.
Definition: Event.h:33
bool Wait()
Wait until this event is raised.
bool mQuery
Definition: Event.h:103
bool mAutoReset
Definition: Event.h:104