Author: rfm
Date: Tue Mar 31 11:45:40 2015
New Revision: 38443
URL: http://svn.gna.org/viewcvs/gnustep?rev=38443&view=rev
Log:
Impement test for main thread on linux
Added:
libs/base/trunk/Tests/base/NSThread/TestInfo
Modified:
libs/base/trunk/Headers/GNUstepBase/config.h.in
libs/base/trunk/Source/NSThread.m
libs/base/trunk/Tests/base/NSThread/lazy_thread.m
libs/base/trunk/configure
libs/base/trunk/configure.ac
Modified: libs/base/trunk/Headers/GNUstepBase/config.h.in
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Headers/GNUstepBase/config.h.in?rev=38443&r1=38442&r2=38443&view=diff
==============================================================================
--- libs/base/trunk/Headers/GNUstepBase/config.h.in (original)
+++ libs/base/trunk/Headers/GNUstepBase/config.h.in Tue Mar 31 11:45:40 2015
@@ -463,6 +463,9 @@
/* Define to 1 if you have the <pthread.h> header file. */
#undef HAVE_PTHREAD_H
+
+/* Define to 1 if you have the `pthread_main_np' function. */
+#undef HAVE_PTHREAD_MAIN_NP
/* Define to 1 if you have the <pthread_np.h> header file. */
#undef HAVE_PTHREAD_NP_H
Modified: libs/base/trunk/Source/NSThread.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSThread.m?rev=38443&r1=38442&r2=38443&view=diff
==============================================================================
--- libs/base/trunk/Source/NSThread.m (original)
+++ libs/base/trunk/Source/NSThread.m Tue Mar 31 11:45:40 2015
@@ -89,16 +89,18 @@
# include <pthread_np.h>
#endif
-#if defined(__FreeBSD__) || defined(__OpenBSD__)
-# define IS_MAIN_PTHREAD (pthread_main_np() == 1)
-#else
-# define IS_MAIN_PTHREAD (1)
-#endif
-
#if defined(HAVE_GETTID)
# include <unistd.h>
# include <sys/syscall.h>
# include <sys/types.h>
+#endif
+
+#if defined(HAVE_PTHREAD_MAIN_NP)
+# define IS_MAIN_PTHREAD (pthread_main_np() == 1)
+#elif defined(HAVE_GETTID)
+# define IS_MAIN_PTHREAD (getpid() == (pid_t)syscall(SYS_gettid))
+#else
+# define IS_MAIN_PTHREAD (1)
#endif
/* Return the current thread ID as an unsigned long.
@@ -845,7 +847,6 @@
}
[_target performSelector: _selector withObject: _arg];
-
}
- (NSString*) name
Added: libs/base/trunk/Tests/base/NSThread/TestInfo
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Tests/base/NSThread/TestInfo?rev=38443&view=auto
==============================================================================
(empty)
Modified: libs/base/trunk/Tests/base/NSThread/lazy_thread.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Tests/base/NSThread/lazy_thread.m?rev=38443&r1=38442&r2=38443&view=diff
==============================================================================
--- libs/base/trunk/Tests/base/NSThread/lazy_thread.m (original)
+++ libs/base/trunk/Tests/base/NSThread/lazy_thread.m Tue Mar 31 11:45:40 2015
@@ -4,24 +4,32 @@
void *thread(void *ignored)
{
- return [NSThread currentThread];
+ return [NSThread currentThread];
}
int main(void)
{
- pthread_t thr;
- void *ret;
+ pthread_t thr;
+ void *ret;
- pthread_create(&thr, NULL, thread, NULL);
- pthread_join(thr, &ret);
- PASS(ret != 0, "NSThread lazily created from POSIX thread");
- testHopeful = YES;
- PASS((ret != 0) && (ret != [NSThread mainThread]), "Spawned thread is
not main thread");
- pthread_create(&thr, NULL, thread, NULL);
- pthread_join(thr, &ret);
- PASS(ret != 0, "NSThread lazily created from POSIX thread");
- PASS((ret != 0) && (ret != [NSThread mainThread]), "Spawned thread is
not main thread");
+ pthread_create(&thr, NULL, thread, NULL);
+ pthread_join(thr, &ret);
+ PASS(ret != 0, "NSThread lazily created from POSIX thread");
+ testHopeful = YES;
+ PASS((ret != 0) && (ret != [NSThread mainThread]),
+ "Spawned thread is not main thread");
+ pthread_create(&thr, NULL, thread, NULL);
+ pthread_join(thr, &ret);
+ PASS(ret != 0, "NSThread lazily created from POSIX thread");
+ PASS((ret != 0) && (ret != [NSThread mainThread]),
+ "Spawned thread is not main thread");
- return 0;
+ NSThread *t = [NSThread currentThread];
+ [t setName: @"xxxtestxxx"];
+ NSLog(@"Thread description is '%@'", t);
+ NSRange r = [[t description] rangeOfString: @"name = xxxtestxxx"];
+ PASS(r.length > 0, "thread description contains name");
+
+ return 0;
}
Modified: libs/base/trunk/configure
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/configure?rev=38443&r1=38442&r2=38443&view=diff
==============================================================================
--- libs/base/trunk/configure (original)
+++ libs/base/trunk/configure Tue Mar 31 11:45:40 2015
@@ -13569,10 +13569,11 @@
{ (exit 1); exit 1; }; }
fi
-/* See if we have an extension to get a pthread ID
+/* Check threading extensions
*/
-for ac_func in pthread_getthreadid_np
+
+for ac_func in pthread_getthreadid_np pthread_main_np
do
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5
Modified: libs/base/trunk/configure.ac
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/configure.ac?rev=38443&r1=38442&r2=38443&view=diff
==============================================================================
--- libs/base/trunk/configure.ac (original)
+++ libs/base/trunk/configure.ac Tue Mar 31 11:45:40 2015
@@ -1715,9 +1715,9 @@
AC_MSG_ERROR([Unable to find pthread library (needed for thread support).])
fi
-/* See if we have an extension to get a pthread ID
+/* Check threading extensions
*/
-AC_CHECK_FUNCS(pthread_getthreadid_np)
+AC_CHECK_FUNCS(pthread_getthreadid_np pthread_main_np)
# Typically need librt on Solaris for sched_yield
AC_CHECK_LIB(rt, sched_yield)
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs