[IMPROVE] add auxilary functions for feature_img_list
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 17 Oct 2013 10:19:44 +0000 (14:19 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 17 Oct 2013 12:01:08 +0000 (16:01 +0400)
that synchronize the add/del from feature_img_list

Change-Id: Ib2303d03fd7d9408a2b903690b3d20bca948f7ad
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
us_manager/sspt/sspt_feature.c

index 9d6eaa0..8c468f4 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/list.h>
+#include <linux/spinlock.h>
 
 
 struct sspt_feature {
@@ -46,7 +47,8 @@ struct sspt_feature_data {
        void *data;
 };
 
-static LIST_HEAD(feature_list);
+static DEFINE_SPINLOCK(feature_img_lock);
+static LIST_HEAD(feature_img_list);
 
 static struct sspt_feature_data *create_feature_data(struct sspt_feature_img *img)
 {
@@ -74,17 +76,20 @@ struct sspt_feature *sspt_create_feature(void)
 
        f = kmalloc(sizeof(*f), GFP_ATOMIC);
        if (f) {
-               INIT_LIST_HEAD(&f->feature_list);
-
                struct sspt_feature_data *fd;
                struct sspt_feature_img *fi;
+               unsigned long flags;
+
+               INIT_LIST_HEAD(&f->feature_list);
 
-               list_for_each_entry(fi, &feature_list, list) {
+               spin_lock_irqsave(&feature_img_lock, flags);
+               list_for_each_entry(fi, &feature_img_list, list) {
                        fd = create_feature_data(fi);
 
                        /* add to list */
                        list_add(&fd->list, &f->feature_list);
                }
+               spin_unlock_irqrestore(&feature_img_lock, flags);
        }
 
        return f;
@@ -103,6 +108,24 @@ void sspt_destroy_feature(struct sspt_feature *f)
        kfree(f);
 }
 
+static void add_feature_img_to_list(struct sspt_feature_img *fi)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&feature_img_lock, flags);
+       list_add(&fi->list, &feature_img_list);
+       spin_unlock_irqrestore(&feature_img_lock, flags);
+}
+
+static void del_feature_img_from_list(struct sspt_feature_img *fi)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&feature_img_lock, flags);
+       list_del(&fi->list);
+       spin_unlock_irqrestore(&feature_img_lock, flags);
+}
+
 static struct sspt_feature_img *create_feature_img(void *(*alloc)(void),
                                                   void (*free)(void *data))
 {
@@ -114,8 +137,7 @@ static struct sspt_feature_img *create_feature_img(void *(*alloc)(void),
                fi->alloc = alloc;
                fi->free = free;
 
-               /* add to list */
-               list_add(&fi->list, &feature_list);
+               add_feature_img_to_list(fi);
        }
 
        return fi;
@@ -123,8 +145,7 @@ static struct sspt_feature_img *create_feature_img(void *(*alloc)(void),
 
 static void destroy_feature_img(struct sspt_feature_img *fi)
 {
-       /* delete from list */
-       list_del(&fi->list);
+       del_feature_img_from_list(fi);
 
        kfree(fi);
 }