\doxysection{src/core/use\+\_\+count.c File Reference}
\label{use__count_8c}\index{src/core/use\_count.c@{src/core/use\_count.c}}


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


{\ttfamily \#include $<$errno.\+h$>$}\newline
{\ttfamily \#include $<$inttypes.\+h$>$}\newline
{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/linuxlist.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/utils.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/use\+\_\+count.\+h$>$}\newline
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
static bool \textbf{ count\+\_\+safe} (int32\+\_\+t $\ast$val\+\_\+p, int32\+\_\+t add)
\begin{DoxyCompactList}\small\item\em Add two int32\+\_\+t but make sure to min-\/ and max-\/clamp at INT32\+\_\+\+MIN and INT32\+\_\+\+MAX, respectively. \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 
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 
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 
static struct \textbf{ osmo\+\_\+use\+\_\+count\+\_\+entry} $\ast$ \textbf{ osmo\+\_\+use\+\_\+count\+\_\+repurpose\+\_\+zero\+\_\+entry} (struct \textbf{ osmo\+\_\+use\+\_\+count} $\ast$uc, const char $\ast$use)
\begin{DoxyCompactList}\small\item\em Find a use count entry that currently has zero count, and re-\/use that for this new use token. \end{DoxyCompactList}\item 
static struct \textbf{ osmo\+\_\+use\+\_\+count\+\_\+entry} $\ast$ \textbf{ osmo\+\_\+use\+\_\+count\+\_\+create} (struct \textbf{ osmo\+\_\+use\+\_\+count} $\ast$uc, const char $\ast$use)
\begin{DoxyCompactList}\small\item\em Allocate a new use count entry, happens implicitly in \doxyref{osmo\+\_\+use\+\_\+count\+\_\+get\+\_\+put()}{p.}{group__use__count_ga3457c05c5d2b707d99eb01704dc5f233}. \end{DoxyCompactList}\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 
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 
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 Implementation (get, put and deallocate on zero count). 

