Browse Source

Work queues: Move to POSIX semaphore abstraction

sbg
Lorenz Meier 10 years ago
parent
commit
d73deabf5c
  1. 9
      src/platforms/posix/include/hrt_work.h
  2. 4
      src/platforms/posix/work_queue/hrt_thread.c
  3. 10
      src/platforms/posix/work_queue/work_lock.c
  4. 8
      src/platforms/posix/work_queue/work_thread.c

9
src/platforms/posix/include/hrt_work.h

@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
****************************************************************************/
#include <px4_log.h>
#include <px4_posix.h>
#include <semaphore.h>
#include <px4_workqueue.h>
@ -39,7 +40,7 @@ @@ -39,7 +40,7 @@
__BEGIN_DECLS
extern sem_t _hrt_work_lock;
extern px4_sem_t _hrt_work_lock;
extern struct wqueue_s g_hrt_work;
void hrt_work_queue_init(void);
@ -49,15 +50,13 @@ void hrt_work_cancel(struct work_s *work); @@ -49,15 +50,13 @@ void hrt_work_cancel(struct work_s *work);
static inline void hrt_work_lock(void);
static inline void hrt_work_lock()
{
//PX4_INFO("hrt_work_lock");
sem_wait(&_hrt_work_lock);
px4_sem_wait(&_hrt_work_lock);
}
static inline void hrt_work_unlock(void);
static inline void hrt_work_unlock()
{
//PX4_INFO("hrt_work_unlock");
sem_post(&_hrt_work_lock);
px4_sem_post(&_hrt_work_lock);
}
__END_DECLS

4
src/platforms/posix/work_queue/hrt_thread.c

@ -66,7 +66,7 @@ struct wqueue_s g_hrt_work; @@ -66,7 +66,7 @@ struct wqueue_s g_hrt_work;
/****************************************************************************
* Private Variables
****************************************************************************/
sem_t _hrt_work_lock;
px4_sem_t _hrt_work_lock;
/****************************************************************************
* Private Functions
@ -241,7 +241,7 @@ static int work_hrtthread(int argc, char *argv[]) @@ -241,7 +241,7 @@ static int work_hrtthread(int argc, char *argv[])
void hrt_work_queue_init(void)
{
sem_init(&_hrt_work_lock, 0, 1);
px4_sem_init(&_hrt_work_lock, 0, 1);
// Create high priority worker thread
g_hrt_work.pid = px4_task_spawn_cmd("wkr_hrt",

10
src/platforms/posix/work_queue/work_lock.c

@ -31,21 +31,19 @@ @@ -31,21 +31,19 @@
*
****************************************************************************/
#include <px4_log.h>
#include <semaphore.h>
#include <px4_posix.h>
#include <stdio.h>
#include "work_lock.h"
extern sem_t _work_lock[];
extern px4_sem_t _work_lock[];
void work_lock(int id)
{
//PX4_INFO("work_lock %d", id);
sem_wait(&_work_lock[id]);
px4_sem_wait(&_work_lock[id]);
}
void work_unlock(int id)
{
//PX4_INFO("work_unlock %d", id);
sem_post(&_work_lock[id]);
px4_sem_post(&_work_lock[id]);
}

8
src/platforms/posix/work_queue/work_thread.c

@ -68,7 +68,7 @@ struct wqueue_s g_work[NWORKERS]; @@ -68,7 +68,7 @@ struct wqueue_s g_work[NWORKERS];
/****************************************************************************
* Private Variables
****************************************************************************/
sem_t _work_lock[NWORKERS];
px4_sem_t _work_lock[NWORKERS];
/****************************************************************************
* Private Functions
@ -187,10 +187,10 @@ static void work_process(struct wqueue_s *wqueue, int lock_id) @@ -187,10 +187,10 @@ static void work_process(struct wqueue_s *wqueue, int lock_id)
****************************************************************************/
void work_queues_init(void)
{
sem_init(&_work_lock[HPWORK], 0, 1);
sem_init(&_work_lock[LPWORK], 0, 1);
px4_sem_init(&_work_lock[HPWORK], 0, 1);
px4_sem_init(&_work_lock[LPWORK], 0, 1);
#ifdef CONFIG_SCHED_USRWORK
sem_init(&_work_lock[USRWORK], 0, 1);
px4_sem_init(&_work_lock[USRWORK], 0, 1);
#endif
// Create high priority worker thread

Loading…
Cancel
Save