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

41
coio.c
View file

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

9
coio.h
View file

@ -5,11 +5,12 @@
extern "C" { extern "C" {
#endif #endif
typedef struct CoioTask CoioTask; typedef struct CoioTask CoioTask;
typedef void (*coio_func) (void *arg);
int coio_main(); int coio_main ();
int coio_create(void (*f)(void *arg), void *arg, unsigned int stacksize); int coio_create(void (*f) (void *arg), void *arg, unsigned int stacksize);
void coio_yield(); void coio_yield();
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -10,7 +10,7 @@ struct CoioTask {
coro_context ctx; coro_context ctx;
struct coro_stack stk; struct coro_stack stk;
coro_func func; coio_func func;
void *arg; void *arg;
int done; int done;
@ -25,7 +25,7 @@ struct CoioTaskList {
CoioTask *tail; CoioTask *tail;
}; };
void coio_add(CoioTaskList *lst, CoioTask *task); void coio_add (CoioTaskList * lst, CoioTask * task);
void coio_del(CoioTaskList *lst, CoioTask *task); void coio_del (CoioTaskList * lst, CoioTask * task);
#endif #endif

View file

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