diff options
author | Timothy Pearson <[email protected]> | 2014-11-12 15:01:36 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2014-11-12 15:01:36 -0600 |
commit | d74fed9b65e4c5e742a3fe81a05b83201ccf591a (patch) | |
tree | 679088bca9ef010b9785605cdda841b64929e69b /xrescheck.c | |
parent | b0c4ab328e98e611c61ce2b34b4535e0120781bd (diff) | |
parent | 325fb4c2983cb3211138078bff9cbec749be21c8 (diff) | |
download | tdebase-d74fed9b65e4c5e742a3fe81a05b83201ccf591a.tar.gz tdebase-d74fed9b65e4c5e742a3fe81a05b83201ccf591a.zip |
Merge remote-tracking branch 'compton-update/master'
Conflicts:
twin/compton-tde/common.h
twin/compton-tde/compton.c
twin/compton-tde/opengl.c
Diffstat (limited to 'xrescheck.c')
-rw-r--r-- | xrescheck.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/xrescheck.c b/xrescheck.c new file mode 100644 index 000000000..6a63bed36 --- /dev/null +++ b/xrescheck.c @@ -0,0 +1,65 @@ +#include "xrescheck.h" + +static xrc_xid_record_t *gs_xid_records = NULL; + +#define HASH_ADD_XID(head, xidfield, add) \ + HASH_ADD(hh, head, xidfield, sizeof(xid), add) + +#define HASH_FIND_XID(head, findxid, out) \ + HASH_FIND(hh, head, findxid, sizeof(xid), out) + +#define M_CPY_POS_DATA(prec) \ + prec->file = file; \ + prec->func = func; \ + prec->line = line; \ + +/** + * @brief Add a record of given XID to the allocation table. + */ +void +xrc_add_xid_(XID xid, const char *type, M_POS_DATA_PARAMS) { + xrc_xid_record_t *prec = cmalloc(1, xrc_xid_record_t); + prec->xid = xid; + prec->type = type; + M_CPY_POS_DATA(prec); + + HASH_ADD_XID(gs_xid_records, xid, prec); +} + +/** + * @brief Delete a record of given XID in the allocation table. + */ +void +xrc_delete_xid_(XID xid, M_POS_DATA_PARAMS) { + xrc_xid_record_t *prec = NULL; + HASH_FIND_XID(gs_xid_records, &xid, prec); + if (!prec) { + printf_err("XRC: %s:%d %s(): Can't find XID %#010lx we want to delete.", + file, line, func, xid); + return; + } + HASH_DEL(gs_xid_records, prec); + free(prec); +} + +/** + * @brief Report about issues found in the XID allocation table. + */ +void +xrc_report_xid(void) { + for (xrc_xid_record_t *prec = gs_xid_records; prec; prec = prec->hh.next) + printf_dbg("XRC: %s:%d %s(): %#010lx (%s) not freed.\n", + prec->file, prec->line, prec->func, prec->xid, prec->type); +} + +/** + * @brief Clear the XID allocation table. + */ +void +xrc_clear_xid(void) { + xrc_xid_record_t *prec = NULL, *ptmp = NULL; + HASH_ITER(hh, gs_xid_records, prec, ptmp) { + HASH_DEL(gs_xid_records, prec); + free(prec); + } +} |