blob: 6cb0a6b7d25105a08c5ed0713c14d8d14b12eb6f [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file write_queue.h
2 * Generic write queue implementation */
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +01003/*
4 * (C) 2010 by Holger Hans Peter Freyther
5 * (C) 2010 by On-Waves
6 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010019 */
Sylvain Munaut12ba7782014-06-16 10:13:40 +020020#pragma once
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010021
Harald Welte2777ecd2011-08-17 14:23:42 +020022/*! \defgroup write_queue Osmocom msgb write queues
23 * @{
Neels Hofmeyr17518fe2017-06-20 04:35:06 +020024 * \file write_queue.h */
Harald Weltebd598e32011-08-16 23:26:52 +020025
Pablo Neira Ayusodc35dbe2011-03-28 19:24:20 +020026#include <osmocom/core/select.h>
27#include <osmocom/core/msgb.h>
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010028
Harald Weltebd598e32011-08-16 23:26:52 +020029/*! write queue instance */
Pablo Neira Ayuso9111d932011-05-07 12:42:51 +020030struct osmo_wqueue {
Neels Hofmeyr87e45502017-06-20 00:17:59 +020031 /*! osmocom file descriptor */
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020032 struct osmo_fd bfd;
Neels Hofmeyr87e45502017-06-20 00:17:59 +020033 /*! maximum length of write queue */
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010034 unsigned int max_length;
Neels Hofmeyr87e45502017-06-20 00:17:59 +020035 /*! current length of write queue */
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010036 unsigned int current_length;
37
Neels Hofmeyr87e45502017-06-20 00:17:59 +020038 /*! actual linked list implementing the queue */
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010039 struct llist_head msg_queue;
40
Pau Espin Pedrol686eba92018-05-04 18:20:35 +020041 /*! call-back in case qeueue is readable. Return -EBADF if fd is freed inside cb. */
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020042 int (*read_cb)(struct osmo_fd *fd);
Pau Espin Pedrol686eba92018-05-04 18:20:35 +020043 /*! call-back in case qeueue is writable. Return -EBADF if fd is freed inside cb. */
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020044 int (*write_cb)(struct osmo_fd *fd, struct msgb *msg);
Pau Espin Pedrol686eba92018-05-04 18:20:35 +020045 /*! call-back in case qeueue has exceptions. Return -EBADF if fd is freed inside cb. */
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020046 int (*except_cb)(struct osmo_fd *fd);
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010047};
48
Pablo Neira Ayuso9111d932011-05-07 12:42:51 +020049void osmo_wqueue_init(struct osmo_wqueue *queue, int max_length);
50void osmo_wqueue_clear(struct osmo_wqueue *queue);
51int osmo_wqueue_enqueue(struct osmo_wqueue *queue, struct msgb *data);
Harald Welte66138cc2020-09-26 22:02:27 +020052int osmo_wqueue_enqueue_quiet(struct osmo_wqueue *queue, struct msgb *data);
Pablo Neira Ayuso9111d932011-05-07 12:42:51 +020053int osmo_wqueue_bfd_cb(struct osmo_fd *fd, unsigned int what);
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010054
Sylvain Munautdca7d2c2012-04-18 21:53:23 +020055/*! @} */