Changeset 150
- Timestamp:
- Feb 7, 2006 10:17:55 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/os_core_unix.c
r66 r150 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 18 */ 19 #define _GNU_SOURCE 19 20 #include <pj/os.h> 20 21 #include <pj/assert.h> … … 35 36 #include <errno.h> // errno 36 37 37 #define __USE_GNU38 //uncomment this to get pthread_mutexattr_settype declaration.39 //unfortunately this causes syntax error in pthread.h! :(40 //#define __USE_UNIX9841 38 #include <pthread.h> 42 39 … … 999 996 } 1000 997 #endif 998 999 /////////////////////////////////////////////////////////////////////////////// 1000 struct pj_rwmutex_t 1001 { 1002 pthread_rwlock_t rwlock; 1003 }; 1004 1005 PJ_DEF(pj_status_t) pj_rwmutex_create(pj_pool_t *pool, const char *name, 1006 pj_rwmutex_t **p_mutex) 1007 { 1008 pj_rwmutex_t *rwm; 1009 pj_status_t status; 1010 1011 PJ_UNUSED_ARG(name); 1012 1013 rwm = pj_pool_alloc(pool, sizeof(pj_rwmutex_t)); 1014 PJ_ASSERT_RETURN(rwm, PJ_ENOMEM); 1015 1016 status = pthread_rwlock_init(&rwm->rwlock, NULL); 1017 if (status != 0) 1018 return PJ_RETURN_OS_ERROR(status); 1019 1020 *p_mutex = rwm; 1021 return PJ_SUCCESS; 1022 } 1023 1024 /* 1025 * Lock the mutex for reading. 1026 * 1027 */ 1028 PJ_DEF(pj_status_t) pj_rwmutex_lock_read(pj_rwmutex_t *mutex) 1029 { 1030 pj_status_t status; 1031 1032 status = pthread_rwlock_rdlock(&mutex->rwlock); 1033 if (status != 0) 1034 return PJ_RETURN_OS_ERROR(status); 1035 1036 return PJ_SUCCESS; 1037 } 1038 1039 /* 1040 * Lock the mutex for writing. 1041 * 1042 */ 1043 PJ_DEF(pj_status_t) pj_rwmutex_lock_write(pj_rwmutex_t *mutex) 1044 { 1045 pj_status_t status; 1046 1047 status = pthread_rwlock_wrlock(&mutex->rwlock); 1048 if (status != 0) 1049 return PJ_RETURN_OS_ERROR(status); 1050 1051 return PJ_SUCCESS; 1052 } 1053 1054 /* 1055 * Release read lock. 1056 * 1057 */ 1058 PJ_DEF(pj_status_t) pj_rwmutex_unlock_read(pj_rwmutex_t *mutex) 1059 { 1060 return pj_rwmutex_unlock_write(mutex); 1061 } 1062 1063 /* 1064 * Release write lock. 1065 * 1066 */ 1067 PJ_DEF(pj_status_t) pj_rwmutex_unlock_write(pj_rwmutex_t *mutex) 1068 { 1069 pj_status_t status; 1070 1071 status = pthread_rwlock_unlock(&mutex->rwlock); 1072 if (status != 0) 1073 return PJ_RETURN_OS_ERROR(status); 1074 1075 return PJ_SUCCESS; 1076 } 1077 1078 /* 1079 * Destroy reader/writer mutex. 1080 * 1081 */ 1082 PJ_DEF(pj_status_t) pj_rwmutex_destroy(pj_rwmutex_t *mutex) 1083 { 1084 pj_status_t status; 1085 1086 status = pthread_rwlock_destroy(&mutex->rwlock); 1087 if (status != 0) 1088 return PJ_RETURN_OS_ERROR(status); 1089 1090 return PJ_SUCCESS; 1091 } 1001 1092 1002 1093 ///////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.