mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Impement test for main thread on linux
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38443 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
33688ccb99
commit
82e156d9cb
6 changed files with 37 additions and 24 deletions
|
@ -464,6 +464,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
|
||||
|
||||
|
|
|
@ -89,18 +89,20 @@
|
|||
# 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.
|
||||
* Ideally, we use the operating-system's notion of a thread ID so
|
||||
* that external process monitoring software will be using the same
|
||||
|
@ -845,7 +847,6 @@ unregisterActiveThread(NSThread *thread)
|
|||
}
|
||||
|
||||
[_target performSelector: _selector withObject: _arg];
|
||||
|
||||
}
|
||||
|
||||
- (NSString*) name
|
||||
|
|
0
Tests/base/NSThread/TestInfo
Normal file
0
Tests/base/NSThread/TestInfo
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
5
configure
vendored
5
configure
vendored
|
@ -13569,10 +13569,11 @@ $as_echo "$as_me: error: Unable to find pthread library (needed for thread suppo
|
|||
{ (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
|
||||
|
|
|
@ -1715,9 +1715,9 @@ if test $pthread_ok = no ; then
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue