Bug #46981 Use my_atomic* functions for thread_safe_increment/decrement
Submitted: 28 Aug 2009 19:44 Modified: 28 Aug 2009 19:49
Reporter: Harrison Fisk Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: General Severity:S4 (Feature request)
Version:5.1+ OS:Any
Assigned to: CPU Architecture:Any

[28 Aug 2009 19:44] Harrison Fisk
Description:
There is a set of macros used in MySQL for thread safe operations:

 thread_safe_increment
 thread_safe_decrement
 thread_safe_add
 thread_safe_sub

In previous versions of MySQL these used to sometimes use atomic processor operations.  However, it was done by using the linux kernel headers, which caused various bugs (Bug #28456, Bug #15244) and it was removed as a result in 5.1.

Instead, MySQL now always uses mutexes to handle this which is slower than the old atomic operations.

MySQL 5.1 adds it's own library of atomic operations in mysys, defined in my_atomic.h.  

However, for some reason the two were never linked.  The thread_safe* functions should be able to use the my_atomics which should increase performance with less mutexes being used.

How to repeat:
1.  Check 5.0 compiled on linux and see it will use ASM
2.  Check 5.1 and see it uses mutexes
3.  See 5.1 provides my_atomic
4.  Wonder why the it isn't being used

Suggested fix:
Modify my_pthread.h to make use of the my_atomic_add and my_atomic_sub which is part of my_atomic.h.