Skip to content

Commit 34cd4f7

Browse files
committed
Bug#28510691 TSAN: DATA RACE IN SAFE_MUTEX IMPLEMENTATION
Fix data races in safe_mutex_assert_owner() and safe_mutex_assert_not_owner() by locking safe_mutex_t::global mutex before inspecting safe_mutex_t contents. No consequences for release builds as SAFE_MUTEX is only used for debug builds. Change-Id: I98745a4301ce724e3f51ba9343e66b7e72165fab
1 parent fbeece3 commit 34cd4f7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

include/thr_mutex.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef THR_MUTEX_INCLUDED
22
#define THR_MUTEX_INCLUDED
33

4-
/* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License, version 2.0,
@@ -145,14 +145,18 @@ int safe_mutex_lock(safe_mutex_t *mp, bool try_lock, const char *file,
145145
int safe_mutex_unlock(safe_mutex_t *mp, const char *file, uint line);
146146
int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint line);
147147

148-
static inline void safe_mutex_assert_owner(const safe_mutex_t *mp) {
148+
static inline void safe_mutex_assert_owner(safe_mutex_t *mp) {
149149
DBUG_ASSERT(mp != NULL);
150+
native_mutex_lock(&mp->global);
150151
DBUG_ASSERT(mp->count > 0 && my_thread_equal(my_thread_self(), mp->thread));
152+
native_mutex_unlock(&mp->global);
151153
}
152154

153-
static inline void safe_mutex_assert_not_owner(const safe_mutex_t *mp) {
155+
static inline void safe_mutex_assert_not_owner(safe_mutex_t *mp) {
154156
DBUG_ASSERT(mp != NULL);
157+
native_mutex_lock(&mp->global);
155158
DBUG_ASSERT(!mp->count || !my_thread_equal(my_thread_self(), mp->thread));
159+
native_mutex_unlock(&mp->global);
156160
}
157161
#endif /* SAFE_MUTEX */
158162

0 commit comments

Comments
 (0)