root/trunk/libffado/src/threads.h

Revision 864, 3.1 kB (checked in by ppalmers, 16 years ago)

update license to GPLv2 or GPLv3 instead of GPLv2 or any later version. Update copyrights to reflect the new year

Line 
1 /*
2  * Copyright (C) 2005-2008 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 program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program 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
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
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.