Skip to content

Commit

Permalink
use tbb::speculative_spin_mutex for TSX impl
Browse files Browse the repository at this point in the history
  • Loading branch information
cmpxchg16 committed Apr 22, 2014
1 parent f2b831a commit 1a1a9d1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 126 deletions.
119 changes: 0 additions & 119 deletions HybridLock.h

This file was deleted.

4 changes: 3 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Benchmark multiple implementation of multi-producer multi-consumer queue:
4. Intel TSX (Transactional Synchronization Extensions)

Build:
$> g++ -Wall -std=c++11 -O3 -D DCACHE1_LINESIZE=`getconf LEVEL1_DCACHE_LINESIZE` main.cpp -pthread -Wl,--no-as-needed -mrtm
$> g++ -Wall -std=c++11 -O3 -D DCACHE1_LINESIZE=`getconf LEVEL1_DCACHE_LINESIZE` main.cpp -pthread -ltbb -Wl,--no-as-needed

Note: the tsx implementation based on the tbb::speculative_spin_mutex

Author: Uri Shamay ([email protected])
12 changes: 6 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* performance and verification tests.
*
* Build with (g++ version must be >= 4.5.0):
* $> g++ -Wall -std=c++11 -O3 -D DCACHE1_LINESIZE=`getconf LEVEL1_DCACHE_LINESIZE` main.cpp -pthread -Wl,--no-as-needed -mrtm
* $> g++ -Wall -std=c++11 -O3 -D DCACHE1_LINESIZE=`getconf LEVEL1_DCACHE_LINESIZE` main.cpp -pthread -ltbb -Wl,--no-as-needed
*
* I verified the program with g++ 4.5.3, 4.6.1, 4.6.3 and 4.8.1.
*
Expand Down Expand Up @@ -341,8 +341,7 @@ class LockFreeQueue {
T **ptr_array_;
};

#include "HybridLock.h"

#include <tbb/spin_mutex.h>
/*
* ----------------------------------------------------------------------------------------------------
* Intel TSX (Transactional Synchronization Extensions) fixed size multi-producer multi-consumer queue
Expand All @@ -358,7 +357,7 @@ class TSXQueue
{
while(1)
{
std::lock_guard<HybridLock> lock(lock_);
tbb::speculative_spin_mutex::scoped_lock guard(lock_);
if (counter_ >= Q_SIZE)
{
continue;
Expand All @@ -375,7 +374,7 @@ class TSXQueue
T* t = nullptr;
while(1)
{
std::lock_guard<HybridLock> lock(lock_);
tbb::speculative_spin_mutex::scoped_lock guard(lock_);
if (counter_ == 0)
{
continue;
Expand All @@ -388,7 +387,8 @@ class TSXQueue
}

private:
HybridLock lock_;

tbb::speculative_spin_mutex lock_;
unsigned long counter_;
T ____cacheline_aligned* array_[Q_SIZE] ____cacheline_aligned;
};
Expand Down

0 comments on commit 1a1a9d1

Please sign in to comment.