\doxysection{include/osmocom/core/use\+\_\+count.h File Reference}
\label{use__count_8h}\index{include/osmocom/core/use\_count.h@{include/osmocom/core/use\_count.h}}


Generic object usage counter API (get, put and deallocate on zero count).  


{\ttfamily \#include $<$stdint.\+h$>$}\newline
{\ttfamily \#include $<$stdlib.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/linuxlist.\+h$>$}\newline
\doxysubsection*{Data Structures}
\begin{DoxyCompactItemize}
\item 
struct \textbf{ osmo\+\_\+use\+\_\+count}
\begin{DoxyCompactList}\small\item\em Use counter state for one used object, managing N distinct named counters. \end{DoxyCompactList}\item 
struct \textbf{ osmo\+\_\+use\+\_\+count\+\_\+entry}
\begin{DoxyCompactList}\small\item\em One named counter in the list managed by \doxyref{osmo\+\_\+use\+\_\+count}{p.}{structosmo__use__count}. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ osmo\+\_\+use\+\_\+count\+\_\+get\+\_\+put}(USE\+\_\+\+LIST,  USE,  CHANGE)~ \textbf{ \+\_\+osmo\+\_\+use\+\_\+count\+\_\+get\+\_\+put}(USE\+\_\+\+LIST, USE, CHANGE, \+\_\+\+\_\+\+FILE\+\_\+\+\_\+, \+\_\+\+\_\+\+LINE\+\_\+\+\_\+)
\begin{DoxyCompactList}\small\item\em Change the use count for a given use token. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef int($\ast$ \textbf{ osmo\+\_\+use\+\_\+count\+\_\+cb\+\_\+t}) (struct \textbf{ osmo\+\_\+use\+\_\+count\+\_\+entry} $\ast$use\+\_\+count\+\_\+entry, int32\+\_\+t old\+\_\+use\+\_\+count, const char $\ast$\textbf{ file}, int line)
\begin{DoxyCompactList}\small\item\em Invoked when a use count changes. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
int \textbf{ \+\_\+osmo\+\_\+use\+\_\+count\+\_\+get\+\_\+put} (struct \textbf{ osmo\+\_\+use\+\_\+count} $\ast$uc, const char $\ast$use, int32\+\_\+t change, const char $\ast$\textbf{ file}, int line)
\begin{DoxyCompactList}\small\item\em Implementation for \doxyref{osmo\+\_\+use\+\_\+count\+\_\+get\+\_\+put()}{p.}{group__use__count_ga3457c05c5d2b707d99eb01704dc5f233}, which can also be directly invoked to pass source file information. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ osmo\+\_\+use\+\_\+count\+\_\+name\+\_\+buf} (char $\ast$buf, size\+\_\+t buf\+\_\+len, const struct \textbf{ osmo\+\_\+use\+\_\+count} $\ast$uc)
\begin{DoxyCompactList}\small\item\em Write a comprehensive listing of use counts to a string buffer. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+use\+\_\+count\+\_\+to\+\_\+str\+\_\+buf} (char $\ast$buf, size\+\_\+t buf\+\_\+len, const struct \textbf{ osmo\+\_\+use\+\_\+count} $\ast$uc)
\begin{DoxyCompactList}\small\item\em Write a comprehensive listing of use counts to a string buffer. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+use\+\_\+count\+\_\+to\+\_\+str\+\_\+c} (void $\ast$ctx, const struct \textbf{ osmo\+\_\+use\+\_\+count} $\ast$uc)
\begin{DoxyCompactList}\small\item\em Write a comprehensive listing of use counts to a talloc allocated string buffer. \end{DoxyCompactList}\item 
int32\+\_\+t \textbf{ osmo\+\_\+use\+\_\+count\+\_\+total} (const struct \textbf{ osmo\+\_\+use\+\_\+count} $\ast$uc)
\begin{DoxyCompactList}\small\item\em Return the sum of all use counts, min-\/ and max-\/clamped at INT32\+\_\+\+MIN and INT32\+\_\+\+MAX. \end{DoxyCompactList}\item 
int32\+\_\+t \textbf{ osmo\+\_\+use\+\_\+count\+\_\+by} (const struct \textbf{ osmo\+\_\+use\+\_\+count} $\ast$uc, const char $\ast$use)
\begin{DoxyCompactList}\small\item\em Return use count by a single use token. \end{DoxyCompactList}\item 
struct \textbf{ osmo\+\_\+use\+\_\+count\+\_\+entry} $\ast$ \textbf{ osmo\+\_\+use\+\_\+count\+\_\+find} (const struct \textbf{ osmo\+\_\+use\+\_\+count} $\ast$uc, const char $\ast$use)
\item 
void \textbf{ osmo\+\_\+use\+\_\+count\+\_\+free} (struct \textbf{ osmo\+\_\+use\+\_\+count\+\_\+entry} $\ast$use\+\_\+count\+\_\+entry)
\begin{DoxyCompactList}\small\item\em Deallocate a use count entry. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+use\+\_\+count\+\_\+make\+\_\+static\+\_\+entries} (struct \textbf{ osmo\+\_\+use\+\_\+count} $\ast$uc, struct \textbf{ osmo\+\_\+use\+\_\+count\+\_\+entry} $\ast$buf, size\+\_\+t buf\+\_\+n\+\_\+entries)
\begin{DoxyCompactList}\small\item\em Add N static use token entries to avoid dynamic allocation of use count tokens. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Generic object usage counter API (get, put and deallocate on zero count). 

