1 | /* |
2 | Copyright (c) 2005-2019 Intel Corporation |
3 | |
4 | Licensed under the Apache License, Version 2.0 (the "License"); |
5 | you may not use this file except in compliance with the License. |
6 | You may obtain a copy of the License at |
7 | |
8 | http://www.apache.org/licenses/LICENSE-2.0 |
9 | |
10 | Unless required by applicable law or agreed to in writing, software |
11 | distributed under the License is distributed on an "AS IS" BASIS, |
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | See the License for the specific language governing permissions and |
14 | limitations under the License. |
15 | */ |
16 | |
17 | #include "tbb/task.h" |
18 | #include "harness.h" |
19 | |
20 | //! Helper for verifying that old use cases of spawn syntax still work. |
21 | tbb::task* GetTaskPtr( int& counter ) { |
22 | ++counter; |
23 | return NULL; |
24 | } |
25 | |
26 | class TaskGenerator: public tbb::task { |
27 | int m_ChildCount; |
28 | int m_Depth; |
29 | |
30 | public: |
31 | TaskGenerator( int child_count, int _depth ) : m_ChildCount(child_count), m_Depth(_depth) {} |
32 | ~TaskGenerator( ) { m_ChildCount = m_Depth = -125; } |
33 | |
34 | tbb::task* execute() __TBB_override { |
35 | ASSERT( m_ChildCount>=0 && m_Depth>=0, NULL ); |
36 | if( m_Depth>0 ) { |
37 | recycle_as_safe_continuation(); |
38 | set_ref_count( m_ChildCount+1 ); |
39 | int k=0; |
40 | for( int j=0; j<m_ChildCount; ++j ) { |
41 | tbb::task& t = *new( allocate_child() ) TaskGenerator(m_ChildCount/2,m_Depth-1); |
42 | GetTaskPtr(k)->spawn(t); |
43 | } |
44 | ASSERT(k==m_ChildCount,NULL); |
45 | --m_Depth; |
46 | __TBB_Yield(); |
47 | ASSERT( state()==recycle && ref_count()>0, NULL); |
48 | } |
49 | return NULL; |
50 | } |
51 | }; |
52 | |