Skip to content
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

Spinlock improvements and TaskId #127

Merged
merged 1 commit into from
May 20, 2020
Merged

Conversation

accelerated
Copy link
Contributor

@accelerated accelerated commented May 18, 2020

Describe your changes

  • Added TaskId to coroutines and IO tasks. This can be obtained at runtime via local::context::taskId() which is similar in nature to std::this_thread::get_id().
  • Prevent decrementing ReadWriteSpinlock if not unlocked.
  • Make Mutex class owner-aware. Only owning thread or coroutine can unlock.
  • Added test-test-and-set logic to SpinLock and ReadWriteSpinLock and added CPU pause instructions between spins. Support backoff after a certain number of spins with yield and sleep to release CPU. This makes the spinlock classes a lot more efficient. Fixes Inefficient SpinLock implementation #123.
  • Spinlock behavior can be configured via SpinLockTraits class.
  • Refactored logic in APIs not taking ISyncPtr to reduce code duplication. These APIs now call the ISyncPtr overload with nullptr as argument.
  • Added ReadWriteMutex class.
  • Changed Mutex::Guard to use TryToLock tag instead of a boolean. Also added AdoptLock tag overload.
  • Both Mutex and ReadWriteMutex are protected against locking inside a coroutine w/o a synchronization context.

@accelerated accelerated changed the title Rwlock Spinlock perf improvements May 18, 2020
@accelerated accelerated force-pushed the rwlock branch 2 times, most recently from 2014239 to f2e1f4d Compare May 19, 2020 23:07
@accelerated accelerated changed the title Spinlock perf improvements Spinlock improvements and TaskId May 19, 2020
@accelerated accelerated force-pushed the rwlock branch 7 times, most recently from 39f7744 to 64f617c Compare May 20, 2020 16:51
* Fixed inefficient Spinlock implementation
* Added TaskId and local::taskId()
* Updated Mutex class to be owner aware
* Refactored internal 'ISyncPtr' API calls to reduce code duplication
* Fixed accidental unlocking of the ReadWriteSpinlock
* Added spinlock traits and utils
* Added ReadWriteLock and tests for TaskId.

Signed-off-by: Alexander Damian <[email protected]>
Copy link
Contributor

@arosenzweig3 arosenzweig3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@accelerated accelerated reopened this May 20, 2020
@accelerated accelerated merged commit 0a1b20e into bloomberg:master May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inefficient SpinLock implementation
2 participants