Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
scheduler_utility.h
Go to the documentation of this file.
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 
18 
19 */
20 
21 #ifndef _TBB_scheduler_utility_H
22 #define _TBB_scheduler_utility_H
23 
24 #include "scheduler.h"
25 
26 namespace tbb {
27 namespace internal {
28 
29 //------------------------------------------------------------------------
30 // auto_empty_task
31 //------------------------------------------------------------------------
32 
37 public:
39  : my_task( new(&s->allocate_task(sizeof(empty_task), __TBB_CONTEXT_ARG(NULL, context))) empty_task )
40  , my_scheduler(s)
41  {}
42  // empty_task has trivial destructor, so there's no need to call it.
44 
45  operator task& () { return *my_task; }
46  task* operator & () { return my_task; }
47  task_prefix& prefix () { return my_task->prefix(); }
48 }; // class auto_empty_task
49 
50 //------------------------------------------------------------------------
51 // fast_reverse_vector
52 //------------------------------------------------------------------------
53 
55 
59 template<typename T, size_t max_segments = 16>
61 {
62 public:
63  fast_reverse_vector ( T* initial_segment, size_t segment_size )
64  : m_cur_segment(initial_segment)
65  , m_cur_segment_size(segment_size)
66  , m_pos(segment_size)
67  , m_num_segments(0)
68  , m_size(0)
69  {
70  __TBB_ASSERT ( initial_segment && segment_size, "Nonempty initial segment must be supplied");
71  }
72 
74  {
75  for ( size_t i = 1; i < m_num_segments; ++i )
76  NFS_Free( m_segments[i] );
77  }
78 
79  size_t size () const { return m_size + m_cur_segment_size - m_pos; }
80 
81  void push_back ( const T& val )
82  {
83  if ( !m_pos ) {
86  m_cur_segment_size *= 2;
89  __TBB_ASSERT ( m_num_segments < max_segments, "Maximal capacity exceeded" );
90  }
91  m_cur_segment[--m_pos] = val;
92  }
93 
95 
96  void copy_memory ( T* dst ) const
97  {
98  size_t sz = m_cur_segment_size - m_pos;
99  memcpy( dst, m_cur_segment + m_pos, sz * sizeof(T) );
100  dst += sz;
101  sz = m_cur_segment_size / 2;
102  for ( long i = (long)m_num_segments - 2; i >= 0; --i ) {
103  memcpy( dst, m_segments[i], sz * sizeof(T) );
104  dst += sz;
105  sz /= 2;
106  }
107  }
108 
109 protected:
112 
115 
117  size_t m_pos;
118 
120  T *m_segments[max_segments];
121 
124 
126  size_t m_size;
127 
128 }; // class fast_reverse_vector
129 
130 } // namespace internal
131 } // namespace tbb
132 
133 #endif /* _TBB_scheduler_utility_H */
void *__TBB_EXPORTED_FUNC NFS_Allocate(size_t n_element, size_t element_size, void *hint)
Allocate memory on cache/sector line boundary.
#define __TBB_CONTEXT_ARG(arg1, context)
Memory prefix to a task object.
Definition: task.h:188
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
task that does nothing. Useful for synchronization.
Definition: task.h:959
Used to form groups of tasks.
Definition: task.h:335
size_t m_size
Number of items in the segments in m_segments.
Vector that grows without reallocations, and stores items in the reverse order.
Base class for user-defined tasks.
Definition: task.h:592
Work stealing task scheduler.
Definition: scheduler.h:124
Smart holder for the empty task class with automatic destruction.
size_t m_pos
Insertion position in m_cur_segment.
size_t m_cur_segment_size
Capacity of m_cur_segment.
fast_reverse_vector(T *initial_segment, size_t segment_size)
The graph class.
generic_scheduler * my_scheduler
void const char const char int ITT_FORMAT __itt_group_sync s
T * m_segments[max_segments]
Array of segments (has fixed size specified by the second template parameter)
void copy_memory(T *dst) const
Copies the contents of the vector into the dst array.
T * m_cur_segment
The current (not completely filled) segment.
void __TBB_EXPORTED_FUNC NFS_Free(void *)
Free memory allocated by NFS_Allocate.
internal::task_prefix & prefix(internal::version_tag *=NULL) const
Get reference to corresponding task_prefix.
Definition: task.h:941
Bitwise-OR of local_task and small_task.
void free_task(task &t)
Put task on free list.
Definition: scheduler.h:652
auto_empty_task(__TBB_CONTEXT_ARG(generic_scheduler *s, task_group_context *context))
size_t m_num_segments
Number of segments (the size of m_segments)

Copyright © 2005-2019 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.