RigsofRods
Soft-body Physics Simulation
InterThreadStoreVector.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5 
6  For more information, see http://www.rigsofrods.org/
7 
8  Rigs of Rods is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License version 3, as
10  published by the Free Software Foundation.
11 
12  Rigs of Rods is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #pragma once
22 
23 #include "Application.h"
24 
25 #include <mutex>
26 
28 template <class T>
30 {
31 public:
32 
33  void push(T v)
34  {
35  std::lock_guard<std::mutex> lock(m_vector_mutex);
36  store.push_back(v);
37  }
38 
39  void pull(std::vector<T>& res)
40  {
41  std::lock_guard<std::mutex> lock(m_vector_mutex);
42  res = store;
43  store.clear();
44  }
45 
46 protected:
47 
48  std::mutex m_vector_mutex;
49  std::vector<T> store;
50 };
InterThreadStoreVector
this class is a helper to exchange data in a class between different threads, it can be pushed and pu...
Definition: InterThreadStoreVector.h:29
Application.h
Central state/object manager and communications hub.
InterThreadStoreVector::push
void push(T v)
Definition: InterThreadStoreVector.h:33
InterThreadStoreVector::m_vector_mutex
std::mutex m_vector_mutex
Definition: InterThreadStoreVector.h:48
InterThreadStoreVector::store
std::vector< T > store
Definition: InterThreadStoreVector.h:49
InterThreadStoreVector::pull
void pull(std::vector< T > &res)
Definition: InterThreadStoreVector.h:39