indent sources

fix style before adding more code
This commit is contained in:
Moritz Bitsch 2015-03-25 21:16:49 +01:00
parent b62135d7a0
commit c3d1cef5e7
4 changed files with 42 additions and 55 deletions

35
coio.c
View file

@ -24,21 +24,17 @@ coio_main()
coio_del(&coio_ready, coio_current);
coro_transfer(&_sched_ctx, &coio_current->ctx);
if (coio_current->done)
{
if (coio_current->done) {
_taskcount--;
coro_stack_free(&coio_current->stk);
free(coio_current);
}
coio_current = NULL;
}
if (_taskcount)
{
if (_taskcount) {
return -1;
}
return 0;
}
@ -54,7 +50,7 @@ _coio_entry(void *arg)
}
int
coio_create(void (*f)(void *arg), void *arg, unsigned int stacksize)
coio_create(coio_func f, void *arg, unsigned int stacksize)
{
CoioTask *task;
@ -62,12 +58,10 @@ coio_create(void (*f)(void *arg), void *arg, unsigned int stacksize)
if (!task)
return -1;
if(!coro_stack_alloc(&task->stk, stacksize / sizeof(void *)))
{
if (!coro_stack_alloc(&task->stk, stacksize / sizeof(void *))) {
free(task);
return -1;
}
task->func = f;
task->arg = arg;
@ -89,13 +83,10 @@ coio_yield()
void
coio_add(CoioTaskList * lst, CoioTask * task)
{
if (lst->tail)
{
if (lst->tail) {
lst->tail->next = task;
task->prev = lst->tail;
}
else
{
} else {
lst->head = task;
task->prev = NULL;
}
@ -106,21 +97,15 @@ coio_add(CoioTaskList *lst, CoioTask *task)
void
coio_del(CoioTaskList * lst, CoioTask * task)
{
if (task->prev)
{
if (task->prev) {
task->prev->next = task->next;
}
else
{
} else {
lst->head = task->next;
}
if (task->next)
{
if (task->next) {
task->next->prev = task->prev;
}
else
{
} else {
lst->tail = task->prev;
}
}

1
coio.h
View file

@ -6,6 +6,7 @@ extern "C" {
#endif
typedef struct CoioTask CoioTask;
typedef void (*coio_func) (void *arg);
int coio_main ();
int coio_create(void (*f) (void *arg), void *arg, unsigned int stacksize);

View file

@ -10,7 +10,7 @@ struct CoioTask {
coro_context ctx;
struct coro_stack stk;
coro_func func;
coio_func func;
void *arg;
int done;

View file

@ -1,21 +1,24 @@
#include <stdio.h>
#include "coio.h"
void _t1(void *arg)
void
_t1(void *arg)
{
printf("Hello 1 from _t1\n");
coio_yield();
printf("Hello 2 from _t1\n");
}
void _t2(void *arg)
void
_t2(void *arg)
{
printf("Hello 1 from _t2\n");
coio_yield();
printf("Hello 2 from _t2\n");
}
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -23,11 +26,9 @@ int main(int argc, char **argv)
coio_create(_t1, NULL, 0x8000);
coio_create(_t2, NULL, 0x8000);
if (coio_main() < 0)
{
if (coio_main() < 0) {
printf("Deadlocked\n");
return 1;
}
return 0;
}