From: Zhushuai Yin <yinzhushuai@huawei.com> To improve performance, the lock scope is narrowed, and the mb() operation is added to ensure the visibility and ordering of shared data, thereby avoiding data races. Signed-off-by: Zhushuai Yin <yinzhushuai@huawei.com> --- src/uadk_aead.c | 1 + src/uadk_cipher.c | 1 + src/uadk_dh.c | 1 + src/uadk_digest.c | 1 + src/uadk_pkey.c | 1 + src/uadk_rsa.c | 1 + 6 files changed, 6 insertions(+) diff --git a/src/uadk_aead.c b/src/uadk_aead.c index 6920c04..db5faf7 100644 --- a/src/uadk_aead.c +++ b/src/uadk_aead.c @@ -263,6 +263,7 @@ static int uadk_e_init_aead_cipher(void) return UADK_E_FAIL; } + mb(); g_aead_engine.pid = getpid(); pthread_spin_unlock(&g_aead_engine.lock); free(dev); diff --git a/src/uadk_cipher.c b/src/uadk_cipher.c index 9029ece..4067fb6 100644 --- a/src/uadk_cipher.c +++ b/src/uadk_cipher.c @@ -448,6 +448,7 @@ static int uadk_e_init_cipher(void) if (ret) goto err_unlock; + mb(); g_cipher_engine.pid = getpid(); pthread_spin_unlock(&g_cipher_engine.lock); free(dev); diff --git a/src/uadk_dh.c b/src/uadk_dh.c index cae7d0a..e49250b 100644 --- a/src/uadk_dh.c +++ b/src/uadk_dh.c @@ -400,6 +400,7 @@ static int uadk_e_dh_init(void) } g_dh_res.numa_id = dev->numa_id; + mb(); g_dh_res.status = UADK_INIT_SUCCESS; pthread_spin_unlock(&g_dh_res.lock); free(dev); diff --git a/src/uadk_digest.c b/src/uadk_digest.c index 88e7fc8..c8372b4 100644 --- a/src/uadk_digest.c +++ b/src/uadk_digest.c @@ -523,6 +523,7 @@ static int uadk_e_init_digest(void) if (ret) goto err_unlock; + mb(); g_digest_engine.pid = getpid(); pthread_spin_unlock(&g_digest_engine.lock); free(dev); diff --git a/src/uadk_pkey.c b/src/uadk_pkey.c index fb45ccc..c5f711b 100644 --- a/src/uadk_pkey.c +++ b/src/uadk_pkey.c @@ -599,6 +599,7 @@ int uadk_init_ecc(void) } ecc_res.numa_id = dev->numa_id; + mb(); ecc_res.status = UADK_INIT_SUCCESS; pthread_spin_unlock(&ecc_res.lock); free(dev); diff --git a/src/uadk_rsa.c b/src/uadk_rsa.c index 160ab8c..318f8ed 100644 --- a/src/uadk_rsa.c +++ b/src/uadk_rsa.c @@ -849,6 +849,7 @@ static int uadk_e_rsa_init(void) } g_rsa_res.numa_id = dev->numa_id; + mb(); g_rsa_res.status = UADK_INIT_SUCCESS; pthread_spin_unlock(&g_rsa_res.lock); free(dev); -- 2.43.0