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.com/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/system.h> |
---|
27 | #include <rtems/posix/pthreadimpl.h> |
---|
28 | #include <rtems/score/thread.h> |
---|
29 | |
---|
30 | int pthread_equal( |
---|
31 | pthread_t t1, |
---|
32 | pthread_t t2 |
---|
33 | ) |
---|
34 | { |
---|
35 | /* |
---|
36 | * If the system is configured for debug, then we will do everything we |
---|
37 | * can to insure that both ids are valid. Otherwise, we will do the |
---|
38 | * cheapest possible thing to determine if they are equal. |
---|
39 | */ |
---|
40 | |
---|
41 | #ifndef RTEMS_DEBUG |
---|
42 | return _Objects_Are_ids_equal( t1, t2 ); |
---|
43 | #else |
---|
44 | int status; |
---|
45 | Objects_Locations location; |
---|
46 | Thread_Control *thread_1; |
---|
47 | Thread_Control *thread_2; |
---|
48 | |
---|
49 | /* |
---|
50 | * By default this is not a match. |
---|
51 | */ |
---|
52 | |
---|
53 | status = 0; |
---|
54 | |
---|
55 | /* |
---|
56 | * Validate the first id and return 0 if it is not valid |
---|
57 | */ |
---|
58 | |
---|
59 | thread_1 = _Thread_Get( t1, &location ); |
---|
60 | switch ( location ) { |
---|
61 | |
---|
62 | case OBJECTS_LOCAL: |
---|
63 | |
---|
64 | /* |
---|
65 | * Validate the second id and return 0 if it is not valid |
---|
66 | */ |
---|
67 | |
---|
68 | thread_2 = _Thread_Get( t2, &location ); |
---|
69 | switch ( location ) { |
---|
70 | |
---|
71 | case OBJECTS_LOCAL: |
---|
72 | status = _Objects_Are_ids_equal( t1, t2 ); |
---|
73 | _Objects_Put_without_thread_dispatch( &thread_2->Object ); |
---|
74 | _Objects_Put( &thread_1->Object ); |
---|
75 | break; |
---|
76 | |
---|
77 | case OBJECTS_ERROR: |
---|
78 | #if defined(RTEMS_MULTIPROCESSING) |
---|
79 | case OBJECTS_REMOTE: |
---|
80 | #endif |
---|
81 | /* t1 must have been valid so exit the critical section */ |
---|
82 | _Objects_Put( &thread_1->Object ); |
---|
83 | /* return status == 0 */ |
---|
84 | break; |
---|
85 | } |
---|
86 | break; |
---|
87 | |
---|
88 | #if defined(RTEMS_MULTIPROCESSING) |
---|
89 | case OBJECTS_REMOTE: |
---|
90 | #endif |
---|
91 | case OBJECTS_ERROR: |
---|
92 | /* return status == 0 */ |
---|
93 | break; |
---|
94 | } |
---|
95 | |
---|
96 | return status; |
---|
97 | #endif |
---|
98 | } |
---|