diff options
Diffstat (limited to 'firmware/export')
-rw-r--r-- | firmware/export/kernel.h | 2 | ||||
-rw-r--r-- | firmware/export/thread.h | 38 |
2 files changed, 25 insertions, 15 deletions
diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h index beba58eb21..ef65463e5d 100644 --- a/firmware/export/kernel.h +++ b/firmware/export/kernel.h | |||
@@ -261,7 +261,7 @@ extern void queue_post(struct event_queue *q, long id, intptr_t data); | |||
261 | #ifdef HAVE_EXTENDED_MESSAGING_AND_NAME | 261 | #ifdef HAVE_EXTENDED_MESSAGING_AND_NAME |
262 | extern void queue_enable_queue_send(struct event_queue *q, | 262 | extern void queue_enable_queue_send(struct event_queue *q, |
263 | struct queue_sender_list *send, | 263 | struct queue_sender_list *send, |
264 | struct thread_entry *owner); | 264 | unsigned int owner_id); |
265 | extern intptr_t queue_send(struct event_queue *q, long id, intptr_t data); | 265 | extern intptr_t queue_send(struct event_queue *q, long id, intptr_t data); |
266 | extern void queue_reply(struct event_queue *q, intptr_t retval); | 266 | extern void queue_reply(struct event_queue *q, intptr_t retval); |
267 | extern bool queue_in_queue_send(struct event_queue *q); | 267 | extern bool queue_in_queue_send(struct event_queue *q); |
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); |