Skip to content

Commit 8cab081

Browse files
shintaro-iwasakihppritcha
authored andcommitted
test/class: fix opal_fifo and opal_lifo
Signed-off-by: Shintaro Iwasaki <[email protected]>
1 parent ee35174 commit 8cab081

File tree

4 files changed

+43
-39
lines changed

4 files changed

+43
-39
lines changed

opal/mca/threads/argobots/threads_argobots_module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct opal_tsd_key_value {
4040
};
4141

4242
static ABT_thread opal_main_thread;
43-
struct opal_tsd_key_value *opal_tsd_key_values = NULL;
43+
static struct opal_tsd_key_value *opal_tsd_key_values = NULL;
4444
static int opal_tsd_key_values_count = 0;
4545

4646
/*

opal/mca/threads/pthreads/threads_pthreads_module.c

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@
3232
#include "opal/mca/threads/threads.h"
3333
#include "opal/mca/threads/tsd.h"
3434

35+
static pthread_t opal_main_thread;
36+
3537
struct opal_tsd_key_value {
3638
opal_tsd_key_t key;
3739
opal_tsd_destructor_t destructor;
3840
};
3941

40-
static pthread_t opal_main_thread;
41-
struct opal_tsd_key_value *opal_tsd_key_values = NULL;
42+
static struct opal_tsd_key_value *opal_tsd_key_values = NULL;
4243
static int opal_tsd_key_values_count = 0;
4344

4445
/*
@@ -54,17 +55,19 @@ OBJ_CLASS_INSTANCE(opal_thread_t,
5455
opal_object_t,
5556
opal_thread_construct, NULL);
5657

57-
58-
opal_thread_t *opal_thread_get_self(void)
58+
int opal_thread_start(opal_thread_t *t)
5959
{
60-
opal_thread_t *t = OBJ_NEW(opal_thread_t);
61-
t->t_handle = pthread_self();
62-
return t;
63-
}
60+
int rc;
6461

65-
bool opal_thread_self_compare(opal_thread_t *t)
66-
{
67-
return pthread_self() == t->t_handle;
62+
if (OPAL_ENABLE_DEBUG) {
63+
if (NULL == t->t_run || (pthread_t)-1 != t->t_handle) {
64+
return OPAL_ERR_BAD_PARAM;
65+
}
66+
}
67+
68+
rc = pthread_create(&t->t_handle, NULL, (void *(*)(void *))t->t_run, t);
69+
70+
return 0 == rc ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
6871
}
6972

7073
int opal_thread_join(opal_thread_t *t, void **thr_return)
@@ -74,28 +77,18 @@ int opal_thread_join(opal_thread_t *t, void **thr_return)
7477
return 0 == rc ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
7578
}
7679

77-
void opal_thread_set_main(void)
80+
bool opal_thread_self_compare(opal_thread_t *t)
7881
{
79-
opal_main_thread = pthread_self();
82+
return pthread_self() == t->t_handle;
8083
}
8184

82-
int opal_thread_start(opal_thread_t *t)
85+
opal_thread_t *opal_thread_get_self(void)
8386
{
84-
int rc;
85-
86-
if (OPAL_ENABLE_DEBUG) {
87-
if (NULL == t->t_run || (pthread_t)-1 != t->t_handle) {
88-
return OPAL_ERR_BAD_PARAM;
89-
}
90-
}
91-
92-
rc = pthread_create(&t->t_handle, NULL, (void *(*)(void *))t->t_run, t);
93-
94-
return 0 == rc ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
87+
opal_thread_t *t = OBJ_NEW(opal_thread_t);
88+
t->t_handle = pthread_self();
89+
return t;
9590
}
9691

97-
OBJ_CLASS_DECLARATION(opal_thread_t);
98-
9992
int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor)
10093
{
10194
int rc;
@@ -131,6 +124,11 @@ int opal_tsd_keys_destruct(void)
131124
return OPAL_SUCCESS;
132125
}
133126

127+
void opal_thread_set_main(void)
128+
{
129+
opal_main_thread = pthread_self();
130+
}
131+
134132
void opal_event_use_threads(void)
135133
{
136134
evthread_use_pthreads();

test/class/opal_fifo.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@
4242
} while (0)
4343
#endif
4444

45-
static void *thread_test (opal_thread_t *arg) {
46-
opal_fifo_t *fifo = (opal_fifo_t *) arg->t_arg;
45+
static void *thread_test (opal_object_t *arg) {
46+
opal_thread_t *t = (opal_thread_t *) arg;
47+
opal_fifo_t *fifo = (opal_fifo_t *) t->t_arg;
4748
opal_list_item_t *item;
4849
struct timeval start, stop, total;
4950
double timing;
@@ -67,8 +68,9 @@ static void *thread_test (opal_thread_t *arg) {
6768
return NULL;
6869
}
6970

70-
static void *thread_test_exhaust (opal_thread_t *arg) {
71-
opal_fifo_t *fifo = (opal_fifo_t *) arg->t_arg;
71+
static void *thread_test_exhaust (opal_object_t *arg) {
72+
opal_thread_t *t = (opal_thread_t *) arg;
73+
opal_fifo_t *fifo = (opal_fifo_t *) t->t_arg;
7274
opal_list_item_t *items[ITEMS_PER_LOOP];
7375
struct timeval start, stop, total;
7476
int item_count = 0;
@@ -184,7 +186,7 @@ int main (int argc, char *argv[]) {
184186
(int)total.tv_usec, (int)(timing / 1e-9));
185187

186188
threads[0].t_arg = &fifo;
187-
thread_test (&threads[0]);
189+
thread_test ((opal_object_t *) &threads[0]);
188190

189191
if (check_fifo_consistency (&fifo, ITEM_COUNT)) {
190192
test_success ();
@@ -194,7 +196,8 @@ int main (int argc, char *argv[]) {
194196

195197
gettimeofday (&start, NULL);
196198
for (int i = 0 ; i < OPAL_FIFO_TEST_THREAD_COUNT ; ++i) {
197-
threads[i].t_run = (opal_thread_fn_t) thread_test;
199+
OBJ_CONSTRUCT(&threads[i], opal_thread_t);
200+
threads[i].t_run = thread_test;
198201
threads[i].t_arg = &fifo;
199202
opal_thread_start (threads + i);
200203
}
@@ -222,7 +225,8 @@ int main (int argc, char *argv[]) {
222225

223226
gettimeofday (&start, NULL);
224227
for (int i = 0 ; i < OPAL_FIFO_TEST_THREAD_COUNT ; ++i) {
225-
threads[i].t_run = (opal_thread_fn_t) thread_test_exhaust;
228+
OBJ_CONSTRUCT(&threads[i], opal_thread_t);
229+
threads[i].t_run = thread_test_exhaust;
226230
threads[i].t_arg = &fifo;
227231
opal_thread_start (threads + i);
228232
}

test/class/opal_lifo.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
} while (0)
4040
#endif
4141

42-
static void *thread_test (opal_thread_t *arg) {
43-
opal_lifo_t *lifo = (opal_lifo_t *) arg->t_arg;
42+
static void *thread_test (opal_object_t *arg) {
43+
opal_thread_t *t = (opal_thread_t *) arg;
44+
opal_lifo_t *lifo = (opal_lifo_t *) t->t_arg;
4445
opal_list_item_t *item;
4546
struct timeval start, stop, total;
4647
double timing;
@@ -145,7 +146,7 @@ int main (int argc, char *argv[]) {
145146
(int)total.tv_usec, (int)(timing / 1e-9));
146147

147148
threads[0].t_arg = &lifo;
148-
thread_test (&threads[0]);
149+
thread_test ((opal_object_t *) &threads[0]);
149150

150151
if (check_lifo_consistency (&lifo, ITEM_COUNT)) {
151152
test_success ();
@@ -155,7 +156,8 @@ int main (int argc, char *argv[]) {
155156

156157
gettimeofday (&start, NULL);
157158
for (int i = 0 ; i < OPAL_LIFO_TEST_THREAD_COUNT ; ++i) {
158-
threads[i].t_run = (opal_thread_fn_t) thread_test;
159+
OBJ_CONSTRUCT(&threads[i], opal_thread_t);
160+
threads[i].t_run = thread_test;
159161
threads[i].t_arg = &lifo;
160162
opal_thread_start (threads + i);
161163
}

0 commit comments

Comments
 (0)