myxce/src/include/mylock.h

39 lines
1,023 B
C

#if !defined(_MYLOCK_H_)
#define _MYLOCK_H_ 1
#include <pthread.h>
typedef pthread_mutex_t mylock_t;
typedef pthread_rwlock_t my_rwlock_t;
typedef struct {
int ncap;
int head;
int len;
int isize;
void* data;
pthread_mutex_t mutex;
pthread_cond_t condget;
pthread_cond_t condput;
} cbuf_t;
extern int mylock_init(mylock_t*);
extern void mylock_fini(mylock_t*);
extern int mylock_try(mylock_t*);
extern int mylock_lock(mylock_t*);
extern int mylock_unlock(mylock_t*);
extern int my_rwlock_init(my_rwlock_t*);
extern void my_rwlock_fini(my_rwlock_t*);
extern int my_rwlock_rlock(my_rwlock_t*);
extern int my_rwlock_wlock(my_rwlock_t*);
extern int my_rwlock_unlock(my_rwlock_t*);
extern int cbuf_init(cbuf_t*, int, int);
extern void cbuf_fini(cbuf_t*);
extern int cbuf_put(cbuf_t*, void*);
extern int cbuf_tryput(cbuf_t*, void*);
extern int cbuf_get(cbuf_t*, void*);
extern int cbuf_tryget(cbuf_t*, void*);
#endif