]> git.sesse.net Git - casparcg/blob - tbb/include/tbb/combinable.h
2.0.0.2: Updated tbb version.
[casparcg] / tbb / include / tbb / combinable.h
1 /*
2     Copyright 2005-2011 Intel Corporation.  All Rights Reserved.
3
4     This file is part of Threading Building Blocks.
5
6     Threading Building Blocks is free software; you can redistribute it
7     and/or modify it under the terms of the GNU General Public License
8     version 2 as published by the Free Software Foundation.
9
10     Threading Building Blocks is distributed in the hope that it will be
11     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with Threading Building Blocks; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19     As a special exception, you may use this file as part of a free software
20     library without restriction.  Specifically, if other files instantiate
21     templates or use macros or inline functions from this file, or you compile
22     this file and link it with other files to produce an executable, this
23     file does not by itself cause the resulting executable to be covered by
24     the GNU General Public License.  This exception does not however
25     invalidate any other reasons why the executable file might be covered by
26     the GNU General Public License.
27 */
28
29 #ifndef __TBB_combinable_H
30 #define __TBB_combinable_H
31
32 #include "enumerable_thread_specific.h"
33 #include "cache_aligned_allocator.h"
34
35 namespace tbb {
36 /** \name combinable
37     **/
38 //@{
39 //! Thread-local storage with optional reduction
40 /** @ingroup containers */
41     template <typename T>
42         class combinable {
43     private:
44         typedef typename tbb::cache_aligned_allocator<T> my_alloc;
45
46         typedef typename tbb::enumerable_thread_specific<T, my_alloc, ets_no_key> my_ets_type;
47         my_ets_type my_ets; 
48  
49     public:
50
51         combinable() { }
52
53         template <typename finit>
54         combinable( finit _finit) : my_ets(_finit) { }
55
56         //! destructor
57         ~combinable() { 
58         }
59
60         combinable(const combinable& other) : my_ets(other.my_ets) { }
61
62         combinable & operator=( const combinable & other) { my_ets = other.my_ets; return *this; }
63
64         void clear() { my_ets.clear(); }
65
66         T& local() { return my_ets.local(); }
67
68         T& local(bool & exists) { return my_ets.local(exists); }
69
70         // combine_func_t has signature T(T,T) or T(const T&, const T&)
71         template <typename combine_func_t>
72         T combine(combine_func_t f_combine) { return my_ets.combine(f_combine); }
73
74         // combine_func_t has signature void(T) or void(const T&)
75         template <typename combine_func_t>
76         void combine_each(combine_func_t f_combine) { my_ets.combine_each(f_combine); }
77
78     };
79 } // namespace tbb
80 #endif /* __TBB_combinable_H */