-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,51 @@ | ||
#ifdef WITH_WSREP | ||
#include "sql/wsrep_async_monitor.h" | ||
#include <algorithm> | ||
#include <cassert> | ||
|
||
void Wsrep_async_monitor::enter(seqno_t seqno) { | ||
std::unique_lock<std::mutex> lock(m_mutex); | ||
|
||
// Wait for its turn | ||
m_cond.wait(lock, [this, seqno]() { return seqno == m_last_left + 1; }); | ||
m_last_entered = (seqno > m_last_entered) ? seqno : m_last_entered; | ||
fprintf(stderr, "Entered the monitor with seqno: %llu\n", seqno); | ||
} | ||
|
||
void Wsrep_async_monitor::leave(seqno_t seqno) { | ||
// Wait for its turn before leaving | ||
std::unique_lock<std::mutex> lock(m_mutex); | ||
m_cond.wait(lock, [this, seqno]() { return seqno == m_last_left + 1; }); | ||
m_last_left = seqno; | ||
|
||
fprintf(stderr, "Left the monitor seqno: %llu\n", seqno); | ||
// Notify all waiting threads | ||
m_cond.notify_all(); | ||
} | ||
|
||
void Wsrep_async_monitor::drain(seqno_t seqno) { | ||
// Wait for its turn before resetting it | ||
std::unique_lock<std::mutex> lock(m_mutex); | ||
|
||
// No need to wait if the seqno has already left | ||
if (seqno !=0 && seqno < m_last_left) { | ||
return; | ||
} | ||
|
||
m_cond.wait(lock, [this, seqno]() { return seqno == m_last_left + 1; }); | ||
|
||
} | ||
|
||
void Wsrep_async_monitor::reset(seqno_t seqno) { | ||
std::unique_lock<std::mutex> lock(m_mutex); | ||
|
||
// We can reset only if the last entered and last left | ||
// are same, meaning that there is no one who is inside | ||
// the monitor | ||
assert(m_last_entered == m_last_left); | ||
m_last_entered = seqno; | ||
m_last_left = seqno; | ||
m_cond.notify_all(); | ||
} | ||
|
||
#endif /* WITH_WSREP */ |
This file contains 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,42 @@ | ||
#ifndef WSREP_ASYNC_MONITOR_H | ||
#define WSREP_ASYNC_MONITOR_H | ||
|
||
#ifdef WITH_WSREP | ||
#include <condition_variable> | ||
#include <mutex> | ||
|
||
class Wsrep_async_monitor { | ||
public: | ||
using seqno_t = unsigned long long; | ||
|
||
Wsrep_async_monitor() : m_last_entered(0), m_last_left(0) {} | ||
|
||
~Wsrep_async_monitor() { | ||
std::unique_lock<std::mutex> lock(m_mutex); | ||
m_last_entered = 0; | ||
m_last_left = 0; | ||
m_cond.notify_all(); | ||
} | ||
|
||
void enter(seqno_t seqno); | ||
void leave(seqno_t seqno); | ||
void drain(seqno_t seqno); | ||
void reset(seqno_t seqno); | ||
|
||
seqno_t last_entered() const { return m_last_entered; } | ||
seqno_t last_left() const { return m_last_left; } | ||
|
||
//std::mutex &mutex() { return m_mutex; } | ||
//std::condition_variable &cond() { return m_cond; } | ||
|
||
private: | ||
std::mutex m_mutex; | ||
std::condition_variable m_cond; | ||
|
||
// TODO: Evaluate if we really need m_last_entered | ||
seqno_t m_last_entered; | ||
seqno_t m_last_left; | ||
}; | ||
|
||
#endif /* WITH_WSREP */ | ||
#endif /* WSREP_ASYNC_MONITOR_H */ |
This file contains 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 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 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