leonid@255: /* leonid@255: This file is part of CanFestival, a library implementing CanOpen Stack. leonid@255: leonid@255: CanFestival Copyright (C): Edouard TISSERANT and Francis DUPIN leonid@255: CanFestival Win32 port Copyright (C) 2007 Leonid Tochinski, ChattenAssociates, Inc. leonid@255: leonid@255: See COPYING file for copyrights details. leonid@255: leonid@255: This library is free software; you can redistribute it and/or leonid@255: modify it under the terms of the GNU Lesser General Public leonid@255: License as published by the Free Software Foundation; either leonid@255: version 2.1 of the License, or (at your option) any later version. leonid@255: leonid@255: This library is distributed in the hope that it will be useful, leonid@255: but WITHOUT ANY WARRANTY; without even the implied warranty of leonid@255: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU leonid@255: Lesser General Public License for more details. leonid@255: leonid@255: You should have received a copy of the GNU Lesser General Public leonid@255: License along with this library; if not, write to the Free Software leonid@255: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA leonid@255: */ leonid@255: leonid@252: // thread safe que leonid@255: #ifndef __async_access_que_h__ leonid@255: #define __async_access_que_h__ leonid@255: leonid@252: #include leonid@252: #include "AutoReleaseCS.h" leonid@252: leonid@252: template leonid@252: class async_access_que leonid@252: { leonid@252: public: leonid@252: async_access_que() leonid@252: { leonid@252: ::InitializeCriticalSection(&m_cs); leonid@252: } leonid@252: ~async_access_que() leonid@252: { leonid@252: ::DeleteCriticalSection(&m_cs); leonid@252: } leonid@252: leonid@252: void append(const type& data) leonid@252: { leonid@252: AutoReleaseCS acs(m_cs); leonid@252: m_data.push_back(data); leonid@252: } leonid@252: leonid@252: bool extract_top(type& data) leonid@252: { leonid@252: AutoReleaseCS acs(m_cs); leonid@252: if (m_data.empty()) leonid@252: return false; leonid@252: data = m_data.front(); leonid@252: m_data.pop_front(); leonid@252: return true; leonid@252: } leonid@252: leonid@252: void clear() leonid@252: { leonid@252: AutoReleaseCS acs(m_cs); leonid@252: m_data.clear(); leonid@252: } leonid@252: leonid@252: protected: leonid@252: std::deque m_data; leonid@252: CRITICAL_SECTION m_cs; leonid@252: }; leonid@255: #endif //__async_access_que_h__