config REFACTOR built-in atomics implement memoery barrier
diff --git a/src/config.h.in b/src/config.h.in
index b96e54d..7f4257d 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -25,8 +25,8 @@
 #define LYPLG_EXT_DIR "@PLUGINS_DIR_TYPES@"
 
 /** atomic compiler operations, to be able to use uint32_t */
-#define LY_ATOMIC_INC_RELAXED(var) __sync_fetch_and_add(&(var), 1)
-#define LY_ATOMIC_DEC_RELAXED(var) __sync_fetch_and_sub(&(var), 1)
+#define LY_ATOMIC_INC_BARRIER(var) __sync_fetch_and_add(&(var), 1)
+#define LY_ATOMIC_DEC_BARRIER(var) __sync_fetch_and_sub(&(var), 1)
 
 /** printf compiler attribute */
 #if (@CMAKE_C_COMPILER_ID@ == GNU) || (@CMAKE_C_COMPILER_ID@ == Clang)
diff --git a/src/path.c b/src/path.c
index 83b1ba3..f2b713c 100644
--- a/src/path.c
+++ b/src/path.c
@@ -552,7 +552,7 @@
             ++(*tok_idx);
 
             /* "allocate" the type to avoid problems when freeing the value after the type was freed */
-            LY_ATOMIC_INC_RELAXED(((struct lysc_type *)p->value.realtype)->refcount);
+            LY_ATOMIC_INC_BARRIER(((struct lysc_type *)p->value.realtype)->refcount);
 
             /* ']' */
             assert(expr->tokens[*tok_idx] == LYXP_TOKEN_BRACK2);
@@ -613,7 +613,7 @@
         ++(*tok_idx);
 
         /* "allocate" the type to avoid problems when freeing the value after the type was freed */
-        LY_ATOMIC_INC_RELAXED(((struct lysc_type *)p->value.realtype)->refcount);
+        LY_ATOMIC_INC_BARRIER(((struct lysc_type *)p->value.realtype)->refcount);
 
         /* ']' */
         assert(expr->tokens[*tok_idx] == LYXP_TOKEN_BRACK2);
@@ -1105,7 +1105,7 @@
                     /* key-predicate or leaf-list-predicate */
                     (*dup)[u].predicates[v].key = pred->key;
                     pred->value.realtype->plugin->duplicate(ctx, &pred->value, &(*dup)[u].predicates[v].value);
-                    LY_ATOMIC_INC_RELAXED(((struct lysc_type *)pred->value.realtype)->refcount);
+                    LY_ATOMIC_INC_BARRIER(((struct lysc_type *)pred->value.realtype)->refcount);
                     break;
                 case LY_PATH_PREDTYPE_NONE:
                     break;
diff --git a/src/schema_compile.c b/src/schema_compile.c
index f8ee4b7..bef6229 100644
--- a/src/schema_compile.c
+++ b/src/schema_compile.c
@@ -1067,7 +1067,7 @@
         return ret;
     }
 
-    LY_ATOMIC_INC_RELAXED(((struct lysc_type *)storage->realtype)->refcount);
+    LY_ATOMIC_INC_BARRIER(((struct lysc_type *)storage->realtype)->refcount);
     return LY_SUCCESS;
 }
 
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index 2a75a1a..68fabd0 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -1433,7 +1433,7 @@
 
                 } else {
                     utypes[u + additional] = un_aux->types[v];
-                    LY_ATOMIC_INC_RELAXED(un_aux->types[v]->refcount);
+                    LY_ATOMIC_INC_BARRIER(un_aux->types[v]->refcount);
                 }
                 ++additional;
                 LY_ARRAY_INCREMENT(utypes);
@@ -2009,11 +2009,11 @@
                 (plugin == base->plugin)) {
             /* no change, reuse the compiled base */
             ((struct lysp_tpdf *)tctx->tpdf)->type.compiled = base;
-            LY_ATOMIC_INC_RELAXED(base->refcount);
+            LY_ATOMIC_INC_BARRIER(base->refcount);
             continue;
         }
 
-        LY_ATOMIC_INC_RELAXED((*type)->refcount);
+        LY_ATOMIC_INC_BARRIER((*type)->refcount);
         if (~type_substmt_map[basetype] & tctx->tpdf->type.flags) {
             LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG, "Invalid type \"%s\" restriction(s) for %s type.",
                     tctx->tpdf->name, ly_data_type2str[basetype]);
@@ -2048,14 +2048,14 @@
         /* get restrictions from the node itself */
         (*type)->basetype = basetype;
         (*type)->plugin = base ? base->plugin : lyplg_find(LYPLG_TYPE, "", NULL, ly_data_type2str[basetype]);
-        LY_ATOMIC_INC_RELAXED((*type)->refcount);
+        LY_ATOMIC_INC_BARRIER((*type)->refcount);
         ret = lys_compile_type_(ctx, context_pnode, context_flags, context_name, type_p, basetype, NULL, base, type);
         LY_CHECK_GOTO(ret, cleanup);
     } else if ((basetype != LY_TYPE_BOOL) && (basetype != LY_TYPE_EMPTY)) {
         /* no specific restriction in leaf's type definition, copy from the base */
         free(*type);
         (*type) = base;
-        LY_ATOMIC_INC_RELAXED((*type)->refcount);
+        LY_ATOMIC_INC_BARRIER((*type)->refcount);
     }
 
     COMPILE_EXTS_GOTO(ctx, type_p->exts, (*type)->exts, (*type), ret, cleanup);
diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c
index 6530557..7c4bf4c 100644
--- a/src/tree_schema_free.c
+++ b/src/tree_schema_free.c
@@ -666,7 +666,7 @@
 void
 lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type)
 {
-    if (LY_ATOMIC_DEC_RELAXED(type->refcount) > 1) {
+    if (LY_ATOMIC_INC_BARRIER(type->refcount) > 1) {
         return;
     }