Skip to content

Commit

Permalink
fix a data race in debug build (#456)
Browse files Browse the repository at this point in the history
fix a data race in debug build

This particular one flooded TSAN report.
  • Loading branch information
kevgs authored and Sergey Vojtovich committed Oct 6, 2017
1 parent a4948da commit e59d080
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions storage/innobase/include/sync0policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class MutexDebug {
{
m_mutex = mutex;

m_thread_id = os_thread_get_curr_id();
my_atomic_storelint(&m_thread_id, os_thread_get_curr_id());

m_filename = filename;

Expand All @@ -89,7 +89,7 @@ class MutexDebug {
{
m_mutex = NULL;

m_thread_id = os_thread_id_t(ULINT_UNDEFINED);
my_atomic_storelint(&m_thread_id, ULINT_UNDEFINED);

m_filename = NULL;

Expand Down Expand Up @@ -138,7 +138,7 @@ class MutexDebug {
unsigned m_line;

/** Thread ID of the thread that own(ed) the mutex */
os_thread_id_t m_thread_id;
ulint m_thread_id;
};

/** Constructor. */
Expand All @@ -157,7 +157,7 @@ class MutexDebug {
/** Mutex is being destroyed. */
void destroy() UNIV_NOTHROW
{
ut_ad(m_context.m_thread_id == os_thread_id_t(ULINT_UNDEFINED));
ut_ad((ulint)my_atomic_loadlint(&m_context.m_thread_id) == ULINT_UNDEFINED);

m_magic_n = 0;

Expand Down Expand Up @@ -199,7 +199,7 @@ class MutexDebug {
bool is_owned() const UNIV_NOTHROW
{
return(os_thread_eq(
m_context.m_thread_id,
my_atomic_loadlint(&m_context.m_thread_id),
os_thread_get_curr_id()));
}

Expand All @@ -221,7 +221,7 @@ class MutexDebug {
os_thread_id_t get_thread_id() const
UNIV_NOTHROW
{
return(m_context.m_thread_id);
return(my_atomic_loadlint(&m_context.m_thread_id));
}

/** Magic number to check for memory corruption. */
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/sync0policy.ic
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void MutexDebug<Mutex>::locked(
UNIV_NOTHROW
{
ut_ad(!is_owned());
ut_ad(m_context.m_thread_id == os_thread_id_t(ULINT_UNDEFINED));
ut_ad(m_context.m_thread_id == ULINT_UNDEFINED);

m_context.locked(mutex, name, line);

Expand Down
2 changes: 2 additions & 0 deletions storage/innobase/include/sync0types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1163,10 +1163,12 @@ enum rw_lock_flag_t {
#ifdef _WIN64
#define my_atomic_addlint(A,B) my_atomic_add64((int64*) (A), (B))
#define my_atomic_loadlint(A) my_atomic_load64((int64*) (A))
#define my_atomic_storelint(A,B) my_atomic_store64((int64*) (A), (B))
#define my_atomic_caslint(A,B,C) my_atomic_cas64((int64*) (A), (int64*) (B), (C))
#else
#define my_atomic_addlint my_atomic_addlong
#define my_atomic_loadlint my_atomic_loadlong
#define my_atomic_storelint my_atomic_storelong
#define my_atomic_caslint my_atomic_caslong
#endif

Expand Down

0 comments on commit e59d080

Please sign in to comment.