255
|
1 |
/*
|
|
2 |
This file is part of CanFestival, a library implementing CanOpen Stack.
|
|
3 |
|
|
4 |
CanFestival Copyright (C): Edouard TISSERANT and Francis DUPIN
|
|
5 |
CanFestival Win32 port Copyright (C) 2007 Leonid Tochinski, ChattenAssociates, Inc.
|
|
6 |
|
|
7 |
See COPYING file for copyrights details.
|
|
8 |
|
|
9 |
This library is free software; you can redistribute it and/or
|
|
10 |
modify it under the terms of the GNU Lesser General Public
|
|
11 |
License as published by the Free Software Foundation; either
|
|
12 |
version 2.1 of the License, or (at your option) any later version.
|
|
13 |
|
|
14 |
This library is distributed in the hope that it will be useful,
|
|
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 |
Lesser General Public License for more details.
|
|
18 |
|
|
19 |
You should have received a copy of the GNU Lesser General Public
|
|
20 |
License along with this library; if not, write to the Free Software
|
|
21 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
22 |
*/
|
|
23 |
|
252
|
24 |
// thread safe que
|
255
|
25 |
#ifndef __async_access_que_h__
|
|
26 |
#define __async_access_que_h__
|
|
27 |
|
252
|
28 |
#include <deque>
|
|
29 |
#include "AutoReleaseCS.h"
|
|
30 |
|
|
31 |
template<typename type>
|
|
32 |
class async_access_que
|
|
33 |
{
|
|
34 |
public:
|
|
35 |
async_access_que()
|
|
36 |
{
|
|
37 |
::InitializeCriticalSection(&m_cs);
|
|
38 |
}
|
|
39 |
~async_access_que()
|
|
40 |
{
|
|
41 |
::DeleteCriticalSection(&m_cs);
|
|
42 |
}
|
|
43 |
|
|
44 |
void append(const type& data)
|
|
45 |
{
|
|
46 |
AutoReleaseCS acs(m_cs);
|
|
47 |
m_data.push_back(data);
|
|
48 |
}
|
|
49 |
|
|
50 |
bool extract_top(type& data)
|
|
51 |
{
|
|
52 |
AutoReleaseCS acs(m_cs);
|
|
53 |
if (m_data.empty())
|
|
54 |
return false;
|
|
55 |
data = m_data.front();
|
|
56 |
m_data.pop_front();
|
|
57 |
return true;
|
|
58 |
}
|
|
59 |
|
|
60 |
void clear()
|
|
61 |
{
|
|
62 |
AutoReleaseCS acs(m_cs);
|
|
63 |
m_data.clear();
|
|
64 |
}
|
|
65 |
|
|
66 |
protected:
|
|
67 |
std::deque<type> m_data;
|
|
68 |
CRITICAL_SECTION m_cs;
|
|
69 |
};
|
255
|
70 |
#endif //__async_access_que_h__ |