VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtLockedBufferedQueue.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2007 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #ifndef DtLockedBufferedQueue_H_
11 #define DtLockedBufferedQueue_H_
12 
13 #include <vrvUtil/vrvUtil.h>
14 #include <vlutil/vlMutex.h>
15 #include <vector>
16 
17 namespace makVrv
18 {
23  template <typename T>
25  {
26  public:
28 
33 
34 
38  unsigned int push(T value);
39 
44  unsigned int push( std::vector<T>& valueVector );
45 
65  void getForReading(std::vector<T>*& output);
66 
71  void deleteAllPointers();
72 
78  void nullAllPointers();
79 
83  void clearBuffers();
84 
85  protected:
86 
89  void swapBuffers();
90 
91  std::vector<T> myFirstBuffer;
92  std::vector<T> mySecondBuffer;
93  std::vector<T>* myCurrentBuffer;
94 
95  DtMutex myBufferMutex;
96  };
97 
98 }
99 
100 #define DtLockedBufferedQueue_INL_
101 #include <vrvUtil/DtLockedBufferedQueue.inl>
102 #undef DtLockedBufferedQueue_INL_
103 
104 
105 #endif
106 
void nullAllPointers()
Helper function for setting all member pointers to null in both buffers (for reference pointers...
void getForReading(std::vector< T > *&output)
Get a vector for reading. This function should only be called by the reader thread. The pointer reference is written to, and can be initially null. The pointer is guaranteed to be valid and not NULL after a call to getForReading. The pointer is only valid until the next call to getForReading. There is no need to clear the buffer when reading is done. The contents of the output will not change until the next call to getForReading. All iterators are invalidated with the next call to getForReading.
~DtLockedBufferedQueue()
DTOR If the type T is a pointer memory must be explicitly deleting by iterating throug both vectors c...
void swapBuffers()
Internal function for swapping buffers and clearing the write buffer.
Contains DLL export macros.
unsigned int push(T value)
Add a value to to the buffer. This function is thread safe and reentrant. The return value is the cur...
std::vector< T > myFirstBuffer
Definition: DtLockedBufferedQueue.h:91
A locked buffered queue which allows multiple writers and a single reader. Internally the queue is st...
Definition: DtLockedBufferedQueue.h:24
void deleteAllPointers()
Helper function for deleting all member pointers in both buffers. This function is not valid if T is ...
DtMutex myBufferMutex
Definition: DtLockedBufferedQueue.h:95
std::vector< T > mySecondBuffer
Definition: DtLockedBufferedQueue.h:92
void clearBuffers()
Helper function to clear all the buffers, if the buffers contain pointers call deleteAllPointers() fi...
std::vector< T > * myCurrentBuffer
Definition: DtLockedBufferedQueue.h:93

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)