Skip to content

Commit 8a987b4

Browse files
committed
Bug#16736461: ATOMIC OPERATIONS USING LOCKS ARE BROKEN, WON'T COMPILE
Post-push fix: Change my_atomic_rwlock_t back to contain pthread_mutex_t and not mysql_mutex_t to avoid risk of recursion. Instead change SAFE_MUTEX versions of my_atomic_rwlock_* macros to accept pthread_mutex_t parameter. Issue noticed by Marc Alff.
1 parent 4b79bdb commit 8a987b4

2 files changed

Lines changed: 8 additions & 71 deletions

File tree

include/atomic/rwlock.h

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,52 +38,19 @@ typedef char my_atomic_rwlock_t;
3838
#define MY_ATOMIC_MODE "dummy (non-atomic)"
3939
#else /* not MY_ATOMIC_MODE_DUMMY */
4040

41-
typedef struct {mysql_mutex_t rw;} my_atomic_rwlock_t;
42-
43-
#ifndef SAFE_MUTEX
41+
typedef struct {pthread_mutex_t rw;} my_atomic_rwlock_t;
4442

4543
/*
4644
we're using read-write lock macros but map them to mutex locks, and they're
4745
faster. Still, having semantically rich API we can change the
4846
underlying implementation, if necessary.
4947
*/
50-
#define my_atomic_rwlock_destroy(name) pthread_mutex_destroy(& (name)->rw.m_mutex)
51-
#define my_atomic_rwlock_init(name) pthread_mutex_init(& (name)->rw.m_mutex, 0)
52-
#define my_atomic_rwlock_rdlock(name) pthread_mutex_lock(& (name)->rw.m_mutex)
53-
#define my_atomic_rwlock_wrlock(name) pthread_mutex_lock(& (name)->rw.m_mutex)
54-
#define my_atomic_rwlock_rdunlock(name) pthread_mutex_unlock(& (name)->rw.m_mutex)
55-
#define my_atomic_rwlock_wrunlock(name) pthread_mutex_unlock(& (name)->rw.m_mutex)
56-
57-
#else /* SAFE_MUTEX */
58-
59-
/*
60-
SAFE_MUTEX pollutes the compiling name space with macros
61-
that alter pthread_mutex_t, pthread_mutex_init, etc.
62-
Atomic operations should never use the safe mutex wrappers.
63-
Unfortunately, there is no way to have both:
64-
- safe mutex macros expanding pthread_mutex_lock to safe_mutex_lock
65-
- my_atomic macros expanding to unmodified pthread_mutex_lock
66-
inlined in the same compilation unit.
67-
So, in case of SAFE_MUTEX, a function call is required.
68-
Given that SAFE_MUTEX is a debugging facility,
69-
this extra function call is not a performance concern for
70-
production builds.
71-
*/
72-
C_MODE_START
73-
extern void plain_pthread_mutex_init(safe_mutex_t *);
74-
extern void plain_pthread_mutex_destroy(safe_mutex_t *);
75-
extern void plain_pthread_mutex_lock(safe_mutex_t *);
76-
extern void plain_pthread_mutex_unlock(safe_mutex_t *);
77-
C_MODE_END
78-
79-
#define my_atomic_rwlock_destroy(name) plain_pthread_mutex_destroy(&(name)->rw.m_mutex)
80-
#define my_atomic_rwlock_init(name) plain_pthread_mutex_init(&(name)->rw.m_mutex)
81-
#define my_atomic_rwlock_rdlock(name) plain_pthread_mutex_lock(&(name)->rw.m_mutex)
82-
#define my_atomic_rwlock_wrlock(name) plain_pthread_mutex_lock(&(name)->rw.m_mutex)
83-
#define my_atomic_rwlock_rdunlock(name) plain_pthread_mutex_unlock(&(name)->rw.m_mutex)
84-
#define my_atomic_rwlock_wrunlock(name) plain_pthread_mutex_unlock(&(name)->rw.m_mutex)
85-
86-
#endif /* SAFE_MUTEX */
48+
#define my_atomic_rwlock_destroy(name) pthread_mutex_destroy(& (name)->rw)
49+
#define my_atomic_rwlock_init(name) pthread_mutex_init(& (name)->rw, 0)
50+
#define my_atomic_rwlock_rdlock(name) pthread_mutex_lock(& (name)->rw)
51+
#define my_atomic_rwlock_wrlock(name) pthread_mutex_lock(& (name)->rw)
52+
#define my_atomic_rwlock_rdunlock(name) pthread_mutex_unlock(& (name)->rw)
53+
#define my_atomic_rwlock_wrunlock(name) pthread_mutex_unlock(& (name)->rw)
8754

8855
#define MY_ATOMIC_MODE "mutex"
8956
#ifndef MY_ATOMIC_MODE_RWLOCKS

mysys/my_atomic.c

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -35,33 +35,3 @@ int my_atomic_initialize()
3535
return MY_ATOMIC_OK;
3636
#endif
3737
}
38-
39-
#ifdef SAFE_MUTEX
40-
#undef pthread_mutex_init
41-
#undef pthread_mutex_destroy
42-
#undef pthread_mutex_lock
43-
#undef pthread_mutex_unlock
44-
45-
void plain_pthread_mutex_init(safe_mutex_t *m)
46-
{
47-
pthread_mutex_init(& m->mutex, NULL);
48-
}
49-
50-
void plain_pthread_mutex_destroy(safe_mutex_t *m)
51-
{
52-
pthread_mutex_destroy(& m->mutex);
53-
}
54-
55-
void plain_pthread_mutex_lock(safe_mutex_t *m)
56-
{
57-
pthread_mutex_lock(& m->mutex);
58-
}
59-
60-
void plain_pthread_mutex_unlock(safe_mutex_t *m)
61-
{
62-
pthread_mutex_unlock(& m->mutex);
63-
}
64-
65-
#endif
66-
67-

0 commit comments

Comments
 (0)