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

49
coio.c
View file

@ -6,8 +6,8 @@
static coro_context _sched_ctx;
static unsigned long _taskcount = 0;
CoioTaskList coio_ready = {0, 0};
CoioTask *coio_current;
CoioTaskList coio_ready = {0, 0};
CoioTask *coio_current;
int
coio_main()
@ -24,28 +24,24 @@ 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;
}
static void
_coio_entry(void *arg)
{
CoioTask *task = (CoioTask *)arg;
CoioTask *task = (CoioTask *) arg;
task->func(task->arg);
@ -54,20 +50,18 @@ _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;
CoioTask *task;
task = calloc(1, sizeof(*task));
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;
@ -87,40 +81,31 @@ coio_yield()
}
void
coio_add(CoioTaskList *lst, CoioTask *task)
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;
}
lst->tail = task;
task->next = NULL;
task->next = NULL;
}
void
coio_del(CoioTaskList *lst, CoioTask *task)
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;
}
}

11
coio.h
View file

@ -2,14 +2,15 @@
#define COIO_H
#ifdef __cplusplus
extern "C" {
extern "C" {
#endif
typedef struct CoioTask CoioTask;
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);
void coio_yield();
int coio_main ();
int coio_create(void (*f) (void *arg), void *arg, unsigned int stacksize);
void coio_yield();
#ifdef __cplusplus
}

View file

@ -7,25 +7,25 @@
typedef struct CoioTaskList CoioTaskList;
struct CoioTask {
coro_context ctx;
coro_context ctx;
struct coro_stack stk;
coro_func func;
void *arg;
coio_func func;
void *arg;
int done;
int done;
/* linked list support */
CoioTask *next;
CoioTask *prev;
CoioTask *next;
CoioTask *prev;
};
struct CoioTaskList {
CoioTask *head;
CoioTask *tail;
CoioTask *head;
CoioTask *tail;
};
void coio_add(CoioTaskList *lst, CoioTask *task);
void coio_del(CoioTaskList *lst, CoioTask *task);
void coio_add (CoioTaskList * lst, CoioTask * task);
void coio_del (CoioTaskList * lst, CoioTask * task);
#endif

View file

@ -1,33 +1,34 @@
#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;
(void) argc;
(void) 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;
}