#include #include #include #include "log.h" #include "lock.h" #define MALLOC malloc #define FREE free lock_t lock_init(void) { int r; pthread_mutex_t *m=MALLOC(sizeof(pthread_mutex_t)); if(!m) { return 0; } r = pthread_mutex_init(m, NULL); if(r) { LOGE("pthread_mutex_create failed\n"); FREE(m); return 0; } return (lock_t)m; } int lock_deinit(lock_t h) { int r; if(!h) { return -1; } r = pthread_mutex_destroy((pthread_mutex_t*)h); FREE((void*)h); return r; } int lock_on(lock_t h) { if(!h) { return -1; } return pthread_mutex_lock((pthread_mutex_t*)h); } int lock_off(lock_t h) { if(!h) { return -1; } return pthread_mutex_unlock((pthread_mutex_t*)h); }