@@ -78,46 +78,40 @@ namespace internal
7878
7979 typename std::aligned_storage<sizeof (Functor), _CPP_TASK_CACHE_LINE_SIZE_>::type functors[splitCount];
8080
81- TaskManager* manager = TaskManager::GetCurrent ();
82- if (manager != nullptr )
81+ auto & manager = TaskManager::GetCurrent ();
82+
83+ for (size_t i = 0 ; i != splitCount; ++i)
8384 {
84- for (size_t i = 0 ; i != splitCount; ++i)
85- {
86- new (functors + i)Functor (functor, SplitMark ());
85+ new (functors + i)Functor (functor, SplitMark ());
8786
88- TASK * ptr = new TASK (ranges[i],
89- *reinterpret_cast <Functor*>(functors + i),
90- myDepth - 1 );
87+ TASK * ptr = new TASK (ranges[i],
88+ *reinterpret_cast <Functor*>(functors + i),
89+ myDepth - 1 );
9190
92- tasks[i].reset (ptr);
93- manager-> AddTask (*tasks[i]);
94- };
91+ tasks[i].reset (ptr);
92+ manager. AddTask (*tasks[i]);
93+ };
9594
96- for (size_t i = 0 ; i != splitCount; ++i)
97- {
98- manager-> WaitTask (*tasks[i]);
99- };
95+ for (size_t i = 0 ; i != splitCount; ++i)
96+ {
97+ manager. WaitTask (*tasks[i]);
98+ };
10099
101- // check exceptions in child tasks
102- for (size_t i = 0 ; i != splitCount; ++i)
103- {
104- if (tasks[i]->GetLastException () != nullptr )
105- {
106- std::rethrow_exception (tasks[i]->GetLastException ());
107- }
108- };
109-
110- // Join
111- for (size_t i = 1 ; i != splitCount; ++i)
100+ // check exceptions in child tasks
101+ for (size_t i = 0 ; i != splitCount; ++i)
102+ {
103+ if (tasks[i]->GetLastException () != nullptr )
112104 {
113- tasks[0 ]->Join (*tasks[i] );
105+ std::rethrow_exception ( tasks[i ]->GetLastException () );
114106 }
115- Join (*tasks[0 ]);
116- }
117- else
107+ };
108+
109+ // Join
110+ for (size_t i = 1 ; i != splitCount; ++i)
118111 {
119- throw Exception ( " Can't acquire current task manager " );
112+ tasks[ 0 ]-> Join (*tasks[i] );
120113 }
114+ Join (*tasks[0 ]);
121115 }
122116 else
123117 {
@@ -135,22 +129,16 @@ namespace internal
135129template <class Iterator , class Functor >
136130inline void ParallelReduce (Iterator start, Iterator end, Functor& functor, size_t maxDepth = 5 )
137131{
138- TaskManager* manager = TaskManager::GetCurrent ();
139- if (manager != nullptr )
140- {
141- typedef Range<Iterator> RANGE ;
142- typedef internal::ReduceTask<RANGE , Functor> TASK ;
143- TASK task (RANGE (start, end), functor, maxDepth);
144- manager->AddTask (task);
145- manager->WaitTask (task);
146- if (task.GetLastException () != nullptr )
147- {
148- std::rethrow_exception (task.GetLastException ());
149- }
150- }
151- else
132+ auto & manager = TaskManager::GetCurrent ();
133+
134+ typedef Range<Iterator> RANGE ;
135+ typedef internal::ReduceTask<RANGE , Functor> TASK ;
136+ TASK task (RANGE (start, end), functor, maxDepth);
137+ manager.AddTask (task);
138+ manager.WaitTask (task);
139+ if (task.GetLastException () != nullptr )
152140 {
153- throw Exception ( " Can't acquire current task manager " );
141+ std::rethrow_exception ( task. GetLastException () );
154142 }
155143}
156144
0 commit comments