فهرست منبع

【完善】链表操作前后加入开关中断操作

SummerGift 6 سال پیش
والد
کامیت
e18e23c9bd
1فایلهای تغییر یافته به همراه19 افزوده شده و 0 حذف شده
  1. 19 0
      src/lssdp_service.c

+ 19 - 0
src/lssdp_service.c

@@ -27,11 +27,17 @@ static int lssdp_service_register(struct lssdp_service *h)
 
     if (h == RT_NULL)
         return -RT_ERROR;
+    
+    /* enter interrupt */
+    rt_interrupt_enter();
 
     rt_slist_for_each(head, &_lssdp_list)
     {
         if (rt_strcmp(h->name, ((lssdp_service_t)head)->name) == 0)
         {
+            /* leave interrupt */
+            rt_interrupt_leave();
+
             LOG_E("service %s is already exists!", h->name );
             return -RT_ERROR;
         }
@@ -39,6 +45,9 @@ static int lssdp_service_register(struct lssdp_service *h)
 
     rt_slist_init(&h->list);
     rt_slist_append(&_lssdp_list, &h->list);
+    
+    /* leave interrupt */
+    rt_interrupt_leave();
 
     return RT_EOK;
 }
@@ -50,16 +59,26 @@ static int lssdp_service_unregister(struct lssdp_service *h)
 
     if (h == RT_NULL)
         return -RT_ERROR;
+    
+    /* enter interrupt */
+    rt_interrupt_enter();
 
     rt_slist_for_each(head, &_lssdp_list)
     {
         if (rt_strcmp(h->name, ((lssdp_service_t)head)->name) == 0)
         {
             rt_slist_remove(&_lssdp_list, head);
+            
+            /* leave interrupt */
+            rt_interrupt_leave();
+            
             rt_free(head);
             return RT_EOK;
         }
     }
+    
+    /* leave interrupt */
+    rt_interrupt_leave();
 
     LOG_E("Can't find service name %s to unregister", h->name);