21
21
22
22
RT_DEFINE_HW_SPINLOCK (pth_lock );
23
23
_pthread_data_t * pth_table [PTHREAD_NUM_MAX ] = {NULL };
24
- static int concurrency_level ;
24
+ static int concurrency_level ;
25
25
26
26
_pthread_data_t * _pthread_get_data (pthread_t thread )
27
27
{
@@ -43,7 +43,7 @@ pthread_t _pthread_data_get_pth(_pthread_data_t *ptd)
43
43
int index ;
44
44
45
45
rt_hw_spin_lock (& pth_lock );
46
- for (index = 0 ; index < PTHREAD_NUM_MAX ; index ++ )
46
+ for (index = 0 ; index < PTHREAD_NUM_MAX ; index ++ )
47
47
{
48
48
if (pth_table [index ] == ptd ) break ;
49
49
}
@@ -54,20 +54,20 @@ pthread_t _pthread_data_get_pth(_pthread_data_t *ptd)
54
54
55
55
pthread_t _pthread_data_create (void )
56
56
{
57
- int index ;
57
+ int index ;
58
58
_pthread_data_t * ptd = NULL ;
59
59
60
- ptd = (_pthread_data_t * )rt_malloc (sizeof (_pthread_data_t ));
60
+ ptd = (_pthread_data_t * )rt_malloc (sizeof (_pthread_data_t ));
61
61
if (!ptd ) return PTHREAD_NUM_MAX ;
62
62
63
63
memset (ptd , 0x0 , sizeof (_pthread_data_t ));
64
- ptd -> canceled = 0 ;
64
+ ptd -> canceled = 0 ;
65
65
ptd -> cancelstate = PTHREAD_CANCEL_DISABLE ;
66
- ptd -> canceltype = PTHREAD_CANCEL_DEFERRED ;
67
- ptd -> magic = PTHREAD_MAGIC ;
66
+ ptd -> canceltype = PTHREAD_CANCEL_DEFERRED ;
67
+ ptd -> magic = PTHREAD_MAGIC ;
68
68
69
69
rt_hw_spin_lock (& pth_lock );
70
- for (index = 0 ; index < PTHREAD_NUM_MAX ; index ++ )
70
+ for (index = 0 ; index < PTHREAD_NUM_MAX ; index ++ )
71
71
{
72
72
if (pth_table [index ] == NULL )
73
73
{
@@ -90,7 +90,7 @@ pthread_t _pthread_data_create(void)
90
90
static inline void _destroy_item (int index , _pthread_data_t * ptd )
91
91
{
92
92
extern _pthread_key_data_t _thread_keys [PTHREAD_KEY_MAX ];
93
- void * data ;
93
+ void * data ;
94
94
95
95
if (_thread_keys [index ].is_used )
96
96
{
@@ -103,7 +103,7 @@ static inline void _destroy_item(int index, _pthread_data_t *ptd)
103
103
}
104
104
105
105
#ifdef RT_USING_CPLUSPLUS11
106
- #define NOT_USE_CXX_TLS -1
106
+ #define NOT_USE_CXX_TLS -1
107
107
#endif
108
108
109
109
void _pthread_data_destroy (_pthread_data_t * ptd )
@@ -123,16 +123,16 @@ void _pthread_data_destroy(_pthread_data_t *ptd)
123
123
* destructors of C++ object must be called safely.
124
124
*/
125
125
extern pthread_key_t emutls_get_pthread_key (void );
126
- pthread_key_t emutls_pthread_key = emutls_get_pthread_key ();
126
+ pthread_key_t emutls_pthread_key = emutls_get_pthread_key ();
127
127
128
128
if (emutls_pthread_key != NOT_USE_CXX_TLS )
129
129
{
130
130
/* If execution reaches here, C++ 'thread_local' may be used.
131
131
* Destructors of c++ class object must be called before emutls_key_destructor.
132
132
*/
133
133
int start = ((emutls_pthread_key - 1 + PTHREAD_KEY_MAX ) % PTHREAD_KEY_MAX );
134
- int i = 0 ;
135
- for (index = start ; i < PTHREAD_KEY_MAX ; index = (index - 1 + PTHREAD_KEY_MAX ) % PTHREAD_KEY_MAX , i ++ )
134
+ int i = 0 ;
135
+ for (index = start ; i < PTHREAD_KEY_MAX ; index = (index - 1 + PTHREAD_KEY_MAX ) % PTHREAD_KEY_MAX , i ++ )
136
136
{
137
137
_destroy_item (index , ptd );
138
138
}
@@ -143,7 +143,7 @@ void _pthread_data_destroy(_pthread_data_t *ptd)
143
143
/* If only C TLS is used, that is, POSIX TLS or __Thread_local,
144
144
* just iterate the _thread_keys from index 0.
145
145
*/
146
- for (index = 0 ; index < PTHREAD_KEY_MAX ; index ++ )
146
+ for (index = 0 ; index < PTHREAD_KEY_MAX ; index ++ )
147
147
{
148
148
_destroy_item (index , ptd );
149
149
}
@@ -153,7 +153,7 @@ void _pthread_data_destroy(_pthread_data_t *ptd)
153
153
ptd -> tls = RT_NULL ;
154
154
}
155
155
156
- pth = _pthread_data_get_pth (ptd );
156
+ pth = _pthread_data_get_pth (ptd );
157
157
/* remove from pthread table */
158
158
rt_hw_spin_lock (& pth_lock );
159
159
pth_table [pth ] = NULL ;
@@ -191,7 +191,7 @@ static void _pthread_cleanup(rt_thread_t tid)
191
191
192
192
static void pthread_entry_stub (void * parameter )
193
193
{
194
- void * value ;
194
+ void * value ;
195
195
_pthread_data_t * ptd ;
196
196
197
197
ptd = (_pthread_data_t * )parameter ;
@@ -253,12 +253,12 @@ int pthread_create(pthread_t *pid,
253
253
const pthread_attr_t * attr ,
254
254
void * (* start )(void * ), void * parameter )
255
255
{
256
- int ret = 0 ;
257
- void * stack ;
258
- char name [RT_NAME_MAX ];
256
+ int ret = 0 ;
257
+ void * stack ;
258
+ char name [RT_NAME_MAX ];
259
259
static rt_uint16_t pthread_number = 0 ;
260
260
261
- pthread_t pth_id ;
261
+ pthread_t pth_id ;
262
262
_pthread_data_t * ptd ;
263
263
264
264
/* pid shall be provided */
@@ -292,10 +292,10 @@ int pthread_create(pthread_t *pid,
292
292
goto __exit ;
293
293
}
294
294
295
- rt_snprintf (name , sizeof (name ), "pth%02d" , pthread_number ++ );
295
+ rt_snprintf (name , sizeof (name ), "pth%02d" , pthread_number ++ );
296
296
297
297
/* pthread is a static thread object */
298
- ptd -> tid = (rt_thread_t ) rt_malloc (sizeof (struct rt_thread ));
298
+ ptd -> tid = (rt_thread_t )rt_malloc (sizeof (struct rt_thread ));
299
299
if (ptd -> tid == RT_NULL )
300
300
{
301
301
ret = ENOMEM ;
@@ -318,7 +318,7 @@ int pthread_create(pthread_t *pid,
318
318
}
319
319
320
320
/* set parameter */
321
- ptd -> thread_entry = start ;
321
+ ptd -> thread_entry = start ;
322
322
ptd -> thread_parameter = parameter ;
323
323
324
324
/* stack */
@@ -340,7 +340,8 @@ int pthread_create(pthread_t *pid,
340
340
/* initial this pthread to system */
341
341
if (rt_thread_init (ptd -> tid , name , pthread_entry_stub , ptd ,
342
342
stack , ptd -> attr .stacksize ,
343
- ptd -> attr .schedparam .sched_priority , 20 ) != RT_EOK )
343
+ ptd -> attr .schedparam .sched_priority , 20 )
344
+ != RT_EOK )
344
345
{
345
346
ret = EINVAL ;
346
347
goto __exit ;
@@ -350,7 +351,7 @@ int pthread_create(pthread_t *pid,
350
351
* pid = pth_id ;
351
352
352
353
/* set pthread cleanup function and ptd data */
353
- ptd -> tid -> cleanup = _pthread_cleanup ;
354
+ ptd -> tid -> cleanup = _pthread_cleanup ;
354
355
ptd -> tid -> pthread_data = (void * )ptd ;
355
356
356
357
/* start thread */
@@ -394,7 +395,7 @@ RTM_EXPORT(pthread_create);
394
395
*/
395
396
int pthread_detach (pthread_t thread )
396
397
{
397
- int ret = 0 ;
398
+ int ret = 0 ;
398
399
_pthread_data_t * ptd = _pthread_get_data (thread );
399
400
if (ptd == RT_NULL )
400
401
{
@@ -466,7 +467,7 @@ RTM_EXPORT(pthread_detach);
466
467
int pthread_join (pthread_t thread , void * * value_ptr )
467
468
{
468
469
_pthread_data_t * ptd ;
469
- rt_err_t result ;
470
+ rt_err_t result ;
470
471
471
472
ptd = _pthread_get_data (thread );
472
473
@@ -524,9 +525,9 @@ RTM_EXPORT(pthread_join);
524
525
*
525
526
* @see pthread_create, pthread_equal, pthread_join
526
527
*/
527
- pthread_t pthread_self (void )
528
+ pthread_t pthread_self (void )
528
529
{
529
- rt_thread_t tid ;
530
+ rt_thread_t tid ;
530
531
_pthread_data_t * ptd ;
531
532
532
533
tid = rt_thread_self ();
@@ -568,7 +569,7 @@ RTM_EXPORT(pthread_self);
568
569
*/
569
570
int pthread_getcpuclockid (pthread_t thread , clockid_t * clock_id )
570
571
{
571
- if (_pthread_get_data (thread ) == NULL )
572
+ if (_pthread_get_data (thread ) == NULL )
572
573
{
573
574
return EINVAL ;
574
575
}
@@ -777,10 +778,10 @@ RTM_EXPORT(pthread_setschedparam);
777
778
*/
778
779
int pthread_setschedprio (pthread_t thread , int prio )
779
780
{
780
- _pthread_data_t * ptd ;
781
+ _pthread_data_t * ptd ;
781
782
struct sched_param param ;
782
783
783
- ptd = _pthread_get_data (thread );
784
+ ptd = _pthread_get_data (thread );
784
785
param .sched_priority = prio ;
785
786
pthread_attr_setschedparam (& ptd -> attr , & param );
786
787
@@ -808,9 +809,9 @@ RTM_EXPORT(pthread_setschedprio);
808
809
*/
809
810
void pthread_exit (void * value )
810
811
{
811
- _pthread_data_t * ptd ;
812
+ _pthread_data_t * ptd ;
812
813
_pthread_cleanup_t * cleanup ;
813
- rt_thread_t tid ;
814
+ rt_thread_t tid ;
814
815
815
816
if (rt_thread_self () == RT_NULL )
816
817
{
@@ -833,7 +834,7 @@ void pthread_exit(void *value)
833
834
*/
834
835
while (ptd -> cleanup != RT_NULL )
835
836
{
836
- cleanup = ptd -> cleanup ;
837
+ cleanup = ptd -> cleanup ;
837
838
ptd -> cleanup = cleanup -> next ;
838
839
839
840
cleanup -> cleanup_func (cleanup -> parameter );
@@ -956,7 +957,7 @@ int pthread_kill(pthread_t thread, int sig)
956
957
{
957
958
#ifdef RT_USING_SIGNALS
958
959
_pthread_data_t * ptd ;
959
- int ret ;
960
+ int ret ;
960
961
961
962
ptd = _pthread_get_data (thread );
962
963
if (ptd )
@@ -1036,7 +1037,7 @@ int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset)
1036
1037
*/
1037
1038
void pthread_cleanup_pop (int execute )
1038
1039
{
1039
- _pthread_data_t * ptd ;
1040
+ _pthread_data_t * ptd ;
1040
1041
_pthread_cleanup_t * cleanup ;
1041
1042
1042
1043
if (rt_thread_self () == NULL ) return ;
@@ -1092,7 +1093,7 @@ RTM_EXPORT(pthread_cleanup_pop);
1092
1093
*/
1093
1094
void pthread_cleanup_push (void (* routine )(void * ), void * arg )
1094
1095
{
1095
- _pthread_data_t * ptd ;
1096
+ _pthread_data_t * ptd ;
1096
1097
_pthread_cleanup_t * cleanup ;
1097
1098
1098
1099
if (rt_thread_self () == NULL ) return ;
@@ -1105,11 +1106,11 @@ void pthread_cleanup_push(void (*routine)(void *), void *arg)
1105
1106
if (cleanup != RT_NULL )
1106
1107
{
1107
1108
cleanup -> cleanup_func = routine ;
1108
- cleanup -> parameter = arg ;
1109
+ cleanup -> parameter = arg ;
1109
1110
1110
1111
rt_enter_critical ();
1111
1112
cleanup -> next = ptd -> cleanup ;
1112
- ptd -> cleanup = cleanup ;
1113
+ ptd -> cleanup = cleanup ;
1113
1114
rt_exit_critical ();
1114
1115
}
1115
1116
}
@@ -1261,7 +1262,7 @@ RTM_EXPORT(pthread_setcanceltype);
1261
1262
*/
1262
1263
void pthread_testcancel (void )
1263
1264
{
1264
- int cancel = 0 ;
1265
+ int cancel = 0 ;
1265
1266
_pthread_data_t * ptd ;
1266
1267
1267
1268
if (rt_thread_self () == NULL ) return ;
@@ -1303,9 +1304,9 @@ RTM_EXPORT(pthread_testcancel);
1303
1304
*/
1304
1305
int pthread_cancel (pthread_t thread )
1305
1306
{
1306
- _pthread_data_t * ptd ;
1307
+ _pthread_data_t * ptd ;
1307
1308
_pthread_cleanup_t * cleanup ;
1308
- rt_thread_t tid ;
1309
+ rt_thread_t tid ;
1309
1310
1310
1311
/* get posix thread data */
1311
1312
ptd = _pthread_get_data (thread );
@@ -1331,7 +1332,7 @@ int pthread_cancel(pthread_t thread)
1331
1332
*/
1332
1333
while (ptd -> cleanup != RT_NULL )
1333
1334
{
1334
- cleanup = ptd -> cleanup ;
1335
+ cleanup = ptd -> cleanup ;
1335
1336
ptd -> cleanup = cleanup -> next ;
1336
1337
1337
1338
cleanup -> cleanup_func (cleanup -> parameter );
0 commit comments