bts: combine bts_{init,cleanup} into consturctor/destructor methods
The bts_init/cleanup functions were kept during the C and C++ structure
merge process to make the patch simpler. It's not needed anymore,
let's move all the destructor logic into one function and keep that
together.
Change-Id: I73a9457d5c92f62261561ef6afe392953576aec4
diff --git a/src/bts.cpp b/src/bts.cpp
index 92cbca5..0e08091 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -192,8 +192,40 @@
bts_stat_item_description,
};
-static void bts_init(struct gprs_rlcmac_bts *bts, struct gprs_pcu *pcu)
+static int bts_talloc_destructor(struct gprs_rlcmac_bts* bts)
{
+ /* this can cause counter updates and must not be left to the
+ * m_ms_store's destructor */
+ bts->ms_store->cleanup();
+ delete bts->ms_store;
+ delete bts->sba;
+ delete bts->pollController;
+
+ if (bts->ratectrs) {
+ rate_ctr_group_free(bts->ratectrs);
+ bts->ratectrs = NULL;
+ }
+
+ if (bts->statg) {
+ osmo_stat_item_group_free(bts->statg);
+ bts->statg = NULL;
+ }
+
+ if (bts->app_info) {
+ msgb_free(bts->app_info);
+ bts->app_info = NULL;
+ }
+ return 0;
+}
+
+struct gprs_rlcmac_bts* bts_alloc(struct gprs_pcu *pcu)
+{
+ struct gprs_rlcmac_bts* bts;
+ bts = talloc_zero(pcu, struct gprs_rlcmac_bts);
+ if (!bts)
+ return bts;
+ talloc_set_destructor(bts, bts_talloc_destructor);
+
bts->pcu = pcu;
bts->pollController = new PollController(*bts);
@@ -247,31 +279,8 @@
bts->statg = osmo_stat_item_group_alloc(tall_pcu_ctx, &bts_statg_desc, 0);
OSMO_ASSERT(bts->statg);
-}
-static void bts_cleanup(gprs_rlcmac_bts *bts)
-{
- /* this can cause counter updates and must not be left to the
- * m_ms_store's destructor */
- bts->ms_store->cleanup();
- delete bts->ms_store;
- delete bts->sba;
- delete bts->pollController;
-
- if (bts->ratectrs) {
- rate_ctr_group_free(bts->ratectrs);
- bts->ratectrs = NULL;
- }
-
- if (bts->statg) {
- osmo_stat_item_group_free(bts->statg);
- bts->statg = NULL;
- }
-
- if (bts->app_info) {
- msgb_free(bts->app_info);
- bts->app_info = NULL;
- }
+ return bts;
}
void bts_set_current_frame_number(struct gprs_rlcmac_bts *bts, int fn)
@@ -1057,24 +1066,6 @@
return ms;
}
-
-static int bts_talloc_destructor(struct gprs_rlcmac_bts* bts)
-{
- bts_cleanup(bts);
- return 0;
-}
-
-struct gprs_rlcmac_bts* bts_alloc(struct gprs_pcu *pcu)
-{
- struct gprs_rlcmac_bts* bts;
- bts = talloc_zero(pcu, struct gprs_rlcmac_bts);
- if (!bts)
- return bts;
- talloc_set_destructor(bts, bts_talloc_destructor);
- bts_init(bts, pcu);
- return bts;
-}
-
struct SBAController *bts_sba(struct gprs_rlcmac_bts *bts)
{
return bts->sba;