-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AO primitives implementation to GC based on C11 atomic intrinsic
* Makefile.direct (SRCS): Add include/private/gc_atomic_ops.h. * include/include.am (dist_noinst_HEADERS): Likewise. * include/private/gc_atomic_ops.h: New file; define needed AO entities if GC_BUILTIN_ATOMIC, otherwise include atomic_ops.h. * include/private/gc_locks.h [THREADS && GC_PTHREADS && !GC_WIN32_THREADS]: Include gc_atomic_ops.h instead of atomic_ops.h. * include/private/gc_priv.h [PARALLEL_MARK || THREADS && MPROTECT_VDB]: Likewise. * include/private/specific.h: Likewise. * pthread_stop_world.c: Include private/gc_atomic_ops.h instead of atomic_ops.h. * tests/subthread_create.c: Likewise. * thread_local_alloc.c [THREAD_LOCAL_ALLOC && GC_GCJ_SUPPORT]: Likewise. * typd_mlc.c [GC_FORCE_INCLUDE_ATOMIC_OPS || GC_BUILTIN_ATOMIC]: Likewise. * win32_threads.c [GC_DLL && !GC_NO_THREADS_DISCOVERY && !MSWINCE]: Likewise.
- Loading branch information
Showing
11 changed files
with
110 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) 2017 Ivan Maidanski | ||
* | ||
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED | ||
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. | ||
* | ||
* Permission is hereby granted to use or copy this program | ||
* for any purpose, provided the above notices are retained on all copies. | ||
* Permission to modify the code and to distribute modified code is granted, | ||
* provided the above notices are retained, and a notice that the code was | ||
* modified is included with the above copyright notice. | ||
*/ | ||
|
||
/* This is a private GC header which provides an implementation of */ | ||
/* libatomic_ops subset primitives sufficient for GC assuming that C11 */ | ||
/* atomic intrinsics are available (and have correct implementation). */ | ||
/* This is enabled by defining GC_BUILTIN_ATOMIC macro. Otherwise, */ | ||
/* libatomic_ops library is used to define the primitives. */ | ||
|
||
#ifndef GC_ATOMIC_OPS_H | ||
#define GC_ATOMIC_OPS_H | ||
|
||
#ifdef GC_BUILTIN_ATOMIC | ||
|
||
# include "gc.h" /* for GC_word */ | ||
typedef GC_word AO_t; | ||
|
||
# ifdef GC_INLINE | ||
# define AO_INLINE GC_INLINE | ||
# else | ||
# define AO_INLINE static __inline | ||
# endif | ||
|
||
typedef unsigned char AO_TS_t; | ||
# define AO_TS_CLEAR 0 | ||
# define AO_TS_INITIALIZER (AO_TS_t)AO_TS_CLEAR | ||
# ifdef __GCC_ATOMIC_TEST_AND_SET_TRUEVAL | ||
# define AO_TS_SET __GCC_ATOMIC_TEST_AND_SET_TRUEVAL | ||
# else | ||
# define AO_TS_SET (AO_TS_t)0xff | ||
# endif | ||
# define AO_CLEAR(p) __atomic_clear(p, __ATOMIC_RELEASE) | ||
# define AO_test_and_set_acquire(p) __atomic_test_and_set(p, __ATOMIC_ACQUIRE) | ||
# define AO_HAVE_test_and_set_acquire | ||
|
||
# define AO_compiler_barrier() __atomic_thread_fence(__ATOMIC_RELAXED) | ||
# define AO_nop_full() __atomic_thread_fence(__ATOMIC_SEQ_CST) | ||
# define AO_HAVE_nop_full | ||
|
||
# define AO_fetch_and_add(p, v) __atomic_fetch_add(p, v, __ATOMIC_RELAXED) | ||
# define AO_HAVE_fetch_and_add | ||
# define AO_fetch_and_add1(p) AO_fetch_and_add(p, 1) | ||
# define AO_HAVE_fetch_and_add1 | ||
|
||
# define AO_or(p, v) (void)__atomic_or_fetch(p, v, __ATOMIC_RELAXED) | ||
# define AO_HAVE_or | ||
|
||
# define AO_load(p) __atomic_load_n(p, __ATOMIC_RELAXED) | ||
# define AO_HAVE_load | ||
# define AO_load_acquire(p) __atomic_load_n(p, __ATOMIC_ACQUIRE) | ||
# define AO_HAVE_load_acquire | ||
# define AO_load_acquire_read(p) AO_load_acquire(p) | ||
# define AO_HAVE_load_acquire_read | ||
|
||
# define AO_store(p, v) __atomic_store_n(p, v, __ATOMIC_RELAXED) | ||
# define AO_HAVE_store | ||
# define AO_store_release(p, v) __atomic_store_n(p, v, __ATOMIC_RELEASE) | ||
# define AO_HAVE_store_release | ||
# define AO_store_release_write(p, v) AO_store_release(p, v) | ||
# define AO_HAVE_store_release_write | ||
|
||
# ifdef AO_REQUIRE_CAS | ||
AO_INLINE int | ||
AO_compare_and_swap(volatile AO_t *p, AO_t ov, AO_t nv) | ||
{ | ||
return (int)__atomic_compare_exchange_n(p, &ov, nv, 0, | ||
__ATOMIC_RELAXED, __ATOMIC_RELAXED); | ||
} | ||
# define AO_HAVE_compare_and_swap | ||
|
||
AO_INLINE int | ||
AO_compare_and_swap_release(volatile AO_t *p, AO_t ov, AO_t nv) | ||
{ | ||
return (int)__atomic_compare_exchange_n(p, &ov, nv, 0, | ||
__ATOMIC_RELEASE, __ATOMIC_RELAXED); | ||
} | ||
# define AO_HAVE_compare_and_swap_release | ||
# endif | ||
|
||
#else | ||
/* Fallback to libatomic_ops. */ | ||
# include "atomic_ops.h" | ||
#endif /* !GC_BUILTIN_ATOMIC */ | ||
|
||
#endif /* GC_ATOMIC_OPS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters