-
Notifications
You must be signed in to change notification settings - Fork 115
[oneTBB] Add adaptive mutexes #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ivankochin
merged 8 commits into
uxlfoundation:main
from
pavelkumbrasev:onetbb-add-adaptive-mutexes
Sep 9, 2021
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
53b8e33
Add adaptive mutexes
e8152ce
Apply suggestions from code review
f71caf2
Apply suggestions from code review
5c568ed
Apply suggestions from code review
bc3ca06
Update copyright version
ivankochin 04747f3
Update copyright
ivankochin df116de
Update copyright
ivankochin 26db3d4
Fix copyrights
ivankochin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
source/elements/oneTBB/source/mutual_exclusion/mutex_cls.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| .. SPDX-FileCopyrightText: 2020-2021 Intel Corporation | ||
| .. | ||
| .. SPDX-License-Identifier: CC-BY-4.0 | ||
|
|
||
| ===== | ||
| mutex | ||
| ===== | ||
| **[mutex.mutex]** | ||
|
|
||
| A ``mutex`` is a class that models :doc:`Mutex requirement <../named_requirements/mutexes/mutex>` | ||
| using an adaptive approach, it guarantees: that the thread that can't acquire the lock spins before blocking. | ||
pavelkumbrasev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| The ``mutex`` class satisfies all of the mutex requirements described in the [thread.mutex.requirements] section of the ISO C++ standard. | ||
| The ``mutex`` class is not fair or recursive. | ||
|
|
||
| .. code:: cpp | ||
|
|
||
| // Defined in header <oneapi/tbb/mutex.h> | ||
|
|
||
| namespace oneapi { | ||
| namespace tbb { | ||
| class mutex { | ||
| public: | ||
| mutex() noexcept; | ||
| ~mutex(); | ||
|
|
||
| mutex(const mutex&) = delete; | ||
| mutex& operator=(const mutex&) = delete; | ||
|
|
||
| class scoped_lock; | ||
|
|
||
| void lock(); | ||
| bool try_lock(); | ||
| void unlock(); | ||
|
|
||
| static constexpr bool is_rw_mutex = false; | ||
| static constexpr bool is_recursive_mutex = false; | ||
| static constexpr bool is_fair_mutex = false; | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| Member classes | ||
| -------------- | ||
|
|
||
| .. namespace:: oneapi::tbb::mutex | ||
|
|
||
| .. cpp:class:: scoped_lock | ||
|
|
||
| The corresponding ``scoped_lock`` class. See :doc:`Mutex requirement <../named_requirements/mutexes/mutex>`. | ||
|
|
||
| Member functions | ||
| ---------------- | ||
|
|
||
| .. cpp:function:: mutex() | ||
|
|
||
| Constructs a ``mutex`` with the unlocked state. | ||
|
|
||
| -------------------------------------------------- | ||
|
|
||
| .. cpp:function:: ~mutex() | ||
|
|
||
| Destroys an unlocked ``mutex``. | ||
|
|
||
| -------------------------------------------------- | ||
|
|
||
| .. cpp:function:: void lock() | ||
|
|
||
| Acquires a lock. It uses adaptive logic for waiting, thus it is blocked after a certain time of busy waiting. | ||
pavelkumbrasev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| -------------------------------------------------- | ||
|
|
||
| .. cpp:function:: bool try_lock() | ||
|
|
||
| Tries to acquire a lock (non-blocking). Returns **true** if succeeded; **false** otherwise. | ||
|
|
||
| -------------------------------------------------- | ||
|
|
||
| .. cpp:function:: void unlock() | ||
|
|
||
| Releases the lock held by a current thread. | ||
104 changes: 104 additions & 0 deletions
104
source/elements/oneTBB/source/mutual_exclusion/rw_mutex_cls.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| .. SPDX-FileCopyrightText: 2020-2021 Intel Corporation | ||
ivankochin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .. | ||
| .. SPDX-License-Identifier: CC-BY-4.0 | ||
|
|
||
| ============= | ||
| rw_mutex | ||
| ============= | ||
| **[mutex.rw_mutex]** | ||
|
|
||
| A ``rw_mutex`` is a class that models :doc:`ReaderWriterMutex requirement <../named_requirements/mutexes/rw_mutex>` | ||
| using an adaptive approach, it guarantees: that the thread that can't acquire the lock spins before blocking. | ||
pavelkumbrasev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| The ``rw_mutex`` class satisfies all of the shared mutex requirements described in the [thread.sharedmutex.requirements] section of the ISO C++ standard. | ||
| The ``rw_mutex`` class is an unfair reader-writer lock with a writer preference. | ||
|
|
||
| .. code:: cpp | ||
|
|
||
| // Defined in header <oneapi/tbb/rw_mutex.h> | ||
|
|
||
| namespace oneapi { | ||
| namespace tbb { | ||
| class rw_mutex { | ||
| public: | ||
| rw_mutex() noexcept; | ||
| ~rw_mutex(); | ||
|
|
||
| rw_mutex(const rw_mutex&) = delete; | ||
| rw_mutex& operator=(const rw_mutex&) = delete; | ||
|
|
||
| class scoped_lock; | ||
|
|
||
| // exclusive ownership | ||
| void lock(); | ||
| bool try_lock(); | ||
| void unlock(); | ||
|
|
||
| // shared ownership | ||
| void lock_shared(); | ||
| bool try_lock_shared(); | ||
| void unlock_shared(); | ||
|
|
||
| static constexpr bool is_rw_mutex = true; | ||
| static constexpr bool is_recursive_mutex = false; | ||
| static constexpr bool is_fair_mutex = false; | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| Member classes | ||
| -------------- | ||
|
|
||
| .. namespace:: oneapi::tbb::rw_mutex | ||
|
|
||
| .. cpp:class:: scoped_lock | ||
|
|
||
| The corresponding scoped-lock class. See :doc:`ReaderWriterMutex requirement <../named_requirements/mutexes/rw_mutex>`. | ||
|
|
||
| Member functions | ||
| ---------------- | ||
|
|
||
| .. cpp:function:: rw_mutex() | ||
|
|
||
| Constructs an unlocked ``rw_mutex``. | ||
|
|
||
| -------------------------------------------------- | ||
|
|
||
| .. cpp:function:: ~rw_mutex() | ||
|
|
||
| Destroys an unlocked ``rw_mutex``. | ||
|
|
||
| -------------------------------------------------- | ||
|
|
||
| .. cpp:function:: void lock() | ||
|
|
||
| Acquires a lock. It uses an adaptive logic for waiting, thus it is blocked after a certain time of busy waiting. | ||
|
|
||
| -------------------------------------------------- | ||
|
|
||
| .. cpp:function:: bool try_lock() | ||
|
|
||
| Tries to acquire a lock (non-blocking) on write. Returns **true** if succeeded; **false** otherwise. | ||
|
|
||
| -------------------------------------------------- | ||
|
|
||
| .. cpp:function:: void unlock() | ||
|
|
||
| Releases the write lock held by the current thread. | ||
|
|
||
| -------------------------------------------------- | ||
|
|
||
| .. cpp:function:: void lock_shared() | ||
|
|
||
| Acquires a lock on read. It uses an adaptive logic for waiting, thus it is blocked after a certain time of busy waiting. | ||
|
|
||
| -------------------------------------------------- | ||
|
|
||
| .. cpp:function:: bool try_lock_shared() | ||
|
|
||
| Tries to acquire the lock (non-blocking) on read. Returns **true** if succeeded; **false** otherwise. | ||
|
|
||
| -------------------------------------------------- | ||
|
|
||
| .. cpp:function:: void unlock_shared() | ||
|
|
||
| Releases the read lock held by the current thread. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.