diff --git a/HISTORY b/HISTORY index 6359c1d..72d0ab9 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,7 @@ +Version 1.47 2021-01-11 + * fc_atomic.h: add FC_ATOMIC_SET + Version 1.46 2020-12-29 * add function get_time_item_from_conf_ex * INI_FIND_ITEM just break instead of return diff --git a/libfastcommon.spec b/libfastcommon.spec index 955401b..6eac53f 100644 --- a/libfastcommon.spec +++ b/libfastcommon.spec @@ -62,5 +62,5 @@ rm -rf %{buildroot} /usr/include/fastcommon/* %changelog -* Mon Jun 23 2014 Zaixue Liao +* Mon Jun 23 2014 Zaixue Liao - first RPM release (1.0) diff --git a/src/fc_atomic.h b/src/fc_atomic.h index f700eac..08e8862 100644 --- a/src/fc_atomic.h +++ b/src/fc_atomic.h @@ -28,6 +28,18 @@ extern "C" { old_value = __sync_add_and_fetch(&var, 0); \ } while (new_value != old_value) +#define FC_ATOMIC_SET(var, new_value) \ + do { \ + typeof(var) _old_value; \ + _old_value = var; \ + do { \ + if (__sync_bool_compare_and_swap(&var, _old_value, new_value)) { \ + break; \ + } \ + _old_value = __sync_add_and_fetch(&var, 0); \ + } while (new_value != _old_value); \ + } while (0) + #ifdef __cplusplus } #endif