Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -95,10 +95,11 @@ #ifdef OF_HAVE_CLASS_PROPERTIES # 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; # endif # ifdef OF_HAVE_SOCKETS @@ -186,10 +187,17 @@ * * @return The main thread */ + (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. * * @return A dictionary to store thread-specific data Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -188,10 +188,18 @@ + (OFThread *)mainThread { return mainThread; } + ++ (bool)isMainThread +{ + if (mainThread == nil) + return false; + + return (of_tlskey_get(threadSelfKey) == mainThread); +} + (OFMutableDictionary *)threadDictionary { OFThread *thread = of_tlskey_get(threadSelfKey);