scheduler_utility.h
Go to the documentation of this file.
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _TBB_scheduler_utility_H
#define _TBB_scheduler_utility_H
#include "scheduler.h"
namespace tbb {
namespace internal {
//------------------------------------------------------------------------
// auto_empty_task
//------------------------------------------------------------------------
class auto_empty_task {
task* my_task;
generic_scheduler* my_scheduler;
public:
auto_empty_task ( __TBB_CONTEXT_ARG(generic_scheduler *s, task_group_context* context) )
: my_task( new(&s->allocate_task(sizeof(empty_task), __TBB_CONTEXT_ARG(NULL, context))) empty_task )
, my_scheduler(s)
{}
// empty_task has trivial destructor, so there's no need to call it.
~auto_empty_task () { my_scheduler->free_task<small_local_task>(*my_task); }
operator task& () { return *my_task; }
task* operator & () { return my_task; }
task_prefix& prefix () { return my_task->prefix(); }
}; // class auto_empty_task
//------------------------------------------------------------------------
// fast_reverse_vector
//------------------------------------------------------------------------
template<typename T, size_t max_segments = 16>
class fast_reverse_vector
{
public:
fast_reverse_vector ( T* initial_segment, size_t segment_size )
: m_cur_segment(initial_segment)
, m_cur_segment_size(segment_size)
, m_pos(segment_size)
, m_num_segments(0)
, m_size(0)
{
__TBB_ASSERT ( initial_segment && segment_size, "Nonempty initial segment must be supplied");
}
~fast_reverse_vector ()
{
for ( size_t i = 1; i < m_num_segments; ++i )
NFS_Free( m_segments[i] );
}
size_t size () const { return m_size + m_cur_segment_size - m_pos; }
void push_back ( const T& val )
{
if ( !m_pos ) {
if ( !m_num_segments ) m_segments[m_num_segments++] = m_cur_segment;
m_size += m_cur_segment_size;
m_cur_segment_size *= 2;
m_pos = m_cur_segment_size;
m_segments[m_num_segments++] = m_cur_segment = (T*)NFS_Allocate( m_cur_segment_size, sizeof(T), NULL );
__TBB_ASSERT ( m_num_segments < max_segments, "Maximal capacity exceeded" );
}
m_cur_segment[--m_pos] = val;
}
void copy_memory ( T* dst ) const
{
size_t sz = m_cur_segment_size - m_pos;
memcpy( dst, m_cur_segment + m_pos, sz * sizeof(T) );
dst += sz;
sz = m_cur_segment_size / 2;
for ( long i = (long)m_num_segments - 2; i >= 0; --i ) {
memcpy( dst, m_segments[i], sz * sizeof(T) );
dst += sz;
sz /= 2;
}
}
protected:
T *m_cur_segment;
size_t m_cur_segment_size;
size_t m_pos;
T *m_segments[max_segments];
size_t m_num_segments;
size_t m_size;
}; // class fast_reverse_vector
} // namespace internal
} // namespace tbb
#endif /* _TBB_scheduler_utility_H */
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
scheduler.h
__TBB_CONTEXT_ARG
#define __TBB_CONTEXT_ARG(arg1, context)
Definition: scheduler_common.h:60
s
void const char const char int ITT_FORMAT __itt_group_sync s
Definition: ittnotify_static.h:91
tbb::internal::NFS_Allocate
void *__TBB_EXPORTED_FUNC NFS_Allocate(size_t n_element, size_t element_size, void *hint)
Allocate memory on cache/sector line boundary.
Definition: cache_aligned_allocator.cpp:176
tbb::internal::NFS_Free
void __TBB_EXPORTED_FUNC NFS_Free(void *)
Free memory allocated by NFS_Allocate.
Definition: cache_aligned_allocator.cpp:198
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::internal::small_local_task
@ small_local_task
Bitwise-OR of local_task and small_task.
Definition: scheduler_common.h:196
internal
Definition: _flow_graph_async_msg_impl.h:24
tbb::internal::task_prefix
Memory prefix to a task object.
Definition: task.h:203
tbb::task_group_context
Used to form groups of tasks.
Definition: task.h:358
tbb::task
Base class for user-defined tasks.
Definition: task.h:615
tbb::task::prefix
internal::task_prefix & prefix(internal::version_tag *=NULL) const
Get reference to corresponding task_prefix.
Definition: task.h:1002
tbb::empty_task
task that does nothing. Useful for synchronization.
Definition: task.h:1042
tbb::internal::generic_scheduler
Work stealing task scheduler.
Definition: scheduler.h:140
tbb::internal::generic_scheduler::free_task
void free_task(task &t)
Put task on free list.
Definition: scheduler.h:730
tbb::internal::auto_empty_task
Smart holder for the empty task class with automatic destruction.
Definition: scheduler_utility.h:30
tbb::internal::auto_empty_task::my_scheduler
generic_scheduler * my_scheduler
Definition: scheduler_utility.h:32
tbb::internal::auto_empty_task::my_task
task * my_task
Definition: scheduler_utility.h:31
tbb::internal::auto_empty_task::~auto_empty_task
~auto_empty_task()
Definition: scheduler_utility.h:39
tbb::internal::auto_empty_task::operator&
task * operator&()
Definition: scheduler_utility.h:42
tbb::internal::auto_empty_task::prefix
task_prefix & prefix()
Definition: scheduler_utility.h:43
tbb::internal::auto_empty_task::auto_empty_task
auto_empty_task(__TBB_CONTEXT_ARG(generic_scheduler *s, task_group_context *context))
Definition: scheduler_utility.h:34
tbb::internal::fast_reverse_vector
Vector that grows without reallocations, and stores items in the reverse order.
Definition: scheduler_utility.h:57
tbb::internal::fast_reverse_vector::m_pos
size_t m_pos
Insertion position in m_cur_segment.
Definition: scheduler_utility.h:113
tbb::internal::fast_reverse_vector::fast_reverse_vector
fast_reverse_vector(T *initial_segment, size_t segment_size)
Definition: scheduler_utility.h:59
tbb::internal::fast_reverse_vector::~fast_reverse_vector
~fast_reverse_vector()
Definition: scheduler_utility.h:69
tbb::internal::fast_reverse_vector::m_segments
T * m_segments[max_segments]
Array of segments (has fixed size specified by the second template parameter)
Definition: scheduler_utility.h:116
tbb::internal::fast_reverse_vector::m_cur_segment_size
size_t m_cur_segment_size
Capacity of m_cur_segment.
Definition: scheduler_utility.h:110
tbb::internal::fast_reverse_vector::m_cur_segment
T * m_cur_segment
The current (not completely filled) segment.
Definition: scheduler_utility.h:107
tbb::internal::fast_reverse_vector::copy_memory
void copy_memory(T *dst) const
Copies the contents of the vector into the dst array.
Definition: scheduler_utility.h:92
tbb::internal::fast_reverse_vector::m_size
size_t m_size
Number of items in the segments in m_segments.
Definition: scheduler_utility.h:122
tbb::internal::fast_reverse_vector::push_back
void push_back(const T &val)
Definition: scheduler_utility.h:77
tbb::internal::fast_reverse_vector::size
size_t size() const
Definition: scheduler_utility.h:75
tbb::internal::fast_reverse_vector::m_num_segments
size_t m_num_segments
Number of segments (the size of m_segments)
Definition: scheduler_utility.h:119

Copyright © 2005-2020 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.