Added a simple TLS test app.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2361 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
7208e95f0e
commit
1f149d94c4
@ -7,6 +7,7 @@ KernelObjects
|
||||
true_main.c
|
||||
sig_test.c
|
||||
select_test.c
|
||||
tls_test.c
|
||||
;
|
||||
|
||||
SubInclude OBOS_TOP src kernel apps cpuinfo ;
|
||||
|
93
src/kernel/apps/tls_test.c
Normal file
93
src/kernel/apps/tls_test.c
Normal file
@ -0,0 +1,93 @@
|
||||
/* tests TLS (thread locale storage) functionality */
|
||||
|
||||
/*
|
||||
** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||
** Distributed under the terms of the OpenBeOS License.
|
||||
*/
|
||||
|
||||
|
||||
#include <OS.h>
|
||||
#include <TLS.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
sem_id gWait;
|
||||
int32 gSlot;
|
||||
|
||||
|
||||
#if __INTEL__
|
||||
static void *
|
||||
read_fs_register(void)
|
||||
{
|
||||
void *fs;
|
||||
|
||||
asm("movl %%fs, %0" : "=r" (fs));
|
||||
return fs;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static int32
|
||||
thread1_func(void *data)
|
||||
{
|
||||
printf("1. stack at: %p\n", &data);
|
||||
printf("1. TLS address = %p\n", tls_address(gSlot));
|
||||
tls_set(gSlot, (void *)"thread 1");
|
||||
printf("1. TLS get = %s (should be \"thread 1\")\n", (char *)tls_get(gSlot));
|
||||
|
||||
acquire_sem(gWait);
|
||||
|
||||
printf("1. TLS get = %s (should be \"thread 1\")\n", (char *)tls_get(gSlot));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int32
|
||||
thread2_func(void *data)
|
||||
{
|
||||
printf("2. stack at: %p\n", &data);
|
||||
printf("2. TLS address = %p\n", tls_address(gSlot));
|
||||
printf("2. TLS get = %s (should be NULL)\n", (char *)tls_get(gSlot));
|
||||
|
||||
acquire_sem(gWait);
|
||||
|
||||
printf("2. TLS get = %s (should be NULL)\n", (char *)tls_get(gSlot));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
thread_id thread1, thread2;
|
||||
|
||||
gWait = create_sem(0, "waiter");
|
||||
gSlot = tls_allocate();
|
||||
|
||||
printf("got slot %ld : %p\n", gSlot, &thread1);
|
||||
|
||||
#if __INTEL__
|
||||
printf("FS register is %p\n", read_fs_register());
|
||||
#endif
|
||||
printf("TLS address in main = %p\n", tls_address(gSlot));
|
||||
|
||||
tls_set(gSlot, (void *)"main thread");
|
||||
|
||||
thread1 = spawn_thread(thread1_func, "Thread 1" , B_NORMAL_PRIORITY, NULL);
|
||||
resume_thread(thread1);
|
||||
thread2 = spawn_thread(thread2_func, "Thread 2" , B_NORMAL_PRIORITY, NULL);
|
||||
resume_thread(thread2);
|
||||
|
||||
printf("TLS in main = %s (should be \"main thread\")\n", (char *)tls_get(gSlot));
|
||||
|
||||
// shut down
|
||||
snooze(100000);
|
||||
delete_sem(gWait);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user