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