diff --git a/src/Util/Asserts.h b/src/Util/Asserts.h index 6b94d56ac..d0cfbc728 100755 --- a/src/Util/Asserts.h +++ b/src/Util/Asserts.h @@ -1,7 +1,5 @@ // -// Asserts.h -// -// Copyright (c) 2016 Open Whisper Systems. All rights reserved. +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // #import @@ -21,9 +19,18 @@ NSLog(@"Assertion failed: %s", CONVERT_EXPR_TO_STRING(X)); \ NSAssert(0, @"Assertion failed: %s", CONVERT_EXPR_TO_STRING(X)); \ } +// OWSAssert() should be used in Obj-C and Swift methods. +// OWSCAssert() should be used in free functions. +#define OWSCAssert(X) \ +if (!(X)) { \ +NSLog(@"Assertion failed: %s", CONVERT_EXPR_TO_STRING(X)); \ +NSCAssert(0, @"Assertion failed: %s", CONVERT_EXPR_TO_STRING(X)); \ +} + #else #define OWSAssert(X) +#define OWSCAssert(X) #endif diff --git a/src/Util/OWSDispatch.h b/src/Util/OWSDispatch.h index 8d6b42985..7da5da39f 100644 --- a/src/Util/OWSDispatch.h +++ b/src/Util/OWSDispatch.h @@ -24,4 +24,6 @@ NS_ASSUME_NONNULL_BEGIN @end +void AssertIsOnMainThread(); + NS_ASSUME_NONNULL_END diff --git a/src/Util/OWSDispatch.m b/src/Util/OWSDispatch.m index 6d3353100..89a4aef96 100644 --- a/src/Util/OWSDispatch.m +++ b/src/Util/OWSDispatch.m @@ -40,4 +40,8 @@ NS_ASSUME_NONNULL_BEGIN @end +void AssertIsOnMainThread() { + OWSCAssert([NSThread isMainThread]); +} + NS_ASSUME_NONNULL_END