summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@heap.zone>2019-09-01 20:22:55 +0200
committerJonathan Schleifer <js@heap.zone>2019-09-01 20:22:55 +0200
commit35d55346a6d8c5e414de004519bae786953bb03a (patch)
tree9fd288e80f2264ff8ca9011d12f882c5bfba7a44
parent8d2db52f33a7ada2d77888394685592f68b5f200 (diff)
Add +[OFThread isMainThread]
-rw-r--r--src/OFThread.h8
-rw-r--r--src/OFThread.m8
2 files changed, 16 insertions, 0 deletions
diff --git a/src/OFThread.h b/src/OFThread.h
index ac0da7b2..501d43c7 100644
--- a/src/OFThread.h
+++ b/src/OFThread.h
@@ -97,6 +97,7 @@ typedef id _Nullable (^of_thread_block_t)(void);
# ifdef OF_HAVE_THREADS
@property (class, readonly, nullable, nonatomic) OFThread *currentThread;
@property (class, readonly, nullable, nonatomic) OFThread *mainThread;
+@property (class, readonly, nonatomic) bool isMainThread;
@property (class, readonly, nullable, nonatomic)
OFMutableDictionary *threadDictionary;
@property (class, nullable, copy, nonatomic) OFString *name;
@@ -189,6 +190,13 @@ typedef id _Nullable (^of_thread_block_t)(void);
+ (nullable OFThread *)mainThread;
/*!
+ * @brief Returns whether the current thread is the main thread.
+ *
+ * @return Whether the current thread is the main thread.
+ */
++ (bool)isMainThread;
+
+/*!
* @brief Returns a dictionary to store thread-specific data, meaning it
* returns a different dictionary for every thread.
*
diff --git a/src/OFThread.m b/src/OFThread.m
index a1e52bd1..cac9291b 100644
--- a/src/OFThread.m
+++ b/src/OFThread.m
@@ -191,6 +191,14 @@ static OFDNSResolver *DNSResolver;
return mainThread;
}
++ (bool)isMainThread
+{
+ if (mainThread == nil)
+ return false;
+
+ return (of_tlskey_get(threadSelfKey) == mainThread);
+}
+
+ (OFMutableDictionary *)threadDictionary
{
OFThread *thread = of_tlskey_get(threadSelfKey);