Use common pattern for function-like macro (#4625)

This commit is contained in:
Alexander Shabalin
2021-01-12 12:47:00 +03:00
committed by Nikolay Krasko
parent 32e3deace1
commit adf80418af
4 changed files with 36 additions and 22 deletions
@@ -129,10 +129,10 @@ class CyclicCollector {
public:
CyclicCollector() {
CHECK_CALL(pthread_mutex_init(&lock_, nullptr), "Cannot init collector mutex")
CHECK_CALL(pthread_mutex_init(&timestampLock_, nullptr), "Cannot init collector timestamp mutex")
CHECK_CALL(pthread_cond_init(&cond_, nullptr), "Cannot init collector condition")
CHECK_CALL(pthread_create(&gcThread_, nullptr, gcWorkerRoutine, this), "Cannot start collector thread")
CHECK_CALL(pthread_mutex_init(&lock_, nullptr), "Cannot init collector mutex");
CHECK_CALL(pthread_mutex_init(&timestampLock_, nullptr), "Cannot init collector timestamp mutex");
CHECK_CALL(pthread_cond_init(&cond_, nullptr), "Cannot init collector condition");
CHECK_CALL(pthread_create(&gcThread_, nullptr, gcWorkerRoutine, this), "Cannot start collector thread");
}
void clear() {
@@ -146,7 +146,7 @@ class CyclicCollector {
Locker locker(&lock_);
terminateCollector_ = true;
if (enabled) shallRunCollector_ = true;
CHECK_CALL(pthread_cond_signal(&cond_), "Cannot signal collector")
CHECK_CALL(pthread_cond_signal(&cond_), "Cannot signal collector");
}
// TODO: improve waiting for collector termination.
while (atomicGet(&terminateCollector_)) {}
@@ -173,7 +173,7 @@ class CyclicCollector {
KStdUnorderedMap<ObjHeader*, int> sideRefCounts;
int restartCount = 0;
while (!terminateCollector_) {
CHECK_CALL(pthread_cond_wait(&cond_, &lock_), "Cannot wait collector condition")
CHECK_CALL(pthread_cond_wait(&cond_, &lock_), "Cannot wait collector condition");
if (!shallRunCollector_) continue;
atomicSet(&gcRunning_, 1);
restartCount = 0;
@@ -325,7 +325,7 @@ class CyclicCollector {
// When exiting the worker - we shall collect the cyclic garbage here.
if (enabled) {
shallRunCollector_ = true;
CHECK_CALL(pthread_cond_signal(&cond_), "Cannot signal collector")
CHECK_CALL(pthread_cond_signal(&cond_), "Cannot signal collector");
}
currentAliveWorkers_--;
}
@@ -416,7 +416,7 @@ class CyclicCollector {
if (checkIfShallCollect()) {
Locker locker(&lock_);
shallRunCollector_ = true;
CHECK_CALL(pthread_cond_signal(&cond_), "Cannot signal collector")
CHECK_CALL(pthread_cond_signal(&cond_), "Cannot signal collector");
}
}
@@ -424,7 +424,7 @@ class CyclicCollector {
if (atomicGet(&gcRunning_) != 0) return;
Locker lock(&lock_);
shallRunCollector_ = true;
CHECK_CALL(pthread_cond_signal(&cond_), "Cannot signal collector")
CHECK_CALL(pthread_cond_signal(&cond_), "Cannot signal collector");
}
void localGC() {
@@ -1164,7 +1164,7 @@ void freeAggregatingFrozenContainer(ContainerHeader* container) {
auto* state = memoryState;
RuntimeAssert(isAggregatingFrozenContainer(container), "expected fictitious frozen container");
MEMORY_LOG("%p is fictitious frozen container\n", container);
RuntimeAssert(!container->buffered(), "frozen objects must not participate in GC")
RuntimeAssert(!container->buffered(), "frozen objects must not participate in GC");
#if USE_GC
// Forbid finalizerQueue handling.
++state->finalizerQueueSuspendCount;
@@ -2056,7 +2056,7 @@ MemoryState* initMemory(bool firstRuntime) {
==
offsetof(MetaObjHeader, typeInfo_),
"Layout mismatch");
RuntimeAssert(sizeof(FrameOverlay) % sizeof(ObjHeader**) == 0, "Frame overlay should contain only pointers")
RuntimeAssert(sizeof(FrameOverlay) % sizeof(ObjHeader**) == 0, "Frame overlay should contain only pointers");
RuntimeAssert(memoryState == nullptr, "memory state must be clear");
memoryState = konanConstructInstance<MemoryState>();
INIT_EVENT(memoryState)
+24 -10
View File
@@ -25,6 +25,13 @@
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#if KONAN_ENABLE_ASSERT
#define CURRENT_SOURCE_LOCATION __FILE__ ":" TOSTRING(__LINE__)
#else
// Do not generate location strings, when asserts are disabled to reduce code size.
#define CURRENT_SOURCE_LOCATION nullptr
#endif
RUNTIME_NORETURN void RuntimeAssertFailed(const char* location, const char* message, ...);
namespace internal {
@@ -46,24 +53,31 @@ extern "C" const int KonanNeedDebugInfo;
#if KONAN_ENABLE_ASSERT
// Use RuntimeAssert() in internal state checks, which could be ignored in production.
#define RuntimeAssert(condition, format, ...) \
if (KonanNeedDebugInfo && (!(condition))) { \
RuntimeAssertFailed( __FILE__ ":" TOSTRING(__LINE__), format, ##__VA_ARGS__); \
}
#define RuntimeAssert(condition, format, ...) \
do { \
if (KonanNeedDebugInfo && (!(condition))) { \
RuntimeAssertFailed(CURRENT_SOURCE_LOCATION, format, ##__VA_ARGS__); \
} \
} while (false)
#else
#define RuntimeAssert(condition, message)
#define RuntimeAssert(condition, format, ...) \
do { \
} while (false)
#endif
// Use RuntimeCheck() in runtime checks that could fail due to external condition and shall lead
// to program termination. Never compiled out.
#define RuntimeCheck(condition, format, ...) \
if (!(condition)) { \
RuntimeAssertFailed(nullptr, format, ##__VA_ARGS__); \
}
// TODO: Consider using `CURRENT_SOURCE_LOCATION` when `KonanNeedDebugInfo` is `true`.
#define RuntimeCheck(condition, format, ...) \
do { \
if (!(condition)) { \
RuntimeAssertFailed(nullptr, format, ##__VA_ARGS__); \
} \
} while (false)
#define TODO(...) \
do { \
::internal::TODOImpl(__FILE__ ":" TOSTRING(__LINE__), ##__VA_ARGS__); \
::internal::TODOImpl(CURRENT_SOURCE_LOCATION, ##__VA_ARGS__); \
} while (false)
#endif // RUNTIME_ASSERT_H
@@ -177,7 +177,7 @@ void BackRefFromAssociatedObject::releaseRef() {
}
void BackRefFromAssociatedObject::detach() {
RuntimeAssert(atomicGet(&refCount) == 0, "unexpected refCount")
RuntimeAssert(atomicGet(&refCount) == 0, "unexpected refCount");
obj_ = nullptr; // Handled in addRef/tryAddRef/releaseRef/ref.
}