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 #ifndef _TBB_scheduler_utility_H
18 #define _TBB_scheduler_utility_H
19 
20 #include "scheduler.h"
21 
22 namespace tbb {
23 namespace internal {
24 
25 //------------------------------------------------------------------------
26 // auto_empty_task
27 //------------------------------------------------------------------------
28 
33 public:
35  : my_task( new(&s->allocate_task(sizeof(empty_task), __TBB_CONTEXT_ARG(NULL, context))) empty_task )
36  , my_scheduler(s)
37  {}
38  // empty_task has trivial destructor, so there's no need to call it.
40 
41  operator task& () { return *my_task; }
42  task* operator & () { return my_task; }
43  task_prefix& prefix () { return my_task->prefix(); }
44 }; // class auto_empty_task
45 
46 //------------------------------------------------------------------------
47 // fast_reverse_vector
48 //------------------------------------------------------------------------
49 
51 
55 template<typename T, size_t max_segments = 16>
57 {
58 public:
59  fast_reverse_vector ( T* initial_segment, size_t segment_size )
60  : m_cur_segment(initial_segment)
61  , m_cur_segment_size(segment_size)
62  , m_pos(segment_size)
63  , m_num_segments(0)
64  , m_size(0)
65  {
66  __TBB_ASSERT ( initial_segment && segment_size, "Nonempty initial segment must be supplied");
67  }
68 
70  {
71  for ( size_t i = 1; i < m_num_segments; ++i )
72  NFS_Free( m_segments[i] );
73  }
74 
75  size_t size () const { return m_size + m_cur_segment_size - m_pos; }
76 
77  void push_back ( const T& val )
78  {
79  if ( !m_pos ) {
82  m_cur_segment_size *= 2;
85  __TBB_ASSERT ( m_num_segments < max_segments, "Maximal capacity exceeded" );
86  }
87  m_cur_segment[--m_pos] = val;
88  }
89 
91 
92  void copy_memory ( T* dst ) const
93  {
94  size_t sz = m_cur_segment_size - m_pos;
95  memcpy( dst, m_cur_segment + m_pos, sz * sizeof(T) );
96  dst += sz;
97  sz = m_cur_segment_size / 2;
98  for ( long i = (long)m_num_segments - 2; i >= 0; --i ) {
99  memcpy( dst, m_segments[i], sz * sizeof(T) );
100  dst += sz;
101  sz /= 2;
102  }
103  }
104 
105 protected:
108 
111 
113  size_t m_pos;
114 
116  T *m_segments[max_segments];
117 
120 
122  size_t m_size;
123 
124 }; // class fast_reverse_vector
125 
126 } // namespace internal
127 } // namespace tbb
128 
129 #endif /* _TBB_scheduler_utility_H */
void copy_memory(T *dst) const
Copies the contents of the vector into the dst array.
Memory prefix to a task object.
Definition: task.h:184
void const char const char int ITT_FORMAT __itt_group_sync s
T * m_cur_segment
The current (not completely filled) segment.
task that does nothing. Useful for synchronization.
Definition: task.h:964
Used to form groups of tasks.
Definition: task.h:332
T * m_segments[max_segments]
Array of segments (has fixed size specified by the second template parameter)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
Vector that grows without reallocations, and stores items in the reverse order.
Base class for user-defined tasks.
Definition: task.h:589
Work stealing task scheduler.
Definition: scheduler.h:120
void __TBB_EXPORTED_FUNC NFS_Free(void *)
Free memory allocated by NFS_Allocate.
The graph class.
Smart holder for the empty task class with automatic destruction.
void *__TBB_EXPORTED_FUNC NFS_Allocate(size_t n_element, size_t element_size, void *hint)
Allocate memory on cache/sector line boundary.
size_t m_size
Number of items in the segments in m_segments.
size_t m_num_segments
Number of segments (the size of m_segments)
Bitwise-OR of local_task and small_task.
#define __TBB_CONTEXT_ARG(arg1, context)
void free_task(task &t)
Put task on free list.
Definition: scheduler.h:648
size_t m_cur_segment_size
Capacity of m_cur_segment.
fast_reverse_vector(T *initial_segment, size_t segment_size)
auto_empty_task(__TBB_CONTEXT_ARG(generic_scheduler *s, task_group_context *context))
generic_scheduler * my_scheduler
internal::task_prefix & prefix(internal::version_tag *=NULL) const
Get reference to corresponding task_prefix.
Definition: task.h:946
size_t m_pos
Insertion position in m_cur_segment.

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.