Skip to content

Commit 977f78d

Browse files
committed
Code refactoring for tst_thread_get_num(): use asserts
1 parent cc91782 commit 977f78d

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

tst_threads.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -235,28 +235,20 @@ int tst_thread_cleanup (struct tst_thread_env_t ** thread_env)
235235
return 0;
236236
}
237237

238-
/*
239-
* Returns the thread ID of the current thread
238+
/** \brief Return thread ID of the current thread
239+
*
240+
* \return Success: thread ID, Fail: -1
240241
*/
241-
inline int tst_thread_get_num (void)
242-
{
242+
inline int tst_thread_get_num() {
243+
assert(num_threads > 0);
244+
assert(NULL != tst_thread_tid_array);
243245
int i = 0;
244246
pthread_t self = pthread_self();
245-
tst_output_printf (DEBUG_LOG, TST_REPORT_MAX, "Searching for thread_id %p\n", self);
246-
247-
if (NULL == tst_thread_tid_array) {
248-
return 0;
249-
}
250247
for (i = 0; i <= num_threads; i++) {
251-
tst_output_printf (DEBUG_LOG, TST_REPORT_MAX, "Comparing with thread_id %p ....", tst_thread_tid_array[i]);
252-
if ( pthread_equal (tst_thread_tid_array[i], self) ) {
253-
tst_output_printf (DEBUG_LOG, TST_REPORT_MAX, "Found :-) Return %d\n", i);
254-
return i;
255-
}
256-
else
257-
tst_output_printf (DEBUG_LOG, TST_REPORT_MAX, "Not equal\n");
248+
if (pthread_equal(tst_thread_tid_array[i], self)) {
249+
return i;
250+
}
258251
}
259-
ERROR (EINVAL, "Thread ID could not be determined");
260252
return -1;
261253
}
262254

0 commit comments

Comments
 (0)