Changeset 107 for pjproject/trunk/pjlib/src/pj/os_core_win32.c
- Timestamp:
- Jan 5, 2006 11:35:46 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/os_core_win32.c
r106 r107 863 863 struct pj_rwmutex_t 864 864 { 865 pj_mutex_t *read_lock, *write_lock; 866 int reader_count; 865 pj_mutex_t *read_lock; 866 /* write_lock must use semaphore, because write_lock may be released 867 * by thread other than the thread that acquire the write_lock in the 868 * first place. 869 */ 870 pj_sem_t *write_lock; 871 pj_int32_t reader_count; 867 872 }; 868 873 … … 886 891 return status; 887 892 888 status = pj_ mutex_create_recursive(pool, name, &rwmutex->write_lock);893 status = pj_sem_create(pool, name, 1, 1, &rwmutex->write_lock); 889 894 if (status != PJ_SUCCESS) { 890 895 pj_mutex_destroy(rwmutex->read_lock); … … 908 913 909 914 status = pj_mutex_lock(mutex->read_lock); 910 if (status != PJ_SUCCESS) 915 if (status != PJ_SUCCESS) { 916 pj_assert(!"This pretty much is unexpected"); 911 917 return status; 918 } 912 919 913 920 mutex->reader_count++; 921 922 pj_assert(mutex->reader_count < 0x7FFFFFF0L); 923 914 924 if (mutex->reader_count == 1) 915 pj_ mutex_lock(mutex->write_lock);925 pj_sem_wait(mutex->write_lock); 916 926 917 927 status = pj_mutex_unlock(mutex->read_lock); … … 926 936 { 927 937 PJ_ASSERT_RETURN(mutex, PJ_EINVAL); 928 return pj_ mutex_lock(mutex->write_lock);938 return pj_sem_wait(mutex->write_lock); 929 939 } 930 940 … … 940 950 941 951 status = pj_mutex_lock(mutex->read_lock); 942 if (status != PJ_SUCCESS) 952 if (status != PJ_SUCCESS) { 953 pj_assert(!"This pretty much is unexpected"); 943 954 return status; 955 } 944 956 945 957 pj_assert(mutex->reader_count >= 1); … … 947 959 --mutex->reader_count; 948 960 if (mutex->reader_count == 0) 949 pj_ mutex_unlock(mutex->write_lock);961 pj_sem_post(mutex->write_lock); 950 962 951 963 status = pj_mutex_unlock(mutex->read_lock); … … 960 972 { 961 973 PJ_ASSERT_RETURN(mutex, PJ_EINVAL); 962 return pj_mutex_unlock(mutex->write_lock); 974 pj_assert(mutex->reader_count <= 1); 975 return pj_sem_post(mutex->write_lock); 963 976 } 964 977 … … 972 985 PJ_ASSERT_RETURN(mutex, PJ_EINVAL); 973 986 pj_mutex_destroy(mutex->read_lock); 974 pj_ mutex_destroy(mutex->write_lock);987 pj_sem_destroy(mutex->write_lock); 975 988 return PJ_SUCCESS; 976 989 }
Note: See TracChangeset
for help on using the changeset viewer.