]> git.droids-corp.org - dpdk.git/commitdiff
raw/ifpga: fix thread closing
authorTianfei Zhang <tianfei.zhang@intel.com>
Mon, 24 Jan 2022 03:50:05 +0000 (22:50 -0500)
committerQi Zhang <qi.z.zhang@intel.com>
Tue, 25 Jan 2022 04:49:06 +0000 (05:49 +0100)
When we want to close a thread, we should set a flag to notify
thread handler function.

Fixes: 9c006c45d0c5 ("raw/ifpga: scan PCIe BDF device tree")
Cc: stable@dpdk.org
Signed-off-by: Tianfei Zhang <tianfei.zhang@intel.com>
Acked-by: Rosen Xu <rosen.xu@intel.com>
drivers/raw/ifpga/ifpga_rawdev.c

index 0eae0c9477b6102d6836d5a80d906bc5cff0612c..fdf3c23d2c5f5eb095458497a161feea288d0430 100644 (file)
@@ -497,7 +497,7 @@ ifpga_rawdev_gsd_handle(__rte_unused void *param)
        int gsd_enable, ret;
 #define MS 1000
 
-       while (1) {
+       while (__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
                gsd_enable = 0;
                for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
                        ifpga_rdev = &ifpga_rawdevices[i];
@@ -525,7 +525,7 @@ ifpga_monitor_start_func(void)
 {
        int ret;
 
-       if (ifpga_monitor_start == 0) {
+       if (!__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
                ret = rte_ctrl_thread_create(&ifpga_monitor_start_thread,
                                             "ifpga-monitor", NULL,
                                             ifpga_rawdev_gsd_handle, NULL);
@@ -534,7 +534,7 @@ ifpga_monitor_start_func(void)
                                "Fail to create ifpga monitor thread");
                        return -1;
                }
-               ifpga_monitor_start = 1;
+               __atomic_store_n(&ifpga_monitor_start, 1, __ATOMIC_RELAXED);
        }
 
        return 0;
@@ -544,7 +544,9 @@ ifpga_monitor_stop_func(void)
 {
        int ret;
 
-       if (ifpga_monitor_start == 1) {
+       if (__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
+               __atomic_store_n(&ifpga_monitor_start, 0, __ATOMIC_RELAXED);
+
                ret = pthread_cancel(ifpga_monitor_start_thread);
                if (ret)
                        IFPGA_RAWDEV_PMD_ERR("Can't cancel the thread");
@@ -553,8 +555,6 @@ ifpga_monitor_stop_func(void)
                if (ret)
                        IFPGA_RAWDEV_PMD_ERR("Can't join the thread");
 
-               ifpga_monitor_start = 0;
-
                return ret;
        }