Add a basic ring queue impl
This commit is contained in:
parent
33d0b03b5f
commit
4e571e82b5
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Feynman -- Wayland compositor for GNU Emacs
|
||||
*
|
||||
* Copyright (c) 2022 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 2.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "queue.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
queue_t *
|
||||
init_queue (unsigned size)
|
||||
{
|
||||
event_t *data = (event_t *)malloc (sizeof (event_t) * size);
|
||||
queue_t *e = (queue_t *)malloc (sizeof (queue_t));
|
||||
|
||||
e->size = size;
|
||||
e->events = data;
|
||||
e->head = NULL;
|
||||
e->tail = NULL;
|
||||
|
||||
return e;
|
||||
};
|
||||
|
||||
void
|
||||
deinit_queue (queue_t *q)
|
||||
{
|
||||
free (q->events);
|
||||
free (q);
|
||||
};
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Feynman -- Wayland compositor for GNU Emacs
|
||||
*
|
||||
* Copyright (c) 2022 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 2.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FEYNMAN_QUEUE_H
|
||||
#define FEYNMAN_QUEUE_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum event_enum
|
||||
{
|
||||
echo = 0,
|
||||
exit = 1,
|
||||
} event_type_t;
|
||||
|
||||
typedef struct arguments
|
||||
{
|
||||
unsigned count;
|
||||
void **args;
|
||||
} arguments_t;
|
||||
|
||||
typedef struct event
|
||||
{
|
||||
unsigned id;
|
||||
event_type_t event_type;
|
||||
arguments_t *args;
|
||||
} event_t;
|
||||
|
||||
typedef struct queue
|
||||
{
|
||||
unsigned *head;
|
||||
unsigned *tail;
|
||||
unsigned size;
|
||||
event_t *events;
|
||||
} queue_t;
|
||||
|
||||
queue_t *init_queue (unsigned size);
|
||||
void deinit_queue (queue_t *q);
|
||||
|
||||
int enqueue_event (queue_t *q, event_t *event);
|
||||
event_t *pop_event (queue_t *q);
|
||||
bool is_queue_empty (queue_t *q);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue