diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-02-01 20:15:13 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-02-01 20:15:13 +0000 |
commit | e499b5eef4a54a30664ea9b711e5c4c074c027ee (patch) | |
tree | 1f437e24f32ccff17d1227b1dbf809a86570b655 | |
parent | 22843acd311d3efc611d145b72e1e02e24db6c44 (diff) | |
download | gcc-e499b5eef4a54a30664ea9b711e5c4c074c027ee.zip gcc-e499b5eef4a54a30664ea9b711e5c4c074c027ee.tar.gz gcc-e499b5eef4a54a30664ea9b711e5c4c074c027ee.tar.bz2 |
Add __sync_bool_compare_and_swap_4 for targets which don't have it.
From-SVN: r169502
-rw-r--r-- | libgo/runtime/thread.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/libgo/runtime/thread.c b/libgo/runtime/thread.c index c4e7f6c..3f1c8d5 100644 --- a/libgo/runtime/thread.c +++ b/libgo/runtime/thread.c @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. #include "runtime.h" +#include "go-assert.h" void runtime_initlock(Lock *l) @@ -75,3 +76,38 @@ runtime_destroylock(Lock *l) { sem_destroy(&l->sem); } + +#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 + +// For targets which don't have the required sync support. Really +// this should be provided by gcc itself. FIXME. + +static pthread_mutex_t sync_lock = PTHREAD_MUTEX_INITIALIZER; + +_Bool +__sync_bool_compare_and_swap_4(uint32*, uint32, uint32) + __attribute__((visibility("hidden"))); + +_Bool +__sync_bool_compare_and_swap_4(uint32* ptr, uint32 old, uint32 new) +{ + int i; + _Bool ret; + + i = pthread_mutex_lock(&sync_lock); + __go_assert(i == 0); + + if(*ptr != old) { + ret = 0; + } else { + *ptr = new; + ret = 1; + } + + i = pthread_mutex_unlock(&sync_lock); + __go_assert(i == 0); + + return ret; +} + +#endif |