Skip to content

Commit

Permalink
Minor rework of SpinLock class for making it more efficient on Unlock…
Browse files Browse the repository at this point in the history
…() (#33)

* Minor rework of SpinLock class for making it more efficient on Unlock()

* remove tabs in Concurrent.h class
  • Loading branch information
noSTALKER authored and MaggieQi committed May 23, 2019
1 parent 60f89d1 commit 4d15203
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ dkms.conf
/Wrappers/inc/AnnIndex.java
/Wrappers/inc/AnnClient.java
/AnnService.users - Copy.props
/.vs
23 changes: 15 additions & 8 deletions AnnService/inc/Helper/Concurrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
#ifndef _SPTAG_HELPER_CONCURRENT_H_
#define _SPTAG_HELPER_CONCURRENT_H_

#include <cstdint>
#include <cstddef>

#include <atomic>
#include <condition_variable>
#include <mutex>
#include <memory>


namespace SPTAG
{
Expand All @@ -21,17 +20,25 @@ namespace Concurrent
class SpinLock
{
public:
SpinLock();
~SpinLock();
SpinLock() = default;

void Lock() noexcept
{
while (m_lock.test_and_set(std::memory_order_acquire))
{
}
}

void Lock();
void Unlock();
void Unlock() noexcept
{
m_lock.clear(std::memory_order_release);
}

SpinLock(const SpinLock&) = delete;
SpinLock& operator = (const SpinLock&) = delete;

private:
std::atomic_flag m_lock;
std::atomic_flag m_lock = ATOMIC_FLAG_INIT;
};


Expand Down
29 changes: 0 additions & 29 deletions AnnService/src/Helper/Concurrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,6 @@
using namespace SPTAG;
using namespace SPTAG::Helper::Concurrent;


SpinLock::SpinLock()
: m_lock()
{
m_lock.clear();
}


SpinLock::~SpinLock()
{
}


void
SpinLock::Lock()
{
while (m_lock.test_and_set(std::memory_order_acquire))
{
}
}


void
SpinLock::Unlock()
{
m_lock.clear();
}


WaitSignal::WaitSignal()
: m_isWaiting(false),
m_unfinished(0)
Expand Down

0 comments on commit 4d15203

Please sign in to comment.