Merge pull request #2627 from mcharleb/posix_whitespace_fixes

POSIX: code format changes
This commit is contained in:
Lorenz Meier
2015-08-01 16:44:13 +02:00
14 changed files with 410 additions and 429 deletions
+4 -6
View File
@@ -56,18 +56,16 @@
* *
************************************************************/ ************************************************************/
void dq_addlast(FAR dq_entry_t *node, dq_queue_t *queue) void dq_addlast(dq_entry_t *node, dq_queue_t *queue)
{ {
node->flink = NULL; node->flink = NULL;
node->blink = queue->tail; node->blink = queue->tail;
if (!queue->head) if (!queue->head) {
{
queue->head = node; queue->head = node;
queue->tail = node; queue->tail = node;
}
else } else {
{
queue->tail->flink = node; queue->tail->flink = node;
queue->tail = node; queue->tail = node;
} }
+9 -13
View File
@@ -56,26 +56,22 @@
* *
************************************************************/ ************************************************************/
void dq_rem(FAR dq_entry_t *node, dq_queue_t *queue) void dq_rem(dq_entry_t *node, dq_queue_t *queue)
{ {
FAR dq_entry_t *prev = node->blink; dq_entry_t *prev = node->blink;
FAR dq_entry_t *next = node->flink; dq_entry_t *next = node->flink;
if (!prev) if (!prev) {
{
queue->head = next; queue->head = next;
}
else } else {
{
prev->flink = next; prev->flink = next;
} }
if (!next) if (!next) {
{
queue->tail = prev; queue->tail = prev;
}
else } else {
{
next->blink = prev; next->blink = prev;
} }
+8 -10
View File
@@ -56,20 +56,18 @@
* *
************************************************************/ ************************************************************/
FAR dq_entry_t *dq_remfirst(dq_queue_t *queue) dq_entry_t *dq_remfirst(dq_queue_t *queue)
{ {
FAR dq_entry_t *ret = queue->head; dq_entry_t *ret = queue->head;
if (ret) if (ret) {
{ dq_entry_t *next = ret->flink;
FAR dq_entry_t *next = ret->flink;
if (!next) if (!next) {
{
queue->head = NULL; queue->head = NULL;
queue->tail = NULL; queue->tail = NULL;
}
else } else {
{
queue->head = next; queue->head = next;
next->blink = NULL; next->blink = NULL;
} }
+18 -19
View File
@@ -90,9 +90,9 @@ static void hrt_work_process(void);
static void hrt_work_process() static void hrt_work_process()
{ {
struct wqueue_s *wqueue = &g_hrt_work; struct wqueue_s *wqueue = &g_hrt_work;
volatile FAR struct work_s *work; volatile struct work_s *work;
worker_t worker; worker_t worker;
FAR void *arg; void *arg;
uint64_t elapsed; uint64_t elapsed;
uint32_t remaining; uint32_t remaining;
uint32_t next; uint32_t next;
@@ -106,9 +106,9 @@ static void hrt_work_process()
hrt_work_lock(); hrt_work_lock();
work = (FAR struct work_s *)wqueue->q.head; work = (struct work_s *)wqueue->q.head;
while (work)
{ while (work) {
/* Is this work ready? It is ready if there is no delay or if /* Is this work ready? It is ready if there is no delay or if
* the delay has elapsed. qtime is the time that the work was added * the delay has elapsed. qtime is the time that the work was added
* to the work queue. It will always be greater than or equal to * to the work queue. It will always be greater than or equal to
@@ -116,9 +116,9 @@ static void hrt_work_process()
*/ */
elapsed = hrt_absolute_time() - work->qtime; elapsed = hrt_absolute_time() - work->qtime;
//PX4_INFO("hrt work_process: in usec elapsed=%lu delay=%u work=%p", elapsed, work->delay, work); //PX4_INFO("hrt work_process: in usec elapsed=%lu delay=%u work=%p", elapsed, work->delay, work);
if (elapsed >= work->delay) if (elapsed >= work->delay) {
{
/* Remove the ready-to-execute work from the list */ /* Remove the ready-to-execute work from the list */
(void)dq_rem((struct dq_entry_s *)work, &wqueue->q); (void)dq_rem((struct dq_entry_s *)work, &wqueue->q);
@@ -140,10 +140,11 @@ static void hrt_work_process()
*/ */
hrt_work_unlock(); hrt_work_unlock();
if (!worker) { if (!worker) {
PX4_ERR("MESSED UP: worker = 0"); PX4_ERR("MESSED UP: worker = 0");
}
else { } else {
worker(arg); worker(arg);
} }
@@ -153,19 +154,18 @@ static void hrt_work_process()
*/ */
hrt_work_lock(); hrt_work_lock();
work = (FAR struct work_s *)wqueue->q.head; work = (struct work_s *)wqueue->q.head;
}
else } else {
{
/* This one is not ready.. will it be ready before the next /* This one is not ready.. will it be ready before the next
* scheduled wakeup interval? * scheduled wakeup interval?
*/ */
/* Here: elapsed < work->delay */ /* Here: elapsed < work->delay */
remaining = work->delay - elapsed; remaining = work->delay - elapsed;
//PX4_INFO("remaining=%u delay=%u elapsed=%lu", remaining, work->delay, elapsed); //PX4_INFO("remaining=%u delay=%u elapsed=%lu", remaining, work->delay, elapsed);
if (remaining < next) if (remaining < next) {
{
/* Yes.. Then schedule to wake up when the work is ready */ /* Yes.. Then schedule to wake up when the work is ready */
next = remaining; next = remaining;
@@ -173,7 +173,7 @@ static void hrt_work_process()
/* Then try the next in the list. */ /* Then try the next in the list. */
work = (FAR struct work_s *)work->dq.flink; work = (struct work_s *)work->dq.flink;
//PX4_INFO("next %u work %p", next, work); //PX4_INFO("next %u work %p", next, work);
} }
} }
@@ -217,8 +217,7 @@ static int work_hrtthread(int argc, char *argv[])
{ {
/* Loop forever */ /* Loop forever */
for (;;) for (;;) {
{
/* First, perform garbage collection. This cleans-up memory de-allocations /* First, perform garbage collection. This cleans-up memory de-allocations
* that were queued because they could not be freed in that execution * that were queued because they could not be freed in that execution
* context (for example, if the memory was freed from an interrupt handler). * context (for example, if the memory was freed from an interrupt handler).
@@ -250,7 +249,7 @@ void hrt_work_queue_init(void)
SCHED_PRIORITY_MAX, SCHED_PRIORITY_MAX,
2000, 2000,
work_hrtthread, work_hrtthread,
(char* const*)NULL); (char *const *)NULL);
} }
@@ -92,18 +92,18 @@ void hrt_work_cancel(struct work_s *work)
*/ */
hrt_work_lock(); hrt_work_lock();
if (work->worker != NULL)
{ if (work->worker != NULL) {
/* A little test of the integrity of the work queue */ /* A little test of the integrity of the work queue */
//DEBUGASSERT(work->dq.flink ||(FAR dq_entry_t *)work == wqueue->q.tail); //DEBUGASSERT(work->dq.flink ||(dq_entry_t *)work == wqueue->q.tail);
//DEBUGASSERT(work->dq.blink ||(FAR dq_entry_t *)work == wqueue->q.head); //DEBUGASSERT(work->dq.blink ||(dq_entry_t *)work == wqueue->q.head);
/* Remove the entry from the work queue and make sure that it is /* Remove the entry from the work queue and make sure that it is
* mark as availalbe (i.e., the worker field is nullified). * mark as availalbe (i.e., the worker field is nullified).
*/ */
dq_rem((FAR dq_entry_t *)work, &wqueue->q); dq_rem((dq_entry_t *)work, &wqueue->q);
work->worker = NULL; work->worker = NULL;
} }
+17 -21
View File
@@ -42,25 +42,22 @@ __EXPORT void sq_rem(sq_entry_t *node, sq_queue_t *queue);
sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue); sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue);
void sq_rem(sq_entry_t *node, sq_queue_t *queue) void sq_rem(sq_entry_t *node, sq_queue_t *queue)
{ {
if (queue->head && node) if (queue->head && node) {
{ if (node == queue->head) {
if (node == queue->head)
{
queue->head = node->flink; queue->head = node->flink;
if (node == queue->tail)
{ if (node == queue->tail) {
queue->tail = NULL; queue->tail = NULL;
} }
}
else } else {
{
sq_entry_t *prev; sq_entry_t *prev;
for(prev = (sq_entry_t*)queue->head;
for (prev = (sq_entry_t *)queue->head;
prev && prev->flink != node; prev && prev->flink != node;
prev = prev->flink); prev = prev->flink);
if (prev) if (prev) {
{
sq_remafter(prev, queue); sq_remafter(prev, queue);
} }
} }
@@ -70,15 +67,13 @@ void sq_rem(sq_entry_t *node, sq_queue_t *queue)
sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue) sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue)
{ {
sq_entry_t *ret = node->flink; sq_entry_t *ret = node->flink;
if (queue->head && ret)
{ if (queue->head && ret) {
if (queue->tail == ret) if (queue->tail == ret) {
{
queue->tail = node; queue->tail = node;
node->flink = NULL; node->flink = NULL;
}
else } else {
{
node->flink = ret->flink; node->flink = ret->flink;
} }
@@ -92,10 +87,11 @@ __EXPORT void sq_addfirst(sq_entry_t *node, sq_queue_t *queue);
void sq_addfirst(sq_entry_t *node, sq_queue_t *queue) void sq_addfirst(sq_entry_t *node, sq_queue_t *queue)
{ {
node->flink = queue->head; node->flink = queue->head;
if (!queue->head)
{ if (!queue->head) {
queue->tail = node; queue->tail = node;
} }
queue->head = node; queue->head = node;
} }
+4 -6
View File
@@ -56,15 +56,13 @@
* *
************************************************************/ ************************************************************/
void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node, void sq_addafter(sq_entry_t *prev, sq_entry_t *node,
sq_queue_t *queue) sq_queue_t *queue)
{ {
if (!queue->head || prev == queue->tail) if (!queue->head || prev == queue->tail) {
{
sq_addlast(node, queue); sq_addlast(node, queue);
}
else } else {
{
node->flink = prev->flink; node->flink = prev->flink;
prev->flink = node; prev->flink = node;
} }
+5 -6
View File
@@ -56,16 +56,15 @@
* the 'queue' * the 'queue'
************************************************************/ ************************************************************/
void sq_addlast(FAR sq_entry_t *node, sq_queue_t *queue) void sq_addlast(sq_entry_t *node, sq_queue_t *queue)
{ {
node->flink = NULL; node->flink = NULL;
if (!queue->head)
{ if (!queue->head) {
queue->head = node; queue->head = node;
queue->tail = node; queue->tail = node;
}
else } else {
{
queue->tail->flink = node; queue->tail->flink = node;
queue->tail = node; queue->tail = node;
} }
+5 -6
View File
@@ -57,15 +57,14 @@
* *
************************************************************/ ************************************************************/
FAR sq_entry_t *sq_remfirst(sq_queue_t *queue) sq_entry_t *sq_remfirst(sq_queue_t *queue)
{ {
FAR sq_entry_t *ret = queue->head; sq_entry_t *ret = queue->head;
if (ret) if (ret) {
{
queue->head = ret->flink; queue->head = ret->flink;
if (!queue->head)
{ if (!queue->head) {
queue->tail = NULL; queue->tail = NULL;
} }
+5 -5
View File
@@ -98,18 +98,18 @@ int work_cancel(int qid, struct work_s *work)
*/ */
work_lock(qid); work_lock(qid);
if (work->worker != NULL)
{ if (work->worker != NULL) {
/* A little test of the integrity of the work queue */ /* A little test of the integrity of the work queue */
//DEBUGASSERT(work->dq.flink ||(FAR dq_entry_t *)work == wqueue->q.tail); //DEBUGASSERT(work->dq.flink ||(dq_entry_t *)work == wqueue->q.tail);
//DEBUGASSERT(work->dq.blink ||(FAR dq_entry_t *)work == wqueue->q.head); //DEBUGASSERT(work->dq.blink ||(dq_entry_t *)work == wqueue->q.head);
/* Remove the entry from the work queue and make sure that it is /* Remove the entry from the work queue and make sure that it is
* mark as availalbe (i.e., the worker field is nullified). * mark as availalbe (i.e., the worker field is nullified).
*/ */
dq_rem((FAR dq_entry_t *)work, &wqueue->q); dq_rem((dq_entry_t *)work, &wqueue->q);
work->worker = NULL; work->worker = NULL;
} }
+25 -27
View File
@@ -88,11 +88,11 @@ sem_t _work_lock[NWORKERS];
* *
****************************************************************************/ ****************************************************************************/
static void work_process(FAR struct wqueue_s *wqueue, int lock_id) static void work_process(struct wqueue_s *wqueue, int lock_id)
{ {
volatile FAR struct work_s *work; volatile struct work_s *work;
worker_t worker; worker_t worker;
FAR void *arg; void *arg;
uint64_t elapsed; uint64_t elapsed;
uint32_t remaining; uint32_t remaining;
uint32_t next; uint32_t next;
@@ -105,9 +105,9 @@ static void work_process(FAR struct wqueue_s *wqueue, int lock_id)
work_lock(lock_id); work_lock(lock_id);
work = (FAR struct work_s *)wqueue->q.head; work = (struct work_s *)wqueue->q.head;
while (work)
{ while (work) {
/* Is this work ready? It is ready if there is no delay or if /* Is this work ready? It is ready if there is no delay or if
* the delay has elapsed. qtime is the time that the work was added * the delay has elapsed. qtime is the time that the work was added
* to the work queue. It will always be greater than or equal to * to the work queue. It will always be greater than or equal to
@@ -115,9 +115,9 @@ static void work_process(FAR struct wqueue_s *wqueue, int lock_id)
*/ */
elapsed = USEC2TICK(clock_systimer() - work->qtime); elapsed = USEC2TICK(clock_systimer() - work->qtime);
//printf("work_process: in ticks elapsed=%lu delay=%u\n", elapsed, work->delay); //printf("work_process: in ticks elapsed=%lu delay=%u\n", elapsed, work->delay);
if (elapsed >= work->delay) if (elapsed >= work->delay) {
{
/* Remove the ready-to-execute work from the list */ /* Remove the ready-to-execute work from the list */
(void)dq_rem((struct dq_entry_s *)work, &wqueue->q); (void)dq_rem((struct dq_entry_s *)work, &wqueue->q);
@@ -138,11 +138,13 @@ static void work_process(FAR struct wqueue_s *wqueue, int lock_id)
*/ */
work_unlock(lock_id); work_unlock(lock_id);
if (!worker) { if (!worker) {
PX4_WARN("MESSED UP: worker = 0\n"); PX4_WARN("MESSED UP: worker = 0\n");
}
else } else {
worker(arg); worker(arg);
}
/* Now, unfortunately, since we re-enabled interrupts we don't /* Now, unfortunately, since we re-enabled interrupts we don't
* know the state of the work list and we will have to start * know the state of the work list and we will have to start
@@ -150,18 +152,17 @@ static void work_process(FAR struct wqueue_s *wqueue, int lock_id)
*/ */
work_lock(lock_id); work_lock(lock_id);
work = (FAR struct work_s *)wqueue->q.head; work = (struct work_s *)wqueue->q.head;
}
else } else {
{
/* This one is not ready.. will it be ready before the next /* This one is not ready.. will it be ready before the next
* scheduled wakeup interval? * scheduled wakeup interval?
*/ */
/* Here: elapsed < work->delay */ /* Here: elapsed < work->delay */
remaining = USEC_PER_TICK*(work->delay - elapsed); remaining = USEC_PER_TICK * (work->delay - elapsed);
if (remaining < next)
{ if (remaining < next) {
/* Yes.. Then schedule to wake up when the work is ready */ /* Yes.. Then schedule to wake up when the work is ready */
next = remaining; next = remaining;
@@ -169,7 +170,7 @@ static void work_process(FAR struct wqueue_s *wqueue, int lock_id)
/* Then try the next in the list. */ /* Then try the next in the list. */
work = (FAR struct work_s *)work->dq.flink; work = (struct work_s *)work->dq.flink;
} }
} }
@@ -195,10 +196,10 @@ void work_queues_init(void)
// Create high priority worker thread // Create high priority worker thread
g_work[HPWORK].pid = px4_task_spawn_cmd("wkr_high", g_work[HPWORK].pid = px4_task_spawn_cmd("wkr_high",
SCHED_DEFAULT, SCHED_DEFAULT,
SCHED_PRIORITY_MAX-1, SCHED_PRIORITY_MAX - 1,
2000, 2000,
work_hpthread, work_hpthread,
(char* const*)NULL); (char *const *)NULL);
// Create low priority worker thread // Create low priority worker thread
g_work[LPWORK].pid = px4_task_spawn_cmd("wkr_low", g_work[LPWORK].pid = px4_task_spawn_cmd("wkr_low",
@@ -206,7 +207,7 @@ void work_queues_init(void)
SCHED_PRIORITY_MIN, SCHED_PRIORITY_MIN,
2000, 2000,
work_lpthread, work_lpthread,
(char* const*)NULL); (char *const *)NULL);
} }
@@ -247,8 +248,7 @@ int work_hpthread(int argc, char *argv[])
{ {
/* Loop forever */ /* Loop forever */
for (;;) for (;;) {
{
/* First, perform garbage collection. This cleans-up memory de-allocations /* First, perform garbage collection. This cleans-up memory de-allocations
* that were queued because they could not be freed in that execution * that were queued because they could not be freed in that execution
* context (for example, if the memory was freed from an interrupt handler). * context (for example, if the memory was freed from an interrupt handler).
@@ -276,8 +276,7 @@ int work_lpthread(int argc, char *argv[])
{ {
/* Loop forever */ /* Loop forever */
for (;;) for (;;) {
{
/* First, perform garbage collection. This cleans-up memory de-allocations /* First, perform garbage collection. This cleans-up memory de-allocations
* that were queued because they could not be freed in that execution * that were queued because they could not be freed in that execution
* context (for example, if the memory was freed from an interrupt handler). * context (for example, if the memory was freed from an interrupt handler).
@@ -306,8 +305,7 @@ int work_usrthread(int argc, char *argv[])
{ {
/* Loop forever */ /* Loop forever */
for (;;) for (;;) {
{
/* Then process queued work. We need to keep interrupts disabled while /* Then process queued work. We need to keep interrupts disabled while
* we process items in the work list. * we process items in the work list.
*/ */