#include #include #include #include "log.h" #include "lock.h" #define MALLOC malloc #define FREE free //static global lock static pthread_mutex_t *mutex_pool[LOCK_ID_MAX]={0}; int lock_s_init(void) { int i,r; pthread_mutex_t *m=NULL; for(i=0; i=LOCK_ID_MAX || !mutex_pool[id]) { return -1; } return pthread_mutex_lock(mutex_pool[id]); } int lock_s_release(int id) { if(id<0 || id>=LOCK_ID_MAX || !mutex_pool[id]) { return -1; } return pthread_mutex_unlock(mutex_pool[id]); } /////////////////////////////////////////////////////// lock_t lock_d_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_d_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_d_hold(lock_t h) { if(!h) { return -1; } return pthread_mutex_lock((pthread_mutex_t*)h); } int lock_d_release(lock_t h) { if(!h) { return -1; } return pthread_mutex_unlock((pthread_mutex_t*)h); }