diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2008-12-10 08:57:10 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2008-12-10 08:57:10 +0000 |
commit | 8cfbd3604fac14f629244e521ad24ffa9938c790 (patch) | |
tree | 16dc096519b8b537bb7d4b73e0c97f5f33ee752b /firmware/export/thread.h | |
parent | 40ff47c7eea41ac893d7af5c5b97ace52a5ffade (diff) | |
download | rockbox-8cfbd3604fac14f629244e521ad24ffa9938c790.tar.gz rockbox-8cfbd3604fac14f629244e521ad24ffa9938c790.zip |
Use cookies for thread identification instead of pointers directly which gives a buffer against wrongly identifying a thread when the slot is recycled (which has been nagging me for awhile). A slot gets 255 uses before it repeats. Everything gets incompatible so a full update is required.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19377 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/export/thread.h')
-rw-r--r-- | firmware/export/thread.h | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/firmware/export/thread.h b/firmware/export/thread.h index c4dfbf4ed3..4c1e952347 100644 --- a/firmware/export/thread.h +++ b/firmware/export/thread.h | |||
@@ -58,9 +58,6 @@ | |||
58 | #define NUM_PRIORITIES 32 | 58 | #define NUM_PRIORITIES 32 |
59 | #define PRIORITY_IDLE 32 /* Priority representative of no tasks */ | 59 | #define PRIORITY_IDLE 32 /* Priority representative of no tasks */ |
60 | 60 | ||
61 | /* TODO: Only a minor tweak to create_thread would be needed to let | ||
62 | * thread slots be caller allocated - no essential threading functionality | ||
63 | * depends upon an array */ | ||
64 | #if CONFIG_CODEC == SWCODEC | 61 | #if CONFIG_CODEC == SWCODEC |
65 | 62 | ||
66 | #ifdef HAVE_RECORDING | 63 | #ifdef HAVE_RECORDING |
@@ -280,6 +277,7 @@ struct thread_entry | |||
280 | int skip_count; /* Number of times skipped if higher priority | 277 | int skip_count; /* Number of times skipped if higher priority |
281 | thread was running */ | 278 | thread was running */ |
282 | #endif | 279 | #endif |
280 | uint16_t id; /* Current slot id */ | ||
283 | unsigned short stack_size; /* Size of stack in bytes */ | 281 | unsigned short stack_size; /* Size of stack in bytes */ |
284 | #ifdef HAVE_PRIORITY_SCHEDULING | 282 | #ifdef HAVE_PRIORITY_SCHEDULING |
285 | unsigned char base_priority; /* Base priority (set explicitly during | 283 | unsigned char base_priority; /* Base priority (set explicitly during |
@@ -298,6 +296,16 @@ struct thread_entry | |||
298 | #endif | 296 | #endif |
299 | }; | 297 | }; |
300 | 298 | ||
299 | /*** Macros for internal use ***/ | ||
300 | /* Thread ID, 16 bits = |VVVVVVVV|SSSSSSSS| */ | ||
301 | #define THREAD_ID_VERSION_SHIFT 8 | ||
302 | #define THREAD_ID_VERSION_MASK 0xff00 | ||
303 | #define THREAD_ID_SLOT_MASK 0x00ff | ||
304 | #define THREAD_ID_INIT(n) ((1u << THREAD_ID_VERSION_SHIFT) | (n)) | ||
305 | |||
306 | /* Specify current thread in a function taking an ID. */ | ||
307 | #define THREAD_ID_CURRENT ((unsigned int)-1) | ||
308 | |||
301 | #if NUM_CORES > 1 | 309 | #if NUM_CORES > 1 |
302 | /* Operations to be performed just before stopping a thread and starting | 310 | /* Operations to be performed just before stopping a thread and starting |
303 | a new one if specified before calling switch_thread */ | 311 | a new one if specified before calling switch_thread */ |
@@ -475,11 +483,11 @@ void init_threads(void); | |||
475 | 483 | ||
476 | /* Allocate a thread in the scheduler */ | 484 | /* Allocate a thread in the scheduler */ |
477 | #define CREATE_THREAD_FROZEN 0x00000001 /* Thread is frozen at create time */ | 485 | #define CREATE_THREAD_FROZEN 0x00000001 /* Thread is frozen at create time */ |
478 | struct thread_entry* | 486 | unsigned int create_thread(void (*function)(void), |
479 | create_thread(void (*function)(void), void* stack, size_t stack_size, | 487 | void* stack, size_t stack_size, |
480 | unsigned flags, const char *name | 488 | unsigned flags, const char *name |
481 | IF_PRIO(, int priority) | 489 | IF_PRIO(, int priority) |
482 | IF_COP(, unsigned int core)); | 490 | IF_COP(, unsigned int core)); |
483 | 491 | ||
484 | /* Set and clear the CPU frequency boost flag for the calling thread */ | 492 | /* Set and clear the CPU frequency boost flag for the calling thread */ |
485 | #ifdef HAVE_SCHEDULER_BOOSTCTRL | 493 | #ifdef HAVE_SCHEDULER_BOOSTCTRL |
@@ -489,17 +497,19 @@ void cancel_cpu_boost(void); | |||
489 | #define trigger_cpu_boost() | 497 | #define trigger_cpu_boost() |
490 | #define cancel_cpu_boost() | 498 | #define cancel_cpu_boost() |
491 | #endif | 499 | #endif |
500 | /* Return thread entry from id */ | ||
501 | struct thread_entry *thread_id_entry(unsigned int thread_id); | ||
492 | /* Make a frozed thread runnable (when started with CREATE_THREAD_FROZEN). | 502 | /* Make a frozed thread runnable (when started with CREATE_THREAD_FROZEN). |
493 | * Has no effect on a thread not frozen. */ | 503 | * Has no effect on a thread not frozen. */ |
494 | void thread_thaw(struct thread_entry *thread); | 504 | void thread_thaw(unsigned int thread_id); |
495 | /* Wait for a thread to exit */ | 505 | /* Wait for a thread to exit */ |
496 | void thread_wait(struct thread_entry *thread); | 506 | void thread_wait(unsigned int thread_id); |
497 | /* Exit the current thread */ | 507 | /* Exit the current thread */ |
498 | void thread_exit(void); | 508 | void thread_exit(void); |
499 | #if defined(DEBUG) || defined(ROCKBOX_HAS_LOGF) | 509 | #if defined(DEBUG) || defined(ROCKBOX_HAS_LOGF) |
500 | #define ALLOW_REMOVE_THREAD | 510 | #define ALLOW_REMOVE_THREAD |
501 | /* Remove a thread from the scheduler */ | 511 | /* Remove a thread from the scheduler */ |
502 | void remove_thread(struct thread_entry *thread); | 512 | void remove_thread(unsigned int thread_id); |
503 | #endif | 513 | #endif |
504 | 514 | ||
505 | /* Switch to next runnable thread */ | 515 | /* Switch to next runnable thread */ |
@@ -526,13 +536,13 @@ unsigned int thread_queue_wake(struct thread_entry **list); | |||
526 | unsigned int wakeup_thread(struct thread_entry **list); | 536 | unsigned int wakeup_thread(struct thread_entry **list); |
527 | 537 | ||
528 | #ifdef HAVE_PRIORITY_SCHEDULING | 538 | #ifdef HAVE_PRIORITY_SCHEDULING |
529 | int thread_set_priority(struct thread_entry *thread, int priority); | 539 | int thread_set_priority(unsigned int thread_id, int priority); |
530 | int thread_get_priority(struct thread_entry *thread); | 540 | int thread_get_priority(unsigned int thread_id); |
531 | #endif /* HAVE_PRIORITY_SCHEDULING */ | 541 | #endif /* HAVE_PRIORITY_SCHEDULING */ |
532 | #if NUM_CORES > 1 | 542 | #if NUM_CORES > 1 |
533 | unsigned int switch_core(unsigned int new_core); | 543 | unsigned int switch_core(unsigned int new_core); |
534 | #endif | 544 | #endif |
535 | struct thread_entry * thread_get_current(void); | 545 | unsigned int thread_get_current(void); |
536 | 546 | ||
537 | /* Debugging info - only! */ | 547 | /* Debugging info - only! */ |
538 | int thread_stack_usage(const struct thread_entry *thread); | 548 | int thread_stack_usage(const struct thread_entry *thread); |