Reformat code

run astyle --style=linux on source files
This commit is contained in:
Moritz Bitsch 2018-07-27 10:45:00 +02:00
parent c41a8ca6b4
commit c801b183dc
6 changed files with 42 additions and 46 deletions

36
coio.c
View file

@ -31,14 +31,14 @@
CoioTaskList coio_ready_list = {0, 0}; CoioTaskList coio_ready_list = {0, 0};
CoioTaskList coio_sleeping = {0, 0}; CoioTaskList coio_sleeping = {0, 0};
coro_context coio_sched_ctx; coro_context coio_sched_ctx;
CoioTask *coio_current; CoioTask* coio_current;
unsigned long coio_taskcount = 0; unsigned long coio_taskcount = 0;
static int msleep(uvlong ms) static int msleep(uvlong ms)
{ {
struct timespec req, rem; struct timespec req, rem;
if(ms > 999) { if (ms > 999) {
req.tv_sec = (int)(ms / 1000); req.tv_sec = (int)(ms / 1000);
req.tv_nsec = (ms - ((long)req.tv_sec * 1000)) * 1000000; req.tv_nsec = (ms - ((long)req.tv_sec * 1000)) * 1000000;
} else { } else {
@ -46,7 +46,7 @@ static int msleep(uvlong ms)
req.tv_nsec = ms * 1000000; req.tv_nsec = ms * 1000000;
} }
return nanosleep(&req , &rem); return nanosleep(&req, &rem);
} }
static void static void
@ -54,7 +54,7 @@ _process_events()
{ {
uvlong now; uvlong now;
int ms = 5; int ms = 5;
CoioTask *t; CoioTask* t;
if ((t = coio_sleeping.head) != NULL && t->timeout != 0) { if ((t = coio_sleeping.head) != NULL && t->timeout != 0) {
now = coio_now(); now = coio_now();
@ -111,9 +111,9 @@ coio_main()
} }
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);
@ -122,15 +122,15 @@ _coio_entry(void *arg)
} }
int int
coio_create(const char* name, coio_func f, void *arg, unsigned int stacksize) coio_create(const char* name, coio_func f, void* arg, unsigned int stacksize)
{ {
CoioTask *task; CoioTask* task;
task = calloc(1, sizeof(*task)); task = calloc(1, sizeof(*task));
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;
} }
@ -147,9 +147,9 @@ coio_create(const char* name, coio_func f, void *arg, unsigned int stacksize)
} }
uvlong uvlong
coio_timeout(CoioTask * task, int ms) coio_timeout(CoioTask* task, int ms)
{ {
CoioTask *t; CoioTask* t;
if (ms >= 0) { if (ms >= 0) {
task->timeout = coio_now() + (ms * 1000000); task->timeout = coio_now() + (ms * 1000000);
@ -201,7 +201,7 @@ 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;
@ -215,7 +215,7 @@ 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;
@ -231,7 +231,7 @@ coio_del(CoioTaskList * lst, CoioTask * task)
} }
void void
coio_ready(CoioTask * task) coio_ready(CoioTask* task)
{ {
task->timeout = 0; task->timeout = 0;
if (!task->ready) { if (!task->ready) {
@ -272,19 +272,17 @@ coio_now()
void void
coio_debug() coio_debug()
{ {
CoioTask *t; CoioTask* t;
fprintf(stderr, ">>>\nCurrent tasks: %s\n", coio_current->name); fprintf(stderr, ">>>\nCurrent tasks: %s\n", coio_current->name);
fprintf(stderr, "Sleeping tasks: "); fprintf(stderr, "Sleeping tasks: ");
for (t = coio_sleeping.head; t != NULL; t = t->next) for (t = coio_sleeping.head; t != NULL; t = t->next) {
{
fprintf(stderr, "%s ", t->name); fprintf(stderr, "%s ", t->name);
} }
fprintf(stderr, "\nReady tasks: "); fprintf(stderr, "\nReady tasks: ");
for (t = coio_ready_list.head; t != NULL; t = t->next) for (t = coio_ready_list.head; t != NULL; t = t->next) {
{
fprintf(stderr, "%s ", t->name); fprintf(stderr, "%s ", t->name);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");

20
coio.h
View file

@ -20,18 +20,18 @@
extern "C" { extern "C" {
#endif #endif
typedef struct CoioTask CoioTask; typedef struct CoioTask CoioTask;
typedef void (*coio_func) (void *arg); typedef void (*coio_func)(void* arg);
typedef unsigned long long uvlong; typedef unsigned long long uvlong;
extern CoioTask *coio_current; extern CoioTask* coio_current;
int coio_main (); int coio_main();
int coio_create(const char* name, coio_func f, void *arg, unsigned int stacksize); int coio_create(const char* name, coio_func f, void* arg, unsigned int stacksize);
void coio_yield(); void coio_yield();
uvlong coio_now(); uvlong coio_now();
int coio_delay(int ms); int coio_delay(int ms);
void coio_ready(CoioTask * task); void coio_ready(CoioTask* task);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -20,8 +20,7 @@
#include <glib.h> #include <glib.h>
struct coio_source struct coio_source {
{
GSource base; GSource base;
}; };
@ -116,8 +115,7 @@ GSource* coio_gsource_create()
{ {
coro_create(&coio_sched_ctx, NULL, NULL, NULL, 0); coro_create(&coio_sched_ctx, NULL, NULL, NULL, 0);
static GSourceFuncs funcs = static GSourceFuncs funcs = {
{
coio_source_prepare, coio_source_prepare,
coio_source_check, coio_source_check,
coio_source_dispatch, coio_source_dispatch,

View file

@ -25,22 +25,22 @@ struct CoioTask {
coro_context ctx; coro_context ctx;
struct coro_stack stk; struct coro_stack stk;
const char *name; const char* name;
coio_func func; coio_func func;
void *arg; void* arg;
uvlong timeout; uvlong timeout;
int ready; int ready;
int done; int done;
/* linked list support */ /* linked list support */
CoioTask *next; CoioTask* next;
CoioTask *prev; CoioTask* prev;
}; };
struct CoioTaskList { struct CoioTaskList {
CoioTask *head; CoioTask* head;
CoioTask *tail; CoioTask* tail;
}; };
extern CoioTaskList coio_ready_list; extern CoioTaskList coio_ready_list;
@ -48,8 +48,8 @@ extern CoioTaskList coio_sleeping;
extern coro_context coio_sched_ctx; extern coro_context coio_sched_ctx;
extern unsigned long coio_taskcount; extern unsigned long coio_taskcount;
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);
void coio_transfer(); void coio_transfer();
void coio_debug(); void coio_debug();

View file

@ -17,7 +17,7 @@
#include "coio.h" #include "coio.h"
void void
_t1(void *arg) _t1(void* arg)
{ {
printf("going to sleep 1000ms (1s)\n"); printf("going to sleep 1000ms (1s)\n");
coio_delay(1000); coio_delay(1000);
@ -25,7 +25,7 @@ _t1(void *arg)
} }
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
(void) argc; (void) argc;
(void) argv; (void) argv;

View file

@ -17,7 +17,7 @@
#include "coio.h" #include "coio.h"
void void
_t1(void *arg) _t1(void* arg)
{ {
printf("Hello 1 from _t1\n"); printf("Hello 1 from _t1\n");
coio_yield(); coio_yield();
@ -25,7 +25,7 @@ _t1(void *arg)
} }
void void
_t2(void *arg) _t2(void* arg)
{ {
printf("Hello 1 from _t2\n"); printf("Hello 1 from _t2\n");
coio_yield(); coio_yield();
@ -33,7 +33,7 @@ _t2(void *arg)
} }
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
(void) argc; (void) argc;
(void) argv; (void) argv;