diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-02-01 20:15:13 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-02-01 20:15:13 +0000 |
commit | 8d32bf9240c3a088f5b63e1b6e204e34855f9853 (patch) | |
tree | 1f437e24f32ccff17d1227b1dbf809a86570b655 /libgo | |
parent | 1facaf0dd3b84c31d77c997334e13c0b06554b66 (diff) | |
download | gcc-8d32bf9240c3a088f5b63e1b6e204e34855f9853.tar.gz |
Add __sync_bool_compare_and_swap_4 for targets which don't have it.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@169502 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo')
-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 c4e7f6c72e0..3f1c8d52e73 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 |