Skip to content

Commit

Permalink
unified: Rationalize thread priority APIs
Browse files Browse the repository at this point in the history
* Gets rid of k_current_priority_get(). Users can just call
  k_thread_priority_get(k_current_get()) instead.

* Declares k_thread_priority_get() in kernel.h, where it
  really belongs.

* Removes duplicate declaration of k_thread_priority_set().

Change-Id: I616ae6f2e06c95ecba3b92324186b3fa29162fd1
Signed-off-by: Allan Stephens <[email protected]>
  • Loading branch information
ajstephens authored and wrsPeterMitsis committed Oct 13, 2016
1 parent b039550 commit 399d0ad
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 26 deletions.
3 changes: 1 addition & 2 deletions include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ extern void k_busy_wait(uint32_t usec_to_wait);
extern void k_yield(void);
extern void k_wakeup(k_tid_t thread);
extern k_tid_t k_current_get(void);
extern int k_current_priority_get(void);
extern int k_thread_cancel(k_tid_t thread);

extern void k_thread_abort(k_tid_t thread);
Expand Down Expand Up @@ -201,7 +200,7 @@ struct _static_thread_data {
K_THREAD_INITIALIZER(_k_thread_obj_##name, stack_size, \
entry, p1, p2, p3, abort, prio, groups)

/* extern int k_thread_prio_get(k_tid_t thread); in sched.h */
extern int k_thread_priority_get(k_tid_t thread);
extern void k_thread_priority_set(k_tid_t thread, int prio);

extern void k_thread_suspend(k_tid_t thread);
Expand Down
3 changes: 2 additions & 1 deletion include/legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ static inline void fiber_sleep(int32_t timeout)
extern int task_offload_to_fiber(int (*func)(), void *argp);

#define task_id_get k_current_get
#define task_priority_get (kpriority_t)k_current_priority_get
#define task_priority_get() \
(kpriority_t)(k_thread_priority_get(k_current_get()))
#define task_abort k_thread_abort
#define task_suspend k_thread_suspend
#define task_resume k_thread_resume
Expand Down
13 changes: 0 additions & 13 deletions kernel/unified/include/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ extern void _pend_current_thread(_wait_q_t *wait_q, int32_t timeout);
extern void _move_thread_to_end_of_prio_q(struct k_thread *thread);
extern struct k_thread *_get_next_ready_thread(void);
extern int __must_switch_threads(void);
extern void k_thread_priority_set(struct k_thread *thread, int32_t priority);
extern int k_current_priority_get(void);
extern int32_t _ms_to_ticks(int32_t ms);

/*
Expand Down Expand Up @@ -294,17 +292,6 @@ static inline void _mark_thread_as_dead(struct k_thread *thread)
thread->flags |= K_DEAD;
}

/*
* Application API.
*
* Get a thread's priority. Note that it might have changed by the time this
* function returns.
*/
static inline int32_t k_thread_priority_get(struct k_thread *thread)
{
return thread->prio;
}

/*
* Set a thread's priority. If the thread is ready, place it in the correct
* queue.
Expand Down
2 changes: 1 addition & 1 deletion kernel/unified/pipes.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ void k_pipe_block_put(struct k_pipe *pipe, struct k_mem_block *block,
async_desc->desc.block = &async_desc->desc.copy_block;
async_desc->desc.copy_block = *block;
async_desc->desc.sem = sem;
async_desc->thread.prio = k_current_priority_get();
async_desc->thread.prio = k_thread_priority_get(_current);

(void) _k_pipe_put_internal(pipe, async_desc, block->data,
block->req_size, &dummy_bytes_written,
Expand Down
12 changes: 6 additions & 6 deletions kernel/unified/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ int _is_next_thread_current(void)
return _get_next_ready_thread() == _current;
}

/* application API: get a thread's priority */
int k_thread_priority_get(k_tid_t thread)
{
return thread->prio;
}

/* application API: change a thread's priority. Not callable from ISR */
void k_thread_priority_set(struct k_thread *thread, int prio)
{
Expand All @@ -226,12 +232,6 @@ void k_thread_priority_set(struct k_thread *thread, int prio)
_reschedule_threads(key);
}

/* application API: find out the priority of the current thread */
int k_current_priority_get(void)
{
return k_thread_priority_get(_current);
}

/*
* Interrupts must be locked when calling this function.
*
Expand Down
4 changes: 1 addition & 3 deletions samples/philosophers/unified/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@

#define fork(x) (forks[x])

extern int k_current_priority_get(void);

static void set_phil_state_pos(int id)
{
#if !DEBUG_PRINTF
Expand All @@ -126,7 +124,7 @@ static void set_phil_state_pos(int id)
#include <stdarg.h>
static void print_phil_state(int id, const char *fmt, int32_t delay)
{
int prio = k_current_priority_get();
int prio = k_thread_priority_get(k_current_get());

set_phil_state_pos(id);

Expand Down

0 comments on commit 399d0ad

Please sign in to comment.