root/trunk/libffado/src/threads.h

Revision 445, 3.2 kB (checked in by pieterpalmers, 17 years ago)

* name change from FreeBoB to FFADO
* replaced tabs by 4 spaces
* got rid of end-of-line spaces
* made all license and copyrights conform

library becomes LGPL, apps become GPL
explicitly state LGPL v2.1 and GPL v2 (don't like v3 draft)

copyrights are 2005-2007 Daniel & Pieter
except for the MotU stuff (C) Jonathan, Pieter

Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
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 version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #ifndef THREADS_H
25 #define THREADS_H
26
27 #include <semaphore.h>
28
29 class Functor
30 {
31 public:
32     Functor() {}
33     virtual ~Functor() {}
34
35     virtual void operator() () = 0;
36 };
37
38 ////////////////////////////////////////////////////////////////////////
39
40 template< typename CalleePtr, typename MemFunPtr >
41 class MemberFunctor0
42     : public Functor
43 {
44 public:
45     MemberFunctor0( const CalleePtr& pCallee,
46             MemFunPtr pMemFun,
47             bool bDelete = true )
48         : m_pCallee( pCallee )
49         , m_pMemFun( pMemFun )
50         , m_pSem( 0 )
51         , m_bDelete( bDelete )
52         {}
53
54     MemberFunctor0( const CalleePtr& pCallee,
55             MemFunPtr pMemFun,
56             sem_t* pSem,
57             bool bDelete = true )
58         : m_pCallee( pCallee )
59         , m_pMemFun( pMemFun )
60         , m_pSem( pSem )
61         , m_bDelete( bDelete )
62         {}
63
64     virtual ~MemberFunctor0()
65         {}
66
67     virtual void operator() ()
68         {
69             ( ( *m_pCallee ).*m_pMemFun )();
70             if ( m_pSem ) {
71                 sem_post( m_pSem);
72             }
73             if (m_bDelete) {
74             delete this;
75         }
76     }
77
78 private:
79     CalleePtr  m_pCallee;
80     MemFunPtr  m_pMemFun;
81     sem_t* m_pSem;
82     bool       m_bDelete;
83 };
84
85 template< typename CalleePtr, typename MemFunPtr, typename Parm0 >
86 class MemberFunctor1
87     : public Functor
88 {
89 public:
90     MemberFunctor1( const CalleePtr& pCallee,
91             MemFunPtr pMemFun,
92             Parm0 parm0,
93             bool bDelete = true)
94         : m_pCallee( pCallee )
95         , m_pMemFun( pMemFun )
96         , m_parm0( parm0 )
97         , m_pSem( 0 )
98         , m_bDelete( bDelete )
99         {}
100
101     MemberFunctor1( const CalleePtr& pCallee,
102             MemFunPtr pMemFun,
103             Parm0 parm0,
104             sem_t* pSem,
105             bool bDelete = true )
106         : m_pCallee( pCallee )
107         , m_pMemFun( pMemFun )
108         , m_parm0( parm0 )
109         , m_pSem( 0 )
110         , m_bDelete( bDelete )
111         {}
112     virtual ~MemberFunctor1()
113     {}
114
115     virtual void operator() ()
116     {
117             ( ( *m_pCallee ).*m_pMemFun )( m_parm0 );
118             if ( m_pSem ) {
119                 sem_post( m_pSem);
120             }
121             if (m_bDelete) {
122                 delete this;
123             }
124     }
125
126 private:
127     CalleePtr  m_pCallee;
128     MemFunPtr  m_pMemFun;
129     Parm0      m_parm0;
130     sem_t* m_pSem;
131     bool       m_bDelete;
132 };
133
134 #endif
135
136
Note: See TracBrowser for help on using the browser.