< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahSharedVariables.hpp

Print this page
rev 59533 : 8246097: Shenandoah: limit parallelism in CLDG root handling
Reviewed-by: XXX

*** 243,248 **** --- 243,282 ---- bool operator< (ShenandoahSharedEnumFlag& other) { fatal("Use get() instead"); return false; } bool operator<=(ShenandoahSharedEnumFlag& other) { fatal("Use get() instead"); return false; } }; + typedef struct ShenandoahSharedSemaphore { + shenandoah_padding(0); + volatile ShenandoahSharedValue value; + shenandoah_padding(1); + + static uint max_tokens() { + return sizeof(ShenandoahSharedValue) * CHAR_MAX; + } + + ShenandoahSharedSemaphore(uint tokens) { + assert(tokens <= max_tokens(), "sanity"); + Atomic::release_store_fence(&value, (ShenandoahSharedValue)tokens); + } + + bool try_acquire() { + while (true) { + ShenandoahSharedValue ov = Atomic::load_acquire(&value); + if (ov == 0) { + return false; + } + ShenandoahSharedValue nv = ov - 1; + if (Atomic::cmpxchg(&value, ov, nv) == ov) { + // successfully set + return true; + } + } + } + + void claim_all() { + Atomic::release_store_fence(&value, (ShenandoahSharedValue)0); + } + + } ShenandoahSharedSemaphore; + #endif // SHARE_GC_SHENANDOAH_SHENANDOAHSHAREDVARIABLES_HPP
< prev index next >