#include <sys/epoll.h>
#include <sys/signalfd.h>
#include <sys/socket.h>
+#include <pthread.h>
#include <murphy/common/macros.h>
#include <murphy/common/mm.h>
mrp_list_hook_t busses; /* known event busses */
mrp_list_hook_t eventq; /* pending events */
mrp_deferred_t *eventd; /* deferred event pump cb */
+
+ pthread_mutex_t lock;
};
MRP_UNUSED(super_data);
MRP_UNUSED(id);
+ pthread_mutex_lock(&ml->lock);
+
mrp_mainloop_poll(ml, FALSE);
mrp_mainloop_dispatch(ml);
ml->timer = NULL;
}
}
+
+ pthread_mutex_unlock(&ml->lock);
}
if (!setup_sighandlers(ml))
goto fail;
+
+ pthread_mutex_init(&ml->lock, NULL);
}
else {
fail:
void mrp_mainloop_destroy(mrp_mainloop_t *ml)
{
if (ml != NULL) {
+ pthread_mutex_lock(&ml->lock);
mrp_clear_superloop(ml);
purge_io_watches(ml);
purge_timers(ml);
fdtbl_destroy(ml->fdtbl);
mrp_free(ml->events);
+ pthread_mutex_unlock(&ml->lock);
+ pthread_mutex_destroy(&ml->lock);
mrp_free(ml);
}
}
void mrp_mainloop_quit(mrp_mainloop_t *ml, int exit_code)
{
+ pthread_mutex_lock(&ml->lock);
+
ml->exit_code = exit_code;
ml->quit = TRUE;
+
+ pthread_mutex_unlock(&ml->lock);
}
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <mcheck.h>
#include <errno.h>
#include <unistd.h>
#include <execinfo.h>
return posix_memalign(ptr, align, size);
}
+MRP_INIT static void menory_check_init()
+{
+ mcheck(NULL);
+}
static void __passthru_free(void *ptr, const char *file, int line,
const char *func)
MRP_UNUSED(file);
MRP_UNUSED(line);
MRP_UNUSED(func);
+ if (ptr == NULL)
+ return;
- free(ptr);
+ if (mprobe(ptr) == MCHECK_OK)
+ free(ptr);
+ else {
+ mrp_log_error("Invalid pointer passed to fuction free");
+ }
}
void mrp_mm_free(void *ptr, const char *file, int line, const char *func)
{
- return __mm.free(ptr, file, line, func);
+ __mm.free(ptr, file, line, func);
+ return;
}