diff --git a/src/htsmsg.c b/src/htsmsg.c index e59abb5f..1976dda0 100644 --- a/src/htsmsg.c +++ b/src/htsmsg.c @@ -570,3 +570,14 @@ htsmsg_copy(htsmsg_t *src) htsmsg_copy_i(src, dst); return dst; } + + +/** + * + */ +void +htsmsg_dtor(htsmsg_t **mp) +{ + if(*mp != NULL) + htsmsg_destroy(*mp); +} diff --git a/src/htsmsg.h b/src/htsmsg.h index 8cad0672..6df3abf6 100644 --- a/src/htsmsg.h +++ b/src/htsmsg.h @@ -259,4 +259,9 @@ htsmsg_t *htsmsg_copy(htsmsg_t *src); #define HTSMSG_FOREACH(f, msg) TAILQ_FOREACH(f, &(msg)->hm_fields, hmf_link) + +extern void htsmsg_dtor(htsmsg_t **mp); + +#define htsmsg_autodtor(n) htsmsg_t *n __attribute__((cleanup(htsmsg_dtor))) + #endif /* HTSMSG_H_ */ diff --git a/src/main.c b/src/main.c index 19911411..251f22e9 100644 --- a/src/main.c +++ b/src/main.c @@ -511,3 +511,12 @@ tvh_str_update(char **strp, const char *src) *strp = strdup(src); } + +/** + * + */ +void +scopedunlock(pthread_mutex_t **mtxp) +{ + pthread_mutex_unlock(*mtxp); +} diff --git a/src/tvhead.h b/src/tvhead.h index 2d637dd9..c2b623c1 100644 --- a/src/tvhead.h +++ b/src/tvhead.h @@ -656,4 +656,13 @@ extern time_t dispatch_clock; extern struct th_transport_list all_transports; extern struct channel_tree channel_name_tree; +extern void scopedunlock(pthread_mutex_t **mtxp); + +#define scopedlock(mtx) \ + pthread_mutex_t *scopedlock ## __LINE__ \ + __attribute__((cleanup(scopedunlock))) = mtx; \ + pthread_mutex_lock(mtx); + +#define scopedgloballock() scopedlock(&global_lock) + #endif /* TV_HEAD_H */