Mercurial > ecos
comparison packages/kernel/current/src/common/kapi.cxx @ 546:bd1ddaaaf796
* src/common/kapi.cxx (cyg_thread_get_next): Be quite zealous about
checking the validity of passed in threads in debug mode.
(cyg_thread_get_info): Ditto.
| author | jlarmour |
|---|---|
| date | Tue, 28 Jan 2003 05:07:01 +0000 |
| parents | a65a4055f146 |
| children | 6b4a1f23fbbb |
comparison
equal
deleted
inserted
replaced
| 545:70b861ba8f8c | 546:bd1ddaaaf796 |
|---|---|
| 8 //####ECOSGPLCOPYRIGHTBEGIN#### | 8 //####ECOSGPLCOPYRIGHTBEGIN#### |
| 9 // ------------------------------------------- | 9 // ------------------------------------------- |
| 10 // This file is part of eCos, the Embedded Configurable Operating System. | 10 // This file is part of eCos, the Embedded Configurable Operating System. |
| 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. | 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
| 12 // Copyright (C) 2002 Nick Garnett | 12 // Copyright (C) 2002 Nick Garnett |
| 13 // Copyright (C) 2003 Jonathan Larmour | |
| 13 // | 14 // |
| 14 // eCos is free software; you can redistribute it and/or modify it under | 15 // eCos is free software; you can redistribute it and/or modify it under |
| 15 // the terms of the GNU General Public License as published by the Free | 16 // the terms of the GNU General Public License as published by the Free |
| 16 // Software Foundation; either version 2 or (at your option) any later version. | 17 // Software Foundation; either version 2 or (at your option) any later version. |
| 17 // | 18 // |
| 315 #ifdef CYGVAR_KERNEL_THREADS_LIST | 316 #ifdef CYGVAR_KERNEL_THREADS_LIST |
| 316 | 317 |
| 317 cyg_bool_t cyg_thread_get_next( cyg_handle_t *current, cyg_uint16 *id ) | 318 cyg_bool_t cyg_thread_get_next( cyg_handle_t *current, cyg_uint16 *id ) |
| 318 { | 319 { |
| 319 cyg_bool_t result = true; | 320 cyg_bool_t result = true; |
| 320 | 321 |
| 322 // There is a minute but finite chance that the thread could have | |
| 323 // exitted since the previous cyg_thread_get_next() call, and we can't | |
| 324 // detect the ID mismatch further down. So be quite zealous with checking. | |
| 325 | |
| 326 CYG_CHECK_DATA_PTRC( current ); | |
| 327 CYG_CHECK_DATA_PTRC( id ); | |
| 328 if ( *current != 0 ) | |
| 329 CYG_CHECK_DATA_PTRC( *current ); | |
| 330 | |
| 321 Cyg_Scheduler::lock(); | 331 Cyg_Scheduler::lock(); |
| 322 | 332 |
| 323 Cyg_Thread *thread = (Cyg_Thread *)*current; | 333 Cyg_Thread *thread = (Cyg_Thread *)*current; |
| 324 | 334 CYG_ASSERT_CLASSC( thread ); |
| 325 if( *current == 0 ) | 335 if( *current == 0 ) |
| 326 { | 336 { |
| 327 thread = Cyg_Thread::get_list_head(); | 337 thread = Cyg_Thread::get_list_head(); |
| 328 *current = (cyg_handle_t)thread; | 338 *current = (cyg_handle_t)thread; |
| 329 *id = thread->get_unique_id(); | 339 *id = thread->get_unique_id(); |
| 330 } | 340 } |
| 331 else if( (thread->get_unique_id() == *id) && | 341 else if( (thread->get_unique_id() == *id) && |
| 332 (thread = thread->get_list_next()) != NULL ) | 342 (thread = thread->get_list_next()) != NULL ) |
| 333 { | 343 { |
| 344 CYG_CHECK_DATA_PTRC( thread ); | |
| 345 CYG_ASSERT_CLASSC( thread ); | |
| 334 *current = (cyg_handle_t)thread; | 346 *current = (cyg_handle_t)thread; |
| 335 *id = thread->get_unique_id(); | 347 *id = thread->get_unique_id(); |
| 336 } | 348 } |
| 337 else | 349 else |
| 338 { | 350 { |
| 371 cyg_uint16 id, | 383 cyg_uint16 id, |
| 372 cyg_thread_info *info ) | 384 cyg_thread_info *info ) |
| 373 { | 385 { |
| 374 cyg_bool_t result = true; | 386 cyg_bool_t result = true; |
| 375 Cyg_Thread *thread = (Cyg_Thread *)threadh; | 387 Cyg_Thread *thread = (Cyg_Thread *)threadh; |
| 388 CYG_CHECK_DATA_PTRC( thread ); | |
| 389 if ( NULL != info ) | |
| 390 CYG_CHECK_DATA_PTRC( info ); | |
| 376 | 391 |
| 377 Cyg_Scheduler::lock(); | 392 Cyg_Scheduler::lock(); |
| 378 | 393 |
| 379 if( thread->get_unique_id() == id && info != NULL ) | 394 if( thread->get_unique_id() == id && info != NULL ) |
| 380 { | 395 { |
| 396 CYG_ASSERT_CLASSC( thread ); | |
| 381 info->handle = threadh; | 397 info->handle = threadh; |
| 382 info->id = id; | 398 info->id = id; |
| 383 info->state = thread->get_state(); | 399 info->state = thread->get_state(); |
| 384 #ifdef CYGVAR_KERNEL_THREADS_NAME | 400 #ifdef CYGVAR_KERNEL_THREADS_NAME |
| 385 info->name = thread->get_name(); | 401 info->name = thread->get_name(); |
