Skip to content

Commit d3778e3

Browse files
authored
Merge pull request mariadb-corporation#2827 from mariadb-corporation/rwlockmonitor_datarace
Atomic bools for RWLockMonitor
2 parents fed115c + 4a8e53f commit d3778e3

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

versioning/BRM/extentmap.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* $Id: extentmap.cpp 1936 2013-07-09 22:10:29Z dhall $
2121
*
2222
****************************************************************************/
23-
23+
#include <atomic>
2424
#include <iostream>
2525
#include <sys/types.h>
2626
#include <sys/time.h>
@@ -6036,17 +6036,17 @@ void ExtentMap::confirmChangesRBTree()
60366036
undoRecordsRBTree.clear();
60376037
}
60386038

6039-
const bool* ExtentMap::getEMFLLockStatus()
6039+
const std::atomic<bool>* ExtentMap::getEMFLLockStatus()
60406040
{
60416041
return &flLocked;
60426042
}
60436043

6044-
const bool* ExtentMap::getEMLockStatus()
6044+
const std::atomic<bool>* ExtentMap::getEMLockStatus()
60456045
{
60466046
return &emLocked;
60476047
}
60486048

6049-
const bool* ExtentMap::getEMIndexLockStatus()
6049+
const std::atomic<bool>* ExtentMap::getEMIndexLockStatus()
60506050
{
60516051
return &emIndexLocked;
60526052
}

versioning/BRM/extentmap.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,9 +1035,9 @@ class ExtentMap : public Undoable
10351035
EXPORT std::vector<InlineLBIDRange> getFreeListEntries();
10361036

10371037
EXPORT void dumpTo(std::ostream& os);
1038-
EXPORT const bool* getEMLockStatus();
1039-
EXPORT const bool* getEMFLLockStatus();
1040-
EXPORT const bool* getEMIndexLockStatus();
1038+
EXPORT const std::atomic<bool>* getEMLockStatus();
1039+
EXPORT const std::atomic<bool>* getEMFLLockStatus();
1040+
EXPORT const std::atomic<bool>* getEMIndexLockStatus();
10411041
size_t EMIndexShmemSize();
10421042
size_t EMIndexShmemFree();
10431043

@@ -1087,7 +1087,9 @@ class ExtentMap : public Undoable
10871087
time_t fCacheTime; // timestamp associated with config cache
10881088

10891089
int numUndoRecords;
1090-
bool flLocked, emLocked, emIndexLocked;
1090+
std::atomic<bool> flLocked{false};
1091+
std::atomic<bool> emLocked{false};
1092+
std::atomic<bool> emIndexLocked{false};
10911093

10921094
static boost::mutex mutex; // @bug5355 - made mutex static
10931095
static boost::mutex emIndexMutex;

versioning/BRM/rwlockmonitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ using namespace logging;
3535

3636
namespace BRM
3737
{
38-
RWLockMonitor::RWLockMonitor(const bool* d, const bool* ls, const uint32_t k) : die(d), lockStatus(ls), key(k)
38+
RWLockMonitor::RWLockMonitor(const std::atomic<bool>* d, const std::atomic<bool>* ls, const uint32_t k) : die(d), lockStatus(ls), key(k)
3939
{
4040
ts.tv_sec = 210; // 3:30 timer
4141
ts.tv_nsec = 0;

versioning/BRM/rwlockmonitor.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <boost/scoped_ptr.hpp>
2929

3030
#include "rwlock.h"
31+
#include <atomic>
3132

3233
#define EXPORT
3334

@@ -37,7 +38,7 @@ class RWLockMonitor
3738
{
3839
public:
3940
// d = die, ls = lock status, k = key
40-
EXPORT RWLockMonitor(const bool* d, const bool* ls, const uint32_t k);
41+
EXPORT RWLockMonitor(const std::atomic<bool>* d, const std::atomic<bool>* ls, const uint32_t k);
4142

4243
EXPORT virtual ~RWLockMonitor();
4344

@@ -49,8 +50,8 @@ class RWLockMonitor
4950
// RWLockMonitor& operator=(const RWLockMonitor&rhs);
5051

5152
/* Some of these vars are only useful once we implement write_lock checking. */
52-
const bool* die;
53-
const bool* lockStatus;
53+
const std::atomic<bool>* die;
54+
const std::atomic<bool>* lockStatus;
5455
uint32_t key;
5556
boost::shared_ptr<rwlock::RWLock> lock;
5657

versioning/BRM/slavedbrmnode.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,27 +1482,27 @@ int SlaveDBRMNode::dmlReleaseLBIDRanges(const vector<LBIDRange>& ranges)
14821482
}
14831483
}
14841484

1485-
const bool* SlaveDBRMNode::getEMFLLockStatus()
1485+
const std::atomic<bool>* SlaveDBRMNode::getEMFLLockStatus()
14861486
{
14871487
return em.getEMFLLockStatus();
14881488
}
14891489

1490-
const bool* SlaveDBRMNode::getEMLockStatus()
1490+
const std::atomic<bool>* SlaveDBRMNode::getEMLockStatus()
14911491
{
14921492
return em.getEMLockStatus();
14931493
}
14941494

1495-
const bool* SlaveDBRMNode::getEMIndexLockStatus()
1495+
const std::atomic<bool> *SlaveDBRMNode::getEMIndexLockStatus()
14961496
{
14971497
return em.getEMIndexLockStatus();
14981498
}
14991499

1500-
const bool* SlaveDBRMNode::getVBBMLockStatus()
1500+
const std::atomic<bool>* SlaveDBRMNode::getVBBMLockStatus()
15011501
{
15021502
return &locked[0];
15031503
}
15041504

1505-
const bool* SlaveDBRMNode::getVSSLockStatus()
1505+
const std::atomic<bool>* SlaveDBRMNode::getVSSLockStatus()
15061506
{
15071507
return &locked[1];
15081508
}

versioning/BRM/slavedbrmnode.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,11 @@ class SlaveDBRMNode
455455
EXPORT int loadState(std::string filename) throw();
456456
EXPORT int saveState(std::string filename) throw();
457457

458-
EXPORT const bool* getEMFLLockStatus();
459-
EXPORT const bool* getEMLockStatus();
460-
EXPORT const bool* getEMIndexLockStatus();
461-
EXPORT const bool* getVBBMLockStatus();
462-
EXPORT const bool* getVSSLockStatus();
458+
EXPORT const std::atomic<bool>* getEMFLLockStatus();
459+
EXPORT const std::atomic<bool>* getEMLockStatus();
460+
EXPORT const std::atomic<bool>* getEMIndexLockStatus();
461+
EXPORT const std::atomic<bool>* getVBBMLockStatus();
462+
EXPORT const std::atomic<bool>* getVSSLockStatus();
463463

464464
private:
465465
explicit SlaveDBRMNode(const SlaveDBRMNode& brm);
@@ -471,7 +471,7 @@ class SlaveDBRMNode
471471
VBBM vbbm;
472472
VSS vss;
473473
CopyLocks copylocks;
474-
bool locked[3]; // 0 = VBBM, 1 = VSS, 2 = CopyLocks
474+
std::atomic<bool> locked[3] {false, false, false}; // 0 = VBBM, 1 = VSS, 2 = CopyLocks
475475
};
476476

477477
} // namespace BRM

versioning/BRM/slavenode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@
3636
#include "crashtrace.h"
3737
#include "service.h"
3838
#include "jobstep.h"
39+
#include <atomic>
3940

4041
using namespace BRM;
4142
using namespace std;
4243

4344
std::unique_ptr<SlaveComm> comm;
44-
bool die = false;
45+
std::atomic<bool> die{false};
4546
boost::thread_group monitorThreads;
4647

4748
class Opt

0 commit comments

Comments
 (0)