pthread_rwlock_trywrlock.c

来自「UNIX网络编程 第2卷 进程间通信 代码」· C语言 代码 · 共 37 行

C
37
字号
/* include trywrlock */#include	"unpipc.h"#include	"pthread_rwlock.h"intpthread_rwlock_trywrlock(pthread_rwlock_t *rw){	int		result;	if (rw->rw_magic != RW_MAGIC)		return(EINVAL);	if ( (result = pthread_mutex_lock(&rw->rw_mutex)) != 0)		return(result);	if (rw->rw_refcount != 0)		result = EBUSY;			/* held by either writer or reader(s) */	else		rw->rw_refcount = -1;	/* available, indicate a writer has it */	pthread_mutex_unlock(&rw->rw_mutex);	return(result);}/* end trywrlock */intPthread_rwlock_trywrlock(pthread_rwlock_t *rw){	int		n;	if ( (n = pthread_rwlock_trywrlock(rw)) != 0) {		errno = n;		err_sys("pthread_rwlock_trywrlock error");	}	return(n);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?