[FIX] Spinlock flags problem
authorAlexander Aksenov <a.aksenov@samsung.com>
Tue, 25 Jun 2013 12:37:22 +0000 (16:37 +0400)
committerAlexander Aksenov <a.aksenov@samsung.com>
Tue, 25 Jun 2013 12:37:22 +0000 (16:37 +0400)
buffer/buffer_description.h
buffer/buffer_queue.c
buffer/kernel_operations.h

index 033e7a4..988c780 100644 (file)
@@ -37,7 +37,7 @@ struct swap_subbuffer {
        /* Pointer to data buffer */
        swap_subbuffer_ptr data_buffer;
        /* Buffer rw sync */
-       sync_t buffer_sync;
+       struct sync_t buffer_sync;
 };
 
 #endif /* __BUFFER_DESCRIPTION_H__ */
index 2966cd1..8c768df 100644 (file)
 struct queue {
        struct swap_subbuffer *start_ptr;
        struct swap_subbuffer *end_ptr;
-       sync_t queue_sync;
+       struct sync_t queue_sync;
 };
 
 /* Write queue */
 struct queue write_queue = {
        .start_ptr = NULL,
-       .end_ptr = NULL
+       .end_ptr = NULL,
+       .queue_sync = {
+               .flags = 0x0
+       }
 };
 
 /* Read queue */
 struct queue read_queue = {
        .start_ptr = NULL,
-       .end_ptr = NULL
+       .end_ptr = NULL,
+       .queue_sync = {
+               .flags = 0x0
+       }
 };
 
 /* Pointers array. Points to busy buffers */
-static struct swap_buffer **queue_busy = NULL;
+static struct swap_subbuffer **queue_busy = NULL;
 
 /* Store last busy element */
 static unsigned int queue_busy_last_element;
@@ -79,7 +85,9 @@ static unsigned int queue_subbuffer_count = 0;
 static size_t queue_subbuffer_size = 0;
 
 /* Busy list sync */
-static sync_t buffer_busy_sync;
+static struct sync_t buffer_busy_sync = {
+       .flags = 0x0
+};
 
 /* Memory pages count in one subbuffer */
 static int pages_order_in_subbuffer = 0;
@@ -323,7 +331,10 @@ struct swap_subbuffer *get_from_write_list(size_t size, void **ptr_to_write)
        /* Callbacks are called at the end of the function to prevent deadlocks */
        struct queue callback_queue = {
                .start_ptr = NULL,
-               .end_ptr = NULL
+               .end_ptr = NULL,
+               .queue_sync = {
+                       .flags = 0x0
+               }
        };
        struct swap_subbuffer *tmp_buffer = NULL;
 
@@ -357,7 +368,6 @@ struct swap_subbuffer *get_from_write_list(size_t size, void **ptr_to_write)
                        break;
                /* This subbuffer is not enough => it goes to read list */
                } else {
-
                        result = write_queue.start_ptr;
 
                        /* If we reached end of the list */
index df9d343..1c41f98 100644 (file)
 #include <linux/mm.h>
 
 
+
+/* MESSAGES */
+#define print_debug(msg, args...) \
+       printk(KERN_DEBUG "SWAP_BUFFER DEBUG : " msg, ##args)
+#define print_msg(msg, args...)   \
+       printk(KERN_INFO "SWAP_BUFFER : " msg, ##args)
+#define print_warn(msg, args...)  \
+       printk(KERN_WARNING "SWAP_BUFFER WARNING : " msg, ##args)
+#define print_err(msg, args...)   \
+       printk(KERN_ERR "SWAP_BUFFER ERROR : " msg, ##args)
+#define print_crit(msg, args...)  \
+       printk(KERN_CRIT "SWAP_BUFFER CRITICAL : " msg, ##args)
+
+
+
+
 /* LOCKS */
 
 /* Using spinlocks as sync primitives */
-typedef spinlock_t sync_t;
-
-/* Spinlock flags */
-static unsigned long flags;
+struct sync_t {
+       spinlock_t spinlock;
+       unsigned long flags;
+};
 
 /* Spinlocks initialization */
-static inline void sync_init(sync_t *buffer_sync)
+static inline void sync_init(struct sync_t *buffer_sync)
 {
-       spin_lock_init(buffer_sync);
+       spin_lock_init(&buffer_sync->spinlock);
 }
 
 /* Lock spinlock */
-static inline void sync_lock(sync_t *buffer_sync)
+static inline void sync_lock(struct sync_t *buffer_sync)
 {
-       spin_lock_irqsave(buffer_sync, flags);
+       spin_lock_irqsave(&buffer_sync->spinlock, buffer_sync->flags);
 }
 
 /* Unlock spinlock */
-static inline void sync_unlock(sync_t *buffer_sync)
+static inline void sync_unlock(struct sync_t *buffer_sync)
 {
-       spin_unlock_irqrestore(buffer_sync, flags);
+       spin_unlock_irqrestore(&buffer_sync->spinlock, buffer_sync->flags);
 }
 
 
@@ -120,17 +136,4 @@ static inline unsigned int get_order_for_alloc_pages(size_t memory_size)
        return nearest_power_of_two(aligned_size / PAGE_SIZE);
 }
 
-
-/* MESSAGES */
-#define print_debug(msg, args...) \
-       printk(KERN_DEBUG "SWAP_BUFFER DEBUG : " msg, ##args)
-#define print_msg(msg, args...)   \
-       printk(KERN_INFO "SWAP_BUFFER : " msg, ##args)
-#define print_warn(msg, args...)  \
-       printk(KERN_WARNING "SWAP_BUFFER WARNING : " msg, ##args)
-#define print_err(msg, args...)   \
-       printk(KERN_ERR "SWAP_BUFFER ERROR : " msg, ##args)
-#define print_crit(msg, args...)  \
-       printk(KERN_CRIT "SWAP_BUFFER CRITICAL : " msg, ##args)
-
 #endif /* __KERNEL_OPERATIONS_H__ */