#include "access.h"
#include "notify.h"
#include "tcp.h"
+#include "memoryinfo.h"
static pthread_mutex_t comet_mutex = PTHREAD_MUTEX_INITIALIZER;
static tvh_cond_t comet_cond;
int mailbox_tally;
int comet_running;
+static memoryinfo_t comet_memoryinfo = {
+ .my_name = "Comet",
+};
+
typedef struct comet_mailbox {
char *cmb_boxid; /* SHA-1 hash */
char *cmb_lang; /* UI language */
LIST_REMOVE(cmb, cmb_link);
+ memoryinfo_free(&comet_memoryinfo,
+ sizeof(*cmb) +
+ (strlen(cmb->cmb_boxid) + 1) +
+ (cmb->cmb_lang ? strlen(cmb->cmb_lang) + 1 : 0));
+
free(cmb->cmb_lang);
free(cmb->cmb_boxid);
free(cmb);
for(cmb = LIST_FIRST(&mailboxes); cmb != NULL; cmb = next) {
next = LIST_NEXT(cmb, cmb_link);
+ printf("refcount %d boxid %s last_used %ld mclk %ld\n", cmb->cmb_refcount, cmb->cmb_boxid, mono2sec(cmb->cmb_last_used), mono2sec(mclk()));
if(cmb->cmb_refcount == 1 &&
cmb->cmb_last_used && cmb->cmb_last_used + sec2mono(60) < mclk())
cmb_destroy(cmb);
mailbox_tally++;
LIST_INSERT_HEAD(&mailboxes, cmb, cmb_link);
+
+ memoryinfo_alloc(&comet_memoryinfo, sizeof(*cmb) +
+ (strlen(id) + 1) +
+ (lang ? strlen(lang) + 1 : 0));
return cmb;
}
pthread_mutex_lock(&comet_mutex);
if (atomic_get(&comet_running))
cmb->cmb_refcount--;
+ cmb->cmb_last_used = mclk();
pthread_mutex_unlock(&comet_mutex);
return res;
{
http_path_t *hp;
+ memoryinfo_register(&comet_memoryinfo);
pthread_mutex_lock(&comet_mutex);
tvh_cond_init(&comet_cond);
atomic_set(&comet_running, 1);
tvh_cond_destroy(&comet_cond);
+ pthread_mutex_lock(&global_lock);
+ memoryinfo_unregister(&comet_memoryinfo);
+ pthread_mutex_unlock(&global_lock);
}
/**