1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Compare Thread IDs |
---|
5 | * @ingroup POSIXAPI |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * NOTE: POSIX does not define the behavior when either thread id is invalid. |
---|
10 | * |
---|
11 | * COPYRIGHT (c) 1989-2007. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #if HAVE_CONFIG_H |
---|
20 | #include "config.h" |
---|
21 | #endif |
---|
22 | |
---|
23 | #include <pthread.h> |
---|
24 | #include <errno.h> |
---|
25 | |
---|
26 | #include <rtems/posix/pthreadimpl.h> |
---|
27 | #include <rtems/score/threadimpl.h> |
---|
28 | |
---|
29 | int pthread_equal( |
---|
30 | pthread_t t1, |
---|
31 | pthread_t t2 |
---|
32 | ) |
---|
33 | { |
---|
34 | /* |
---|
35 | * If the system is configured for debug, then we will do everything we |
---|
36 | * can to insure that both ids are valid. Otherwise, we will do the |
---|
37 | * cheapest possible thing to determine if they are equal. |
---|
38 | */ |
---|
39 | |
---|
40 | #ifndef RTEMS_DEBUG |
---|
41 | return _Objects_Are_ids_equal( t1, t2 ); |
---|
42 | #else |
---|
43 | ISR_lock_Context lock_context_1; |
---|
44 | ISR_lock_Context lock_context_2; |
---|
45 | Thread_Control *thread_1; |
---|
46 | Thread_Control *thread_2; |
---|
47 | |
---|
48 | thread_1 = _Thread_Get( t1, &lock_context_1 ); |
---|
49 | thread_2 = _Thread_Get( t2, &lock_context_2 ); |
---|
50 | |
---|
51 | if ( thread_2 != NULL ) { |
---|
52 | _ISR_lock_ISR_enable( &lock_context_2 ); |
---|
53 | } |
---|
54 | |
---|
55 | if ( thread_1 != NULL ) { |
---|
56 | _ISR_lock_ISR_enable( &lock_context_1 ); |
---|
57 | } |
---|
58 | |
---|
59 | return thread_1 != NULL && thread_1 == thread_2; |
---|
60 | #endif |
---|
61 | } |
---|