wq.h

/**
 * Copyright (c) 2024, SWGY, Inc. <ron@sw.gy>
 *
 * 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; either version 3 of the License, or (at
 * your option) any later version.
 *
 * 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, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
#ifndef __WQ_H_
#define __WQ_H_

#include <sys/queue.h>

#include <pthread.h>

STAILQ_HEAD(_wq_head, task);

struct task {
	int			 theta_min;
	double			*v_out;
	STAILQ_ENTRY(task)	 q; /* singly-linked tail queue. */
};

struct wq_head {
	struct _wq_head _head;
	pthread_mutex_t mutex;
};

/**
 * Initialize and return a new work queue.
 */
struct wq_head *wq_init(void);

/**
 * Enqueue the provided task on the work queue headed by `head`
 */
int wq_q(struct wq_head *head, struct task *t);

/**
 * Return the next task in the queue headed by `head`. Return NULL
 * if the queue is empty.
 */
struct task *wq_pop(struct wq_head *head);

/* Return non-zero if empty */
int wq_empty(struct wq_head *h);

/**
 * Free resources associated with the provided work queue.
 */
void wq_free(struct wq_head *h);


#endif