flint: prepare for redesign

This commit is contained in:
Dmitry Simonenko 2016-11-24 15:45:43 +03:00
parent 6247c1d81d
commit 661acfedca
5 changed files with 175 additions and 0 deletions

54
machinarium/machinarium.h Normal file
View File

@ -0,0 +1,54 @@
#ifndef MACHINARIUM_H_
#define MACHINARIUM_H_
/*
* machinarium.
*
* Cooperative multitasking engine.
*/
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#if __GNUC__ >= 4
# define MM_API __attribute__((visibility("default")))
#else
# define MM_API
#endif
typedef void (*mmfunction_t)(void *arg);
typedef void* mm_t;
typedef void* mmio_t;
MM_API mm_t
mm_new(void);
MM_API int mm_free(mm_t);
MM_API int64_t mm_create(mm_t, mmfunction_t, void *arg);
MM_API int mm_is_online(mm_t);
MM_API int mm_is_cancel(mm_t);
MM_API void mm_start(mm_t);
MM_API void mm_stop(mm_t);
MM_API void mm_sleep(mm_t, uint64_t time_ms);
MM_API int mm_wait(mm_t, uint64_t id);
MM_API int mm_cancel(mm_t, uint64_t id);
MM_API mmio_t
mm_io_new(mm_t);
MM_API void mm_close(mmio_t);
MM_API int mm_fd(mmio_t);
MM_API int mm_is_connected(mmio_t);
MM_API int mm_connect(mmio_t, char *addr, int port, uint64_t time_ms);
MM_API int mm_connect_is_timeout(mmio_t);
MM_API int mm_bind(mmio_t, char *addr, int port);
MM_API int mm_accept(mmio_t, mmio_t *client);
MM_API int mm_read(mmio_t, int size, uint64_t time_ms);
MM_API int mm_read_is_timeout(mmio_t);
MM_API char *mm_read_buf(mmio_t);
MM_API int mm_write(mmio_t, char *buf, int size, uint64_t time_ms);
MM_API int mm_write_is_timeout(mmio_t);
#endif

View File

@ -0,0 +1,30 @@
#ifndef MM_PRIVATE_H_
#define MM_PRIVATE_H_
/*
* machinarium.
*
* Cooperative multitasking engine.
*/
#define _GNU_SOURCE 1
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
#include <unistd.h>
#include <ucontext.h>
#include <uv.h>
#include "mm_macro.h"
#include "mm_list.h"
#include "mm_buf.h"
#include "mm_context.h"
#endif

17
machinarium/makefile Normal file
View File

@ -0,0 +1,17 @@
# libmachinarium makefile.
#
CC = gcc
AR = ar
RM = rm
CFLAGS = -I. -Wall -g -O0 -pedantic
OBJECTS = mm_context.o \
mm_fiber.o \
mm_scheduler.o \
mm.o
LIB = libmachinarium.a
$(LIB): clean $(OBJECTS)
$(AR) cr $(LIB) $(OBJECTS)
.c.o:
$(CC) $(CFLAGS) -c $<
clean:
$(RM) -f $(OBJECTS) $(LIB)

61
machinarium/mm_list.h Normal file
View File

@ -0,0 +1,61 @@
#ifndef MM_LIST_H_
#define MM_LIST_H_
/*
* machinarium.
*
* Cooperative multitasking engine.
*/
typedef struct mmlist mmlist;
struct mmlist {
mmlist *next, *prev;
};
static inline void
mm_listinit(mmlist *h)
{
h->next = h->prev = h;
}
static inline void
mm_listappend(mmlist *h, mmlist *n)
{
n->next = h;
n->prev = h->prev;
n->prev->next = n;
n->next->prev = n;
}
static inline void
mm_listunlink(mmlist *n)
{
n->prev->next = n->next;
n->next->prev = n->prev;
}
static inline void
mm_listpush(mmlist *h, mmlist *n)
{
n->next = h->next;
n->prev = h;
n->prev->next = n;
n->next->prev = n;
}
static inline mmlist*
mm_listpop(mmlist *h)
{
register mmlist *pop = h->next;
mm_listunlink(pop);
return pop;
}
#define mm_listforeach(H, I) \
for (I = (H)->next; I != H; I = (I)->next)
#define mm_listforeach_safe(H, I, N) \
for (I = (H)->next; I != H && (N = I->next); I = N)
#endif

13
machinarium/mm_macro.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef MM_MACRO_H_
#define MM_MACRO_H_
/*
* machinarium.
*
* Cooperative multitasking engine.
*/
#define mm_container_of(ptr, t, f) \
((t*)((char*)(ptr) - __builtin_offsetof(t, f)))
#endif