Changeset 5758
- Timestamp:
- Mar 26, 2018 10:33:50 AM (7 years ago)
- Location:
- pjproject/trunk/pjlib/src/pj
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/os_core_unix.c
r5277 r5758 880 880 PJ_DEF(pj_status_t) pj_atomic_destroy( pj_atomic_t *atomic_var ) 881 881 { 882 pj_status_t status; 883 882 884 PJ_ASSERT_RETURN(atomic_var, PJ_EINVAL); 883 #if PJ_HAS_THREADS 884 return pj_mutex_destroy( atomic_var->mutex ); 885 886 #if PJ_HAS_THREADS 887 status = pj_mutex_destroy( atomic_var->mutex ); 888 if (status == PJ_SUCCESS) { 889 atomic_var->mutex = NULL; 890 } 891 return status; 885 892 #else 886 893 return 0; … … 893 900 PJ_DEF(void) pj_atomic_set(pj_atomic_t *atomic_var, pj_atomic_value_t value) 894 901 { 902 pj_status_t status; 903 904 PJ_CHECK_STACK(); 905 PJ_ASSERT_ON_FAIL(atomic_var, return); 906 907 #if PJ_HAS_THREADS 908 status = pj_mutex_lock( atomic_var->mutex ); 909 if (status != PJ_SUCCESS) { 910 return; 911 } 912 #endif 913 atomic_var->value = value; 914 #if PJ_HAS_THREADS 915 pj_mutex_unlock( atomic_var->mutex); 916 #endif 917 } 918 919 /* 920 * pj_atomic_get() 921 */ 922 PJ_DEF(pj_atomic_value_t) pj_atomic_get(pj_atomic_t *atomic_var) 923 { 924 pj_atomic_value_t oldval; 925 895 926 PJ_CHECK_STACK(); 896 927 … … 898 929 pj_mutex_lock( atomic_var->mutex ); 899 930 #endif 900 atomic_var->value =value;931 oldval = atomic_var->value; 901 932 #if PJ_HAS_THREADS 902 933 pj_mutex_unlock( atomic_var->mutex); 903 934 #endif 904 } 905 906 /* 907 * pj_atomic_get() 908 */ 909 PJ_DEF(pj_atomic_value_t) pj_atomic_get(pj_atomic_t *atomic_var) 910 { 911 pj_atomic_value_t oldval; 935 return oldval; 936 } 937 938 /* 939 * pj_atomic_inc_and_get() 940 */ 941 PJ_DEF(pj_atomic_value_t) pj_atomic_inc_and_get(pj_atomic_t *atomic_var) 942 { 943 pj_atomic_value_t new_value; 912 944 913 945 PJ_CHECK_STACK(); … … 916 948 pj_mutex_lock( atomic_var->mutex ); 917 949 #endif 918 oldval =atomic_var->value;950 new_value = ++atomic_var->value; 919 951 #if PJ_HAS_THREADS 920 952 pj_mutex_unlock( atomic_var->mutex); 921 953 #endif 922 return oldval; 923 } 924 925 /* 926 * pj_atomic_inc_and_get() 927 */ 928 PJ_DEF(pj_atomic_value_t) pj_atomic_inc_and_get(pj_atomic_t *atomic_var) 954 955 return new_value; 956 } 957 /* 958 * pj_atomic_inc() 959 */ 960 PJ_DEF(void) pj_atomic_inc(pj_atomic_t *atomic_var) 961 { 962 PJ_ASSERT_ON_FAIL(atomic_var, return); 963 pj_atomic_inc_and_get(atomic_var); 964 } 965 966 /* 967 * pj_atomic_dec_and_get() 968 */ 969 PJ_DEF(pj_atomic_value_t) pj_atomic_dec_and_get(pj_atomic_t *atomic_var) 929 970 { 930 971 pj_atomic_value_t new_value; … … 935 976 pj_mutex_lock( atomic_var->mutex ); 936 977 #endif 937 new_value = ++atomic_var->value;978 new_value = --atomic_var->value; 938 979 #if PJ_HAS_THREADS 939 980 pj_mutex_unlock( atomic_var->mutex); … … 942 983 return new_value; 943 984 } 944 /*945 * pj_atomic_inc()946 */947 PJ_DEF(void) pj_atomic_inc(pj_atomic_t *atomic_var)948 {949 pj_atomic_inc_and_get(atomic_var);950 }951 952 /*953 * pj_atomic_dec_and_get()954 */955 PJ_DEF(pj_atomic_value_t) pj_atomic_dec_and_get(pj_atomic_t *atomic_var)956 {957 pj_atomic_value_t new_value;958 959 PJ_CHECK_STACK();960 961 #if PJ_HAS_THREADS962 pj_mutex_lock( atomic_var->mutex );963 #endif964 new_value = --atomic_var->value;965 #if PJ_HAS_THREADS966 pj_mutex_unlock( atomic_var->mutex);967 #endif968 969 return new_value;970 }971 985 972 986 /* … … 975 989 PJ_DEF(void) pj_atomic_dec(pj_atomic_t *atomic_var) 976 990 { 991 PJ_ASSERT_ON_FAIL(atomic_var, return); 977 992 pj_atomic_dec_and_get(atomic_var); 978 993 } … … 1006 1021 pj_atomic_value_t value ) 1007 1022 { 1023 PJ_ASSERT_ON_FAIL(atomic_var, return); 1008 1024 pj_atomic_add_and_get(atomic_var, value); 1009 1025 } -
pjproject/trunk/pjlib/src/pj/os_core_win32.c
r5539 r5758 751 751 { 752 752 PJ_CHECK_STACK(); 753 PJ_ASSERT_ON_FAIL(atomic_var, return); 753 754 754 755 InterlockedExchange(&atomic_var->value, value); … … 785 786 PJ_DEF(void) pj_atomic_inc(pj_atomic_t *atomic_var) 786 787 { 788 PJ_ASSERT_ON_FAIL(atomic_var, return); 787 789 pj_atomic_inc_and_get(atomic_var); 788 790 } … … 807 809 PJ_DEF(void) pj_atomic_dec(pj_atomic_t *atomic_var) 808 810 { 811 PJ_ASSERT_ON_FAIL(atomic_var, return); 809 812 pj_atomic_dec_and_get(atomic_var); 810 813 } … … 816 819 pj_atomic_value_t value ) 817 820 { 821 PJ_ASSERT_ON_FAIL(atomic_var, return); 818 822 #if defined(PJ_WIN32_WINNT) && PJ_WIN32_WINNT >= 0x0400 819 823 InterlockedExchangeAdd( &atomic_var->value, value );
Note: See TracChangeset
for help on using the changeset viewer.