\doxysection{it\+\_\+q.\+h}
\label{it__q_8h_source}\index{include/osmocom/core/it\_q.h@{include/osmocom/core/it\_q.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{2 }
\DoxyCodeLine{3 \textcolor{preprocessor}{\#include <osmocom/core/linuxlist.h>}}
\DoxyCodeLine{4 \textcolor{preprocessor}{\#include <osmocom/core/select.h>}}
\DoxyCodeLine{5 \textcolor{preprocessor}{\#include <pthread.h>}}
\DoxyCodeLine{6 }
\DoxyCodeLine{16 \textcolor{keyword}{struct }osmo\_it\_q \{}
\DoxyCodeLine{17         \textcolor{comment}{/* entry in global list of message queues */}}
\DoxyCodeLine{18         \textcolor{keyword}{struct }llist\_head entry;}
\DoxyCodeLine{19 }
\DoxyCodeLine{20         \textcolor{comment}{/* the actual list of user structs. HEAD: first in queue; TAIL: last in queue */}}
\DoxyCodeLine{21         \textcolor{keyword}{struct }llist\_head list;}
\DoxyCodeLine{22         \textcolor{comment}{/* A pthread mutex to safeguard accesses to the queue. No rwlock as we always write. */}}
\DoxyCodeLine{23         pthread\_mutex\_t mutex;}
\DoxyCodeLine{24         \textcolor{comment}{/* Current count of messages in the queue */}}
\DoxyCodeLine{25         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} current\_length;}
\DoxyCodeLine{26         \textcolor{comment}{/* osmo-\/fd wrapped eventfd */}}
\DoxyCodeLine{27         \textcolor{keyword}{struct }osmo\_fd event\_ofd;}
\DoxyCodeLine{28 }
\DoxyCodeLine{29         \textcolor{comment}{/* a user-\/defined name for this queue */}}
\DoxyCodeLine{30         \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name;}
\DoxyCodeLine{31         \textcolor{comment}{/* maximum permitted length of queue */}}
\DoxyCodeLine{32         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} max\_length;}
\DoxyCodeLine{33         \textcolor{comment}{/* read call-\/back, called for each de-\/queued message */}}
\DoxyCodeLine{34         void (*read\_cb)(\textcolor{keyword}{struct }osmo\_it\_q *q, \textcolor{keyword}{struct }llist\_head *item);}
\DoxyCodeLine{35         \textcolor{comment}{/* opaque data pointer passed through to call-\/back function */}}
\DoxyCodeLine{36         \textcolor{keywordtype}{void} *data;}
\DoxyCodeLine{37 \};}
\DoxyCodeLine{38 }
\DoxyCodeLine{39 \textcolor{keyword}{struct }osmo\_it\_q *osmo\_it\_q\_by\_name(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);}
\DoxyCodeLine{40 }
\DoxyCodeLine{41 \textcolor{keywordtype}{int} \_osmo\_it\_q\_enqueue(\textcolor{keyword}{struct} osmo\_it\_q *queue, \textcolor{keyword}{struct} llist\_head *item);}
\DoxyCodeLine{42 \textcolor{preprocessor}{\#define osmo\_it\_q\_enqueue(queue, item, member) \(\backslash\)}}
\DoxyCodeLine{43 \textcolor{preprocessor}{        \_osmo\_it\_q\_enqueue(queue, \&(item)-\/>member)}}
\DoxyCodeLine{44 }
\DoxyCodeLine{45 \textcolor{keyword}{struct }llist\_head *\_osmo\_it\_q\_dequeue(\textcolor{keyword}{struct} osmo\_it\_q *queue);}
\DoxyCodeLine{46 \textcolor{preprocessor}{\#define osmo\_it\_q\_dequeue(queue, item, member) do \{                     \(\backslash\)}}
\DoxyCodeLine{47 \textcolor{preprocessor}{        struct llist\_head *l = \_osmo\_it\_q\_dequeue(queue);               \(\backslash\)}}
\DoxyCodeLine{48 \textcolor{preprocessor}{        if (!l)                                                         \(\backslash\)}}
\DoxyCodeLine{49 \textcolor{preprocessor}{                *item = NULL;                                           \(\backslash\)}}
\DoxyCodeLine{50 \textcolor{preprocessor}{        else                                                            \(\backslash\)}}
\DoxyCodeLine{51 \textcolor{preprocessor}{                *item = llist\_entry(l, typeof(**item), member);         \(\backslash\)}}
\DoxyCodeLine{52 \textcolor{preprocessor}{\} while (0)}}
\DoxyCodeLine{53 }
\DoxyCodeLine{54 }
\DoxyCodeLine{55 \textcolor{keyword}{struct }osmo\_it\_q *osmo\_it\_q\_alloc(\textcolor{keywordtype}{void} *ctx, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} max\_length,}
\DoxyCodeLine{56 }
\DoxyCodeLine{57                                         \textcolor{keywordtype}{void} (*read\_cb)(\textcolor{keyword}{struct} osmo\_it\_q *q, \textcolor{keyword}{struct} llist\_head *item),}
\DoxyCodeLine{58                                         \textcolor{keywordtype}{void} *data);}
\DoxyCodeLine{59 \textcolor{keywordtype}{void} osmo\_it\_q\_destroy(\textcolor{keyword}{struct} osmo\_it\_q *q);}
\DoxyCodeLine{60 \textcolor{keywordtype}{void} osmo\_it\_q\_flush(\textcolor{keyword}{struct} osmo\_it\_q *q);}
\DoxyCodeLine{61 }

\end{DoxyCode}
