Commit Graph

3 Commits

Author SHA1 Message Date
Neels Hofmeyr 6b5f1de06d osmo_use_count_to_str: make robust against unused use_count
A use_count struct gets properly initialized once the first use count is added.
Normally, this happens directly at object allocation. Still make sure
osmo_use_count_to_str_*() don't crash on a yet unused struct use_count.

Change-Id: I47b1acc7f13f2557c78e2cbe67d4690709ce795e
2020-09-30 18:48:12 +00:00
Neels Hofmeyr 9277b97d0b add osmo_use_count_to_str_c()
So far there is only osmo_use_count_name_buf(). Also provide a use count to
string using a talloc context, allowing to use OTC_SELECT.

- instead of foo_name(), rather use foo_to_str().
- osmo_use_count_name_buf() returns the buf and not the chars_needed. So add
  osmo_use_count_to_str_buf() with a signature that is usable by
  OSMO_NAME_C_IMPL().
- provide osmo_use_count_to_str_c() using OSMO_NAME_C_IMPL().

Change-Id: I1d2e7ee979f8c316ef99f7c65675b36d092ddfca
2020-09-20 09:51:32 +00:00
Neels Hofmeyr 0e8df1c7e4 add osmo_use_count API
Provide a common implementation of use counting that supports naming each user
as well as counting more than just one use per user, depending on the rules the
caller implies.

In osmo-msc, we were originally using a simple int counter to see whether a
connection is still in use or should be discarded. For clarity, we later added
names to each user in the form of a bitmask of flags, to figure out exactly
which users are still active: for logging and to debug double get / double put
bugs. This however is still not adequate, since there may be more than one CM
Service Request pending. Also, it is a specialized implementation that is not
re-usable.

With this generalized implementation, we can:

- fix the problem of inadequate counting of multiple concurrent CM Service
  Requests (more than one use count per user category),
- directly use arbitrary names for uses like __func__ or "foo" (no need to
  define enums and value_string[]s),
- re-use the same code for e.g. vlr_subscr and get fairly detailed VLR
  susbscriber usage logging for free.

Change-Id: Ife31e6798b4e728a23913179e346552a7dd338c0
2019-04-08 13:47:17 +00:00