sw_rwlock.h 987 B

123456789101112131415161718192021222324252627282930313233343536
  1. /************************************************************************
  2. * AUTHOR: NiuJiuRu
  3. * FILENAME: sw_rwlock.h
  4. * DESCRIPTION: 读写锁, 也称共享锁
  5. * NOTE: 主要用于多线程同步访问全局共享资源
  6. * HISTORY:
  7. * 1, [2013-05-30] created by NiuJiuRu
  8. ***********************************************************************/
  9. #ifndef __SWRWLOCK_H__
  10. #define __SWRWLOCK_H__
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. /* 创建读写锁 */
  16. void *sw_rwlock_create();
  17. /* 销毁读写锁 */
  18. void sw_rwlock_destroy(void *hRWLock);
  19. /* 读写锁上锁-读(超时设置的时间单位为: 毫秒, 并且当timeout = -1时表示无限等待) */
  20. int sw_rwlock_rdlock(void *hRWLock, int timeout);
  21. /* 读写锁上锁-写(超时设置的时间单位为: 毫秒, 并且当timeout = -1时表示无限等待) */
  22. int sw_rwlock_wrlock(void *hRWLock, int timeout);
  23. /* 读写锁解锁 */
  24. void sw_rwlock_unlock(void *hRWLock);
  25. #ifdef __cplusplus
  26. }
  27. #endif
  28. #endif /* __SWRWLOCK_H__ */