#ifndef _UTILS_H_ #define _UTILS_H_ #include #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a,b) (a) < (b) ? (b) : (a) #define ARRAY_SIZE(a) (sizeof(a) / (sizeof((a)[0]))) struct mutex { pthread_mutex_t lock; int line; char *file; char owner_name[16]; time_t lock_time; char *name; }; void _mutex_lock_acquired(struct mutex *lock, char *file, int line); int _mutex_lock(struct mutex *lock, char *file, int line); int _mutex_unlock(struct mutex *lock); #define mutex_lock(lock) _mutex_lock(lock, __FILE__, __LINE__) #define mutex_unlock(lock) _mutex_unlock(lock) #define mutex_lock_acquired(lock) _mutex_lock_acquired(lock, __FILE__, __LINE__) static inline char *_strlcat(char *dst, const char *src, size_t len) { strncat(dst, src, len - strnlen(dst, len) - 1); dst[len - 1] = '\0'; return dst; } static inline int mutex_init(struct mutex *mutex) { mutex->line = 0; mutex->owner_name[0] = '\0'; mutex->lock_time = 0; mutex->name = NULL; return pthread_mutex_init(&mutex->lock, NULL); } #define ROUND_UP(a, m) ((a) + (m) - (a) % (m)) #endif