Skip to content

Commit df1abba

Browse files
authored
Merge branch 'HaxeFoundation:master' into patch-2
2 parents d8cc23c + be7ef02 commit df1abba

3 files changed

Lines changed: 93 additions & 13 deletions

File tree

include/hx/StdLibs.h

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,16 +473,102 @@ inline void* _hx_atomic_compare_exchange_ptr(volatile void **a, void *expected,
473473
#elif defined(HX_MSVC_ATOMICS)
474474
return _InterlockedCompareExchangePointer((void *volatile *)a, replacement, expected);
475475
#else
476-
void *old = *a;
477-
*a = replacement;
478-
return old;
476+
void *old = *a;
477+
if (old == expected) {
478+
*a = replacement;
479+
}
480+
return old;
479481
#endif
480482
}
481483

482484
inline void* _hx_atomic_compare_exchange_cast_ptr(void *a, void *expected, void *replacement) {
483485
return _hx_atomic_compare_exchange_ptr((volatile void **)a, expected, replacement);
484486
}
485487

488+
#include <atomic>
489+
490+
struct AtomicObject: hx::Object {
491+
std::atomic< ::hx::Object *> aPtr;
492+
493+
AtomicObject(Dynamic val) { aPtr = val.mPtr; }
494+
495+
void __Mark(hx::MarkContext *__inCtx) {
496+
Dynamic ptr = load();
497+
HX_MARK_MEMBER(ptr);
498+
}
499+
500+
#ifdef HXCPP_VISIT_ALLOCS
501+
void __Visit(hx::VisitContext *__inCtx) {
502+
hx::Object *obj = aPtr.load();
503+
HX_VISIT_MEMBER(obj);
504+
aPtr.store(obj);
505+
}
506+
#endif
507+
508+
Dynamic store(Dynamic val) {
509+
aPtr.store(val.mPtr);
510+
HX_OBJ_WB_GET(this, val.mPtr);
511+
return val;
512+
}
513+
514+
Dynamic load() {
515+
return aPtr.load();
516+
}
517+
518+
Dynamic exchange(Dynamic val) {
519+
Dynamic ret = aPtr.exchange(val.mPtr);
520+
HX_OBJ_WB_GET(this, val.mPtr);
521+
return ret;
522+
}
523+
524+
Dynamic compareExchange(Dynamic expected, Dynamic replacement) {
525+
// Note: using Dynamic instead of hx::Object* is important
526+
// Dynamic has an overloaded == operator, a raw pointer to hx::Object does not.
527+
Dynamic original = aPtr.load();
528+
while (original == expected) {
529+
if (aPtr.compare_exchange_weak(original.mPtr, replacement.mPtr)) {
530+
HX_OBJ_WB_GET(this, replacement.mPtr);
531+
return original;
532+
} else {
533+
continue;
534+
}
535+
}
536+
return original;
537+
}
538+
};
539+
540+
inline Dynamic __hxcpp_atomic_object_create(Dynamic value) {
541+
return new AtomicObject(value);
542+
}
543+
544+
inline Dynamic __hxcpp_atomic_object_store(Dynamic dynObj, Dynamic val) {
545+
AtomicObject *obj = dynamic_cast<AtomicObject *>(dynObj.mPtr);
546+
if (!obj)
547+
throw HX_INVALID_OBJECT;
548+
return obj->store(val);
549+
}
550+
551+
inline Dynamic __hxcpp_atomic_object_load(Dynamic dynObj) {
552+
AtomicObject *obj = dynamic_cast<AtomicObject *>(dynObj.mPtr);
553+
if (!obj)
554+
throw HX_INVALID_OBJECT;
555+
return obj->load();
556+
}
557+
558+
inline Dynamic __hxcpp_atomic_object_exchange(Dynamic dynObj, Dynamic newVal) {
559+
AtomicObject *obj = dynamic_cast<AtomicObject *>(dynObj.mPtr);
560+
if (!obj)
561+
throw HX_INVALID_OBJECT;
562+
return obj->exchange(newVal);
563+
}
564+
565+
inline Dynamic __hxcpp_atomic_object_compare_exchange(Dynamic dynObj, Dynamic expected, Dynamic replacement) {
566+
AtomicObject *obj = dynamic_cast<AtomicObject *>(dynObj.mPtr);
567+
if (!obj)
568+
throw HX_INVALID_OBJECT;
569+
return obj->compareExchange(expected, replacement);
570+
}
571+
486572
Array<String> __hxcpp_get_call_stack(bool inSkipLast);
487573
Array<String> __hxcpp_get_exception_stack();
488574
#define HXCPP_HAS_CLASSLIST

src/hx/gc/Immix.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,13 @@ static bool sGcVerifyGenerational = false;
198198
#else
199199
enum { MAX_GC_THREADS = 2 };
200200
#endif
201+
202+
// You can uncomment this for better call stacks if it crashes while collecting
203+
#define HX_MULTI_THREAD_MARKING
201204
#else
202205
enum { MAX_GC_THREADS = 1 };
203206
#endif
204207

205-
#if (MAX_GC_THREADS>1)
206-
// You can uncomment this for better call stacks if it crashes while collecting
207-
#define HX_MULTI_THREAD_MARKING
208-
#endif
209-
210208
#ifdef PROFILE_THREAD_USAGE
211209
static int sThreadMarkCountData[MAX_GC_THREADS+1];
212210
static int sThreadArrayMarkCountData[MAX_GC_THREADS+1];
@@ -1952,7 +1950,7 @@ class MarkContext
19521950
if (obj)
19531951
{
19541952
obj->__Mark(this);
1955-
#if HX_MULTI_THREAD_MARKING
1953+
#ifdef HX_MULTI_THREAD_MARKING
19561954
// Load balance
19571955
if (sLazyThreads && marking->count>32)
19581956
{

src/hx/libs/zlib/Build.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
<compilerflag value="-DSTDC" unless="windows" />
1414
<compilerflag value="-DHAVE_UNISTD_H" unless="windows" />
1515

16-
<compilerflag value="-Wno-unknown-warning" unless="MSVC_VER" />
17-
<compilerflag value="-Wno-unknown-warning-option" unless="MSVC_VER" />
18-
<compilerflag value="-Wno-deprecated-non-prototype" unless="MSVC_VER" />
19-
2016
<file name="ZLib.cpp"/>
2117

2218
<!-- HXCPP_LINK_NO_ZLIB may be set too late, so use filterout as well. -->

0 commit comments

Comments
 (0)