annotate tests/test-tls.c @ 17622:71e733c62cee

savedir: add sorting arg to savedir, streamsavedir; remove fdsavedir Patch based on an idea by Dick Streefland in <https://savannah.gnu.org/patch/?7892>. * NEWS: Document this. * lib/savedir.c (NAME_SIZE_DEFAULT): Remove. (direntry_t, comparison_function): New types. (direntry_cmp_name): New function. (direntry_cmp_inode) [D_INO_IN_DIRENT]: New function. (streamsavedir, savedir): New arg OPTION. (streamsavedir): Simplify memory allocation. (fdsavedir): Remove. * lib/savedir.h (enum savedir_option): New type. (streamsavedir, savedir): New arg OPTION. (fdsavedir): Remove.
author Sergey Poznyakoff <gray@gnu.org.ua>
date Thu, 13 Feb 2014 22:01:39 +0200
parents 344018b6e5d7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of thread-local storage in multithreaded situations.
17587
344018b6e5d7 maint: update copyright
Eric Blake <eblake@redhat.com>
parents: 17249
diff changeset
2 Copyright (C) 2005, 2008-2014 Free Software Foundation, Inc.
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
4 This program is free software: you can redistribute it and/or modify
7139
adb21c293305 Add copyright notices to long-enough files that lack them, since
Paul Eggert <eggert@cs.ucla.edu>
parents: 6115
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
7 (at your option) any later version.
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
7139
adb21c293305 Add copyright notices to long-enough files that lack them, since
Paul Eggert <eggert@cs.ucla.edu>
parents: 6115
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
adb21c293305 Add copyright notices to long-enough files that lack them, since
Paul Eggert <eggert@cs.ucla.edu>
parents: 6115
diff changeset
12 GNU General Public License for more details.
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
7139
adb21c293305 Add copyright notices to long-enough files that lack them, since
Paul Eggert <eggert@cs.ucla.edu>
parents: 6115
diff changeset
14 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2005. */
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 7139
diff changeset
19 #include <config.h>
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
16214
ec738d6aeef5 Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
21 #if USE_POSIX_THREADS || USE_SOLARIS_THREADS || USE_PTH_THREADS || USE_WINDOWS_THREADS
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #if USE_POSIX_THREADS
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 # define TEST_POSIX_THREADS 1
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #endif
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #if USE_SOLARIS_THREADS
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 # define TEST_SOLARIS_THREADS 1
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #endif
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #if USE_PTH_THREADS
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 # define TEST_PTH_THREADS 1
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #endif
16214
ec738d6aeef5 Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
32 #if USE_WINDOWS_THREADS
ec738d6aeef5 Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
33 # define TEST_WINDOWS_THREADS 1
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #endif
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 /* Whether to help the scheduler through explicit yield().
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 Uncomment this to see if the operating system has a fair scheduler. */
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #define EXPLICIT_YIELD 1
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 /* Whether to print debugging messages. */
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 #define ENABLE_DEBUGGING 0
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 /* Number of simultaneous threads. */
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 #define THREAD_COUNT 16
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 /* Number of operations performed in each thread. */
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 #define REPEAT_COUNT 50000
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 #include <stdio.h>
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 #include <stdlib.h>
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 #include <string.h>
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52
10318
8a3539888308 Move the lock and tls source files into a subdirectory.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
53 #include "glthread/tls.h"
10556
d6619672e1a6 Make use of the modules 'thread', 'yield' in the 'tls' test.
Bruno Haible <bruno@clisp.org>
parents: 10461
diff changeset
54 #include "glthread/thread.h"
d6619672e1a6 Make use of the modules 'thread', 'yield' in the 'tls' test.
Bruno Haible <bruno@clisp.org>
parents: 10461
diff changeset
55 #include "glthread/yield.h"
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 #if ENABLE_DEBUGGING
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 # define dbgprintf printf
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 #else
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 # define dbgprintf if (0) printf
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 #endif
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 #if EXPLICIT_YIELD
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 # define yield() gl_thread_yield ()
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 #else
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 # define yield()
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 #endif
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68
17096
14a45e05c23c tls-tests: omit unnecessary 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents: 16214
diff changeset
69 static void
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 perhaps_yield (void)
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 {
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 /* Call yield () only with a certain probability, otherwise with GNU Pth
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 the sequence of thread activations is too predictable. */
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 if ((((unsigned int) rand () >> 3) % 4) == 0)
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 yield ();
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 }
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77
10858
fbae6908522f Avoid gcc -Wmissing-prototypes warnings.
Bruno Haible <bruno@clisp.org>
parents: 10556
diff changeset
78
fbae6908522f Avoid gcc -Wmissing-prototypes warnings.
Bruno Haible <bruno@clisp.org>
parents: 10556
diff changeset
79 /* ----------------------- Test thread-local storage ----------------------- */
fbae6908522f Avoid gcc -Wmissing-prototypes warnings.
Bruno Haible <bruno@clisp.org>
parents: 10556
diff changeset
80
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 #define KEYS_COUNT 4
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 static gl_tls_key_t mykeys[KEYS_COUNT];
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 static void *
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 worker_thread (void *arg)
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 {
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 unsigned int id = (unsigned int) (unsigned long) arg;
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 int i, j, repeat;
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 unsigned int values[KEYS_COUNT];
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91
14901
4b26d9ce6840 thread: Support pthreads-win32.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
92 dbgprintf ("Worker %p started\n", gl_thread_self_pointer ());
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 /* Initialize the per-thread storage. */
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 for (i = 0; i < KEYS_COUNT; i++)
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 {
13051
094f6cfdb5c3 Minor formatting changes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
97 values[i] = (((unsigned int) rand () >> 3) % 1000000) * THREAD_COUNT + id;
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 /* Hopefully no arithmetic overflow. */
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 if ((values[i] % THREAD_COUNT) != id)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
100 abort ();
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 }
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 perhaps_yield ();
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 /* Verify that the initial value is NULL. */
14901
4b26d9ce6840 thread: Support pthreads-win32.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
105 dbgprintf ("Worker %p before initial verify\n", gl_thread_self_pointer ());
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 for (i = 0; i < KEYS_COUNT; i++)
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 if (gl_tls_get (mykeys[i]) != NULL)
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 abort ();
14901
4b26d9ce6840 thread: Support pthreads-win32.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
109 dbgprintf ("Worker %p after initial verify\n", gl_thread_self_pointer ());
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 perhaps_yield ();
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 /* Initialize the per-thread storage. */
14901
4b26d9ce6840 thread: Support pthreads-win32.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
113 dbgprintf ("Worker %p before first tls_set\n", gl_thread_self_pointer ());
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 for (i = 0; i < KEYS_COUNT; i++)
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 {
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 unsigned int *ptr = (unsigned int *) malloc (sizeof (unsigned int));
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 *ptr = values[i];
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 gl_tls_set (mykeys[i], ptr);
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 }
14901
4b26d9ce6840 thread: Support pthreads-win32.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
120 dbgprintf ("Worker %p after first tls_set\n", gl_thread_self_pointer ());
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 perhaps_yield ();
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 /* Shuffle around the pointers. */
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 {
14901
4b26d9ce6840 thread: Support pthreads-win32.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
126 dbgprintf ("Worker %p doing value swapping\n", gl_thread_self_pointer ());
13051
094f6cfdb5c3 Minor formatting changes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
127 i = ((unsigned int) rand () >> 3) % KEYS_COUNT;
094f6cfdb5c3 Minor formatting changes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
128 j = ((unsigned int) rand () >> 3) % KEYS_COUNT;
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 if (i != j)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
130 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
131 void *vi = gl_tls_get (mykeys[i]);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
132 void *vj = gl_tls_get (mykeys[j]);
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
134 gl_tls_set (mykeys[i], vj);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
135 gl_tls_set (mykeys[j], vi);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
136 }
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 perhaps_yield ();
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 }
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 /* Verify that all the values are from this thread. */
14901
4b26d9ce6840 thread: Support pthreads-win32.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
141 dbgprintf ("Worker %p before final verify\n", gl_thread_self_pointer ());
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 for (i = 0; i < KEYS_COUNT; i++)
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 if ((*(unsigned int *) gl_tls_get (mykeys[i]) % THREAD_COUNT) != id)
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 abort ();
14901
4b26d9ce6840 thread: Support pthreads-win32.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
145 dbgprintf ("Worker %p after final verify\n", gl_thread_self_pointer ());
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 perhaps_yield ();
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147
14901
4b26d9ce6840 thread: Support pthreads-win32.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
148 dbgprintf ("Worker %p dying.\n", gl_thread_self_pointer ());
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 return NULL;
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 }
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151
10858
fbae6908522f Avoid gcc -Wmissing-prototypes warnings.
Bruno Haible <bruno@clisp.org>
parents: 10556
diff changeset
152 static void
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 test_tls (void)
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 {
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 int pass, i;
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 for (pass = 0; pass < 2; pass++)
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 {
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 gl_thread_t threads[THREAD_COUNT];
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 if (pass == 0)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
162 for (i = 0; i < KEYS_COUNT; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
163 gl_tls_key_init (mykeys[i], free);
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
165 for (i = KEYS_COUNT - 1; i >= 0; i--)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
166 gl_tls_key_init (mykeys[i], free);
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 /* Spawn the threads. */
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 for (i = 0; i < THREAD_COUNT; i++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
170 threads[i] = gl_thread_create (worker_thread, NULL);
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 /* Wait for the threads to terminate. */
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 for (i = 0; i < THREAD_COUNT; i++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
174 gl_thread_join (threads[i], NULL);
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 for (i = 0; i < KEYS_COUNT; i++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10858
diff changeset
177 gl_tls_key_destroy (mykeys[i]);
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 }
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 }
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180
10858
fbae6908522f Avoid gcc -Wmissing-prototypes warnings.
Bruno Haible <bruno@clisp.org>
parents: 10556
diff changeset
181
fbae6908522f Avoid gcc -Wmissing-prototypes warnings.
Bruno Haible <bruno@clisp.org>
parents: 10556
diff changeset
182 /* -------------------------------------------------------------------------- */
fbae6908522f Avoid gcc -Wmissing-prototypes warnings.
Bruno Haible <bruno@clisp.org>
parents: 10556
diff changeset
183
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 int
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 main ()
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 {
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 #if TEST_PTH_THREADS
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 if (!pth_init ())
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 abort ();
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 #endif
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 printf ("Starting test_tls ..."); fflush (stdout);
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 test_tls ();
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 printf (" OK\n"); fflush (stdout);
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 return 0;
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 }
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 #else
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201 /* No multithreading available. */
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202
10353
a34661f8b5c8 test-lock, test-tls: mention why a test is skipped
Eric Blake <ebb9@byu.net>
parents: 10318
diff changeset
203 #include <stdio.h>
a34661f8b5c8 test-lock, test-tls: mention why a test is skipped
Eric Blake <ebb9@byu.net>
parents: 10318
diff changeset
204
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
205 int
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206 main ()
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207 {
10461
709b75aa9001 Tweak skip message.
Bruno Haible <bruno@clisp.org>
parents: 10353
diff changeset
208 fputs ("Skipping test: multithreading not enabled\n", stderr);
6115
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 return 77;
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
210 }
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
211
07b6ec9ac71f Tests for module 'tls'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
212 #endif