Add automatic destructors for htsmsg's and pthread locks

This commit is contained in:
Andreas Öman 2009-07-15 20:29:58 +00:00
parent 90b6c14906
commit 08466b212e
4 changed files with 34 additions and 0 deletions

View file

@ -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);
}

View file

@ -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_ */

View file

@ -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);
}

View file

@ -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 */