queuing_mutex.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_queuing_mutex_H
#define __TBB_queuing_mutex_H
#define __TBB_queuing_mutex_H_include_area
#include "internal/_warning_suppress_enable_notice.h"
#include <cstring>
#include "atomic.h"
#include "tbb_profiling.h"
namespace tbb {
class queuing_mutex : internal::mutex_copy_deprecated_and_disabled {
public:
queuing_mutex() {
q_tail = NULL;
#if TBB_USE_THREADING_TOOLS
internal_construct();
#endif
}
class scoped_lock: internal::no_copy {
void initialize() {
mutex = NULL;
going = 0;
#if TBB_USE_ASSERT
internal::poison_pointer(next);
#endif /* TBB_USE_ASSERT */
}
public:
scoped_lock() {initialize();}
scoped_lock( queuing_mutex& m ) {
initialize();
acquire(m);
}
~scoped_lock() {
if( mutex ) release();
}
void __TBB_EXPORTED_METHOD acquire( queuing_mutex& m );
bool __TBB_EXPORTED_METHOD try_acquire( queuing_mutex& m );
void __TBB_EXPORTED_METHOD release();
private:
queuing_mutex* mutex;
scoped_lock *next;
uintptr_t going;
};
void __TBB_EXPORTED_METHOD internal_construct();
// Mutex traits
static const bool is_rw_mutex = false;
static const bool is_recursive_mutex = false;
static const bool is_fair_mutex = true;
private:
atomic<scoped_lock*> q_tail;
};
__TBB_DEFINE_PROFILING_SET_NAME(queuing_mutex)
} // namespace tbb
#include "internal/_warning_suppress_disable_notice.h"
#undef __TBB_queuing_mutex_H_include_area
#endif /* __TBB_queuing_mutex_H */
atomic.h
_warning_suppress_disable_notice.h
_warning_suppress_enable_notice.h
tbb_profiling.h
__TBB_DEFINE_PROFILING_SET_NAME
#define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type)
Definition: tbb_profiling.h:115
__TBB_EXPORTED_METHOD
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:98
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::internal::poison_pointer
void poison_pointer(T *__TBB_atomic &)
Definition: tbb_stddef.h:305
tbb::queuing_mutex
Queuing mutex with local-only spinning.
Definition: queuing_mutex.h:31
tbb::queuing_mutex::q_tail
atomic< scoped_lock * > q_tail
The last competitor requesting the lock.
Definition: queuing_mutex.h:102
tbb::queuing_mutex::queuing_mutex
queuing_mutex()
Construct unacquired mutex.
Definition: queuing_mutex.h:34
tbb::queuing_mutex::is_recursive_mutex
static const bool is_recursive_mutex
Definition: queuing_mutex.h:97
tbb::queuing_mutex::is_rw_mutex
static const bool is_rw_mutex
Definition: queuing_mutex.h:96
tbb::queuing_mutex::is_fair_mutex
static const bool is_fair_mutex
Definition: queuing_mutex.h:98
tbb::queuing_mutex::internal_construct
void __TBB_EXPORTED_METHOD internal_construct()
Definition: queuing_mutex.cpp:100
tbb::queuing_mutex::scoped_lock
The scoped locking pattern.
Definition: queuing_mutex.h:44
tbb::queuing_mutex::scoped_lock::scoped_lock
scoped_lock()
Construct lock that has not acquired a mutex.
Definition: queuing_mutex.h:57
tbb::queuing_mutex::scoped_lock::~scoped_lock
~scoped_lock()
Release lock (if lock is held).
Definition: queuing_mutex.h:66
tbb::queuing_mutex::scoped_lock::going
uintptr_t going
The local spin-wait variable.
Definition: queuing_mutex.h:90
tbb::queuing_mutex::scoped_lock::initialize
void initialize()
Initialize fields to mean "no lock held".
Definition: queuing_mutex.h:46
tbb::queuing_mutex::scoped_lock::release
void __TBB_EXPORTED_METHOD release()
Release lock.
Definition: queuing_mutex.cpp:81
tbb::queuing_mutex::scoped_lock::mutex
queuing_mutex * mutex
The pointer to the mutex owned, or NULL if not holding a mutex.
Definition: queuing_mutex.h:81
tbb::queuing_mutex::scoped_lock::try_acquire
bool __TBB_EXPORTED_METHOD try_acquire(queuing_mutex &m)
Acquire lock on given mutex if free (i.e. non-blocking)
Definition: queuing_mutex.cpp:58
tbb::queuing_mutex::scoped_lock::scoped_lock
scoped_lock(queuing_mutex &m)
Acquire lock on given mutex.
Definition: queuing_mutex.h:60
tbb::queuing_mutex::scoped_lock::next
scoped_lock * next
The pointer to the next competitor for a mutex.
Definition: queuing_mutex.h:84
tbb::queuing_mutex::scoped_lock::acquire
void __TBB_EXPORTED_METHOD acquire(queuing_mutex &m)
Acquire lock on given mutex.
Definition: queuing_mutex.cpp:28
tbb::internal::no_copy
Base class for types that should not be copied or assigned.
Definition: tbb_stddef.h:330
tbb::internal::mutex_copy_deprecated_and_disabled
Definition: tbb_stddef.h:365

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.