@@ -614,7 +614,7 @@ LIBYANG_API_DEF LY_ERR
614614ly_ctx_set_options (struct ly_ctx * ctx , uint32_t option )
615615{
616616 LY_ERR lyrc = LY_SUCCESS ;
617- struct ly_ctx_private_data * ctx_data ;
617+ struct ly_ctx_shared_data * ctx_data ;
618618 struct lys_module * mod ;
619619 uint32_t i ;
620620
@@ -637,7 +637,8 @@ ly_ctx_set_options(struct ly_ctx *ctx, uint32_t option)
637637 }
638638
639639 if (!(ctx -> opts & LY_CTX_LEAFREF_LINKING ) && (option & LY_CTX_LEAFREF_LINKING )) {
640- ctx_data = ly_ctx_private_data_get (ctx );
640+ /* context is not printed (ctx data cant be shared with any other ctx), so no need to hold a lock */
641+ ctx_data = ly_ctx_shared_data_get (ctx );
641642 ctx_data -> leafref_links_ht = lyht_new (1 , sizeof (struct lyd_leafref_links_rec * ), ly_ctx_ht_leafref_links_equal_cb , NULL , 1 );
642643 LY_CHECK_ERR_RET (!ctx_data -> leafref_links_ht , LOGARG (ctx , option ), LY_EMEM );
643644 }
@@ -699,13 +700,14 @@ ly_ctx_unset_options(struct ly_ctx *ctx, uint32_t option)
699700 LY_ARRAY_COUNT_TYPE u , v ;
700701 const struct lysc_ext_instance * ext ;
701702 struct lysc_node * root ;
702- struct ly_ctx_private_data * ctx_data ;
703+ struct ly_ctx_shared_data * ctx_data ;
703704
704705 LY_CHECK_ARG_RET (ctx , ctx , !(ctx -> opts & LY_CTX_INT_IMMUTABLE ), LY_EINVAL );
705706 LY_CHECK_ERR_RET (option & LY_CTX_NO_YANGLIBRARY , LOGARG (ctx , option ), LY_EINVAL );
706707
707708 if ((ctx -> opts & LY_CTX_LEAFREF_LINKING ) && (option & LY_CTX_LEAFREF_LINKING )) {
708- ctx_data = ly_ctx_private_data_get (ctx );
709+ /* context is not printed (ctx data cant be shared with any other ctx), so no need to hold a lock */
710+ ctx_data = ly_ctx_shared_data_get (ctx );
709711 lyht_free (ctx_data -> leafref_links_ht , ly_ctx_ht_leafref_links_rec_free );
710712 ctx_data -> leafref_links_ht = NULL ;
711713 }
@@ -828,16 +830,23 @@ ly_ctx_set_module_imp_clb(struct ly_ctx *ctx, ly_module_imp_clb clb, void *user_
828830LIBYANG_API_DEF ly_ext_data_clb
829831ly_ctx_set_ext_data_clb (const struct ly_ctx * ctx , ly_ext_data_clb clb , void * user_data )
830832{
831- struct ly_ctx_private_data * ctx_data ;
833+ struct ly_ctx_shared_data * ctx_data ;
832834 ly_ext_data_clb prev ;
833835
834836 LY_CHECK_ARG_RET (ctx , ctx , NULL );
835837
836- ctx_data = ly_ctx_private_data_get (ctx );
838+ ctx_data = ly_ctx_shared_data_get (ctx );
839+
840+ /* EXT CLB LOCK */
841+ pthread_mutex_lock (& ctx_data -> ext_clb_lock );
842+
837843 prev = ctx_data -> ext_clb ;
838844 ctx_data -> ext_clb = clb ;
839845 ctx_data -> ext_clb_data = user_data ;
840846
847+ /* EXT CLB UNLOCK */
848+ pthread_mutex_unlock (& ctx_data -> ext_clb_lock );
849+
841850 return prev ;
842851}
843852
0 commit comments