Commit 97a0501e authored by Sergei Golubchik's avatar Sergei Golubchik

fix for a strict aliasing issue with gcc 3.4.3 on sol10-amd64-a

parent 38d024b5
...@@ -519,17 +519,24 @@ my_bool trnman_end_trn(TRN *trn, my_bool commit) ...@@ -519,17 +519,24 @@ my_bool trnman_end_trn(TRN *trn, my_bool commit)
*/ */
void trnman_free_trn(TRN *trn) void trnman_free_trn(TRN *trn)
{ {
TRN *tmp= pool; /*
union is to solve strict aliasing issue.
without it gcc 3.4.3 doesn't notice that updating *(void **)&tmp
modifies the value of tmp.
*/
union { TRN *trn; void *v; } tmp;
tmp.trn= pool;
my_atomic_rwlock_wrlock(&LOCK_pool); my_atomic_rwlock_wrlock(&LOCK_pool);
do do
{ {
/* /*
without this volatile cast gcc-3.4.4 moved the assignment without this volatile cast gcc-3.4.4 moves the assignment
down after the loop at -O2 down after the loop at -O2
*/ */
*(TRN * volatile *)&(trn->next)= tmp; *(TRN * volatile *)&(trn->next)= tmp.trn;
} while (!my_atomic_casptr((void **)&pool, (void **)&tmp, trn)); } while (!my_atomic_casptr((void **)&pool, &tmp.v, trn));
my_atomic_rwlock_wrunlock(&LOCK_pool); my_atomic_rwlock_wrunlock(&LOCK_pool);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment