1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

add little FSM to pool, web, api, queue to track state of initialisation

This commit is contained in:
Steffen Vogel 2017-03-06 13:26:23 -04:00
parent 7bb4e145fb
commit 429c07f1e3
8 changed files with 48 additions and 3 deletions

View file

@ -43,6 +43,11 @@ enum api_mode {
struct api {
struct list sessions; /**< List of currently active connections */
enum {
API_STATE_DESTROYED,
API_STATE_INITIALIZED
} state;
struct cfg *cfg;
};

View file

@ -19,6 +19,11 @@ struct pool {
void *buffer; /**< Address of the underlying memory area */
const struct memtype *mem;
enum {
POOL_STATE_DESTROYED,
POOL_STATE_INITIALIZED
} state;
size_t len; /**< Length of the underlying memory area */
size_t blocksz; /**< Length of a block in bytes */

View file

@ -43,6 +43,11 @@ typedef char cacheline_pad_t[CACHELINE_SIZE];
struct queue {
cacheline_pad_t _pad0; /**< Shared area: all threads read */
enum {
QUEUE_STATE_DESTROYED,
QUEUE_STATE_INITIALIZED
} state;
struct memtype const * mem;
size_t buffer_mask;

View file

@ -13,6 +13,11 @@ struct api;
struct web {
struct api *api;
enum {
WEB_STATE_DESTROYED,
WEB_STATE_INITIALIZED
} state;
struct lws_context *context; /**< The libwebsockets server context. */
struct lws_vhost *vhost; /**< The libwebsockets vhost. */

View file

@ -224,12 +224,18 @@ int api_init(struct api *a, struct cfg *cfg)
list_init(&a->sessions);
a->cfg = cfg;
a->state = API_STATE_INITIALIZED;
return 0;
}
int api_destroy(struct api *a)
{
// if (a->state = API_STATE_INITIALIZED)
// do something
a->state = API_STATE_DESTROYED;
return 0;
}

View file

@ -32,6 +32,8 @@ int pool_init(struct pool *p, size_t cnt, size_t blocksz, const struct memtype *
for (int i = 0; i < cnt; i++)
queue_push(&p->queue, (char *) p->buffer + i * p->blocksz);
p->state = POOL_STATE_INITIALIZED;
return 0;
}
@ -40,7 +42,10 @@ int pool_destroy(struct pool *p)
{
queue_destroy(&p->queue);
return memory_free(p->mem, p->buffer, p->len);
if (p->state == POOL_STATE_INITIALIZED)
return memory_free(p->mem, p->buffer, p->len);
p->state = POOL_STATE_DESTROYED;
return 0;
}

View file

@ -57,12 +57,21 @@ int queue_init(struct queue *q, size_t size, const struct memtype *mem)
atomic_store_explicit(&q->tail, 0, memory_order_relaxed);
atomic_store_explicit(&q->head, 0, memory_order_relaxed);
q->state = QUEUE_STATE_INITIALIZED;
return 0;
}
int queue_destroy(struct queue *q)
{
return memory_free(q->mem, q->buffer, (q->buffer_mask + 1) * sizeof(q->buffer[0]));
int ret = 0;
if (q->state == QUEUE_STATE_INITIALIZED)
ret = memory_free(q->mem, q->buffer, (q->buffer_mask + 1) * sizeof(q->buffer[0]));
q->state = QUEUE_STATE_DESTROYED;
return ret;
}
/** Return estimation of current queue usage.

View file

@ -162,13 +162,18 @@ int web_init(struct web *w, struct api *a)
w->vhost = lws_create_vhost(w->context, &vhost_info);
if (w->vhost == NULL)
error("WebSocket: failed to initialize server");
w->state = WEB_STATE_INITIALIZED;
return 0;
}
int web_destroy(struct web *w)
{
lws_context_destroy(w->context);
if (w->state == WEB_STATE_INITIALIZED)
lws_context_destroy(w->context);
w->state = WEB_STATE_DESTROYED;
return 0;
}