vSMC
vSMC: Scalable Monte Carlo
dispatch_group.hpp
Go to the documentation of this file.
1 //============================================================================
2 // vSMC/include/vsmc/gcd/dispatch_group.hpp
3 //----------------------------------------------------------------------------
4 // vSMC: Scalable Monte Carlo
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013,2014, Yan Zhou
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 //============================================================================
31 
32 #ifndef VSMC_GCD_DISPATCH_GROUP_HPP
33 #define VSMC_GCD_DISPATCH_GROUP_HPP
34 
35 #include <vsmc/internal/common.hpp>
38 #include <dispatch/dispatch.h>
39 
40 namespace vsmc {
41 
44 class DispatchGroup : public DispatchObject< ::dispatch_group_t>
45 {
46  public :
47 
49  DispatchObject< ::dispatch_group_t>(::dispatch_group_create(), true) {}
50 
51  void enter () const {::dispatch_group_enter(this->object());}
52 
53  void leave () const {::dispatch_group_leave(this->object());}
54 
55  long wait (::dispatch_time_t timeout) const
56  {return ::dispatch_group_wait(this->object(), timeout);}
57 
58  template <DispatchQueueType Type>
59  void async_f (const DispatchQueue<Type> &queue, void *context,
60  ::dispatch_function_t work) const
61  {::dispatch_group_async_f(this->object(), queue.object(), context, work);}
62 
63  void async_f (::dispatch_queue_t queue, void *context,
64  ::dispatch_function_t work) const
65  {::dispatch_group_async_f(this->object(), queue, context, work);}
66 
67  template <DispatchQueueType Type>
68  void notify_f (const DispatchQueue<Type> &queue, void *context,
69  ::dispatch_function_t work) const
70  {::dispatch_group_notify_f(this->object(), queue.object(), context, work);}
71 
72  void notify_f (::dispatch_queue_t queue, void *context,
73  ::dispatch_function_t work) const
74  {::dispatch_group_notify_f(this->object(), queue, context, work);}
75 
76 #ifdef __BLOCKS__
77  template <DispatchQueueType Type>
78  void async (const DispatchQueue<Type> &queue,
79  ::dispatch_block_t block) const
80  {::dispatch_group_async(this->object(), queue.object(), block);}
81 
82  void async (::dispatch_queue_t queue,
83  ::dispatch_block_t block) const
84  {::dispatch_group_async(this->object(), queue, block);}
85 
86  template <DispatchQueueType Type>
87  void notify (const DispatchQueue<Type> &queue,
88  ::dispatch_block_t block) const
89  {::dispatch_group_notify(this->object(), queue.object(), block);}
90 
91  void notify (::dispatch_queue_t queue,
92  ::dispatch_block_t block) const
93  {::dispatch_group_notify(this->object(), queue, block);}
94 #endif // __BLOCKS__
95 }; // class DispatchGroup
96 
97 } // namespace vsmc
98 
99 #endif // VSMC_GCD_DISPATCH_GROUP_HPP
Definition: adapter.hpp:37
A Dispatch group.
void notify(::dispatch_queue_t queue,::dispatch_block_t block) const
void async_f(::dispatch_queue_t queue, void *context,::dispatch_function_t work) const
Base class of Dispatch objects.
void async(const DispatchQueue< Type > &queue,::dispatch_block_t block) const
void notify_f(const DispatchQueue< Type > &queue, void *context,::dispatch_function_t work) const
void async_f(const DispatchQueue< Type > &queue, void *context,::dispatch_function_t work) const
void async(::dispatch_queue_t queue,::dispatch_block_t block) const
void notify_f(::dispatch_queue_t queue, void *context,::dispatch_function_t work) const
long wait(::dispatch_time_t timeout) const
void notify(const DispatchQueue< Type > &queue,::dispatch_block_t block) const