aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/DocBook/kernel-locking.tmpl
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/DocBook/kernel-locking.tmpl')
-rw-r--r--Documentation/DocBook/kernel-locking.tmpl32
1 files changed, 16 insertions, 16 deletions
diff --git a/Documentation/DocBook/kernel-locking.tmpl b/Documentation/DocBook/kernel-locking.tmpl
index 01825ee7db64..2e9d6b41f034 100644
--- a/Documentation/DocBook/kernel-locking.tmpl
+++ b/Documentation/DocBook/kernel-locking.tmpl
@@ -717,7 +717,7 @@ used, and when it gets full, throws out the least used one.
717 <para> 717 <para>
718For our first example, we assume that all operations are in user 718For our first example, we assume that all operations are in user
719context (ie. from system calls), so we can sleep. This means we can 719context (ie. from system calls), so we can sleep. This means we can
720use a semaphore to protect the cache and all the objects within 720use a mutex to protect the cache and all the objects within
721it. Here's the code: 721it. Here's the code:
722 </para> 722 </para>
723 723
@@ -725,7 +725,7 @@ it. Here's the code:
725#include &lt;linux/list.h&gt; 725#include &lt;linux/list.h&gt;
726#include &lt;linux/slab.h&gt; 726#include &lt;linux/slab.h&gt;
727#include &lt;linux/string.h&gt; 727#include &lt;linux/string.h&gt;
728#include &lt;asm/semaphore.h&gt; 728#include &lt;linux/mutex.h&gt;
729#include &lt;asm/errno.h&gt; 729#include &lt;asm/errno.h&gt;
730 730
731struct object 731struct object
@@ -737,7 +737,7 @@ struct object
737}; 737};
738 738
739/* Protects the cache, cache_num, and the objects within it */ 739/* Protects the cache, cache_num, and the objects within it */
740static DECLARE_MUTEX(cache_lock); 740static DEFINE_MUTEX(cache_lock);
741static LIST_HEAD(cache); 741static LIST_HEAD(cache);
742static unsigned int cache_num = 0; 742static unsigned int cache_num = 0;
743#define MAX_CACHE_SIZE 10 743#define MAX_CACHE_SIZE 10
@@ -789,17 +789,17 @@ int cache_add(int id, const char *name)
789 obj-&gt;id = id; 789 obj-&gt;id = id;
790 obj-&gt;popularity = 0; 790 obj-&gt;popularity = 0;
791 791
792 down(&amp;cache_lock); 792 mutex_lock(&amp;cache_lock);
793 __cache_add(obj); 793 __cache_add(obj);
794 up(&amp;cache_lock); 794 mutex_unlock(&amp;cache_lock);
795 return 0; 795 return 0;
796} 796}
797 797
798void cache_delete(int id) 798void cache_delete(int id)
799{ 799{
800 down(&amp;cache_lock); 800 mutex_lock(&amp;cache_lock);
801 __cache_delete(__cache_find(id)); 801 __cache_delete(__cache_find(id));
802 up(&amp;cache_lock); 802 mutex_unlock(&amp;cache_lock);
803} 803}
804 804
805int cache_find(int id, char *name) 805int cache_find(int id, char *name)
@@ -807,13 +807,13 @@ int cache_find(int id, char *name)
807 struct object *obj; 807 struct object *obj;
808 int ret = -ENOENT; 808 int ret = -ENOENT;
809 809
810 down(&amp;cache_lock); 810 mutex_lock(&amp;cache_lock);
811 obj = __cache_find(id); 811 obj = __cache_find(id);
812 if (obj) { 812 if (obj) {
813 ret = 0; 813 ret = 0;
814 strcpy(name, obj-&gt;name); 814 strcpy(name, obj-&gt;name);
815 } 815 }
816 up(&amp;cache_lock); 816 mutex_unlock(&amp;cache_lock);
817 return ret; 817 return ret;
818} 818}
819</programlisting> 819</programlisting>
@@ -853,7 +853,7 @@ The change is shown below, in standard patch format: the
853 int popularity; 853 int popularity;
854 }; 854 };
855 855
856-static DECLARE_MUTEX(cache_lock); 856-static DEFINE_MUTEX(cache_lock);
857+static spinlock_t cache_lock = SPIN_LOCK_UNLOCKED; 857+static spinlock_t cache_lock = SPIN_LOCK_UNLOCKED;
858 static LIST_HEAD(cache); 858 static LIST_HEAD(cache);
859 static unsigned int cache_num = 0; 859 static unsigned int cache_num = 0;
@@ -870,22 +870,22 @@ The change is shown below, in standard patch format: the
870 obj-&gt;id = id; 870 obj-&gt;id = id;
871 obj-&gt;popularity = 0; 871 obj-&gt;popularity = 0;
872 872
873- down(&amp;cache_lock); 873- mutex_lock(&amp;cache_lock);
874+ spin_lock_irqsave(&amp;cache_lock, flags); 874+ spin_lock_irqsave(&amp;cache_lock, flags);
875 __cache_add(obj); 875 __cache_add(obj);
876- up(&amp;cache_lock); 876- mutex_unlock(&amp;cache_lock);
877+ spin_unlock_irqrestore(&amp;cache_lock, flags); 877+ spin_unlock_irqrestore(&amp;cache_lock, flags);
878 return 0; 878 return 0;
879 } 879 }
880 880
881 void cache_delete(int id) 881 void cache_delete(int id)
882 { 882 {
883- down(&amp;cache_lock); 883- mutex_lock(&amp;cache_lock);
884+ unsigned long flags; 884+ unsigned long flags;
885+ 885+
886+ spin_lock_irqsave(&amp;cache_lock, flags); 886+ spin_lock_irqsave(&amp;cache_lock, flags);
887 __cache_delete(__cache_find(id)); 887 __cache_delete(__cache_find(id));
888- up(&amp;cache_lock); 888- mutex_unlock(&amp;cache_lock);
889+ spin_unlock_irqrestore(&amp;cache_lock, flags); 889+ spin_unlock_irqrestore(&amp;cache_lock, flags);
890 } 890 }
891 891
@@ -895,14 +895,14 @@ The change is shown below, in standard patch format: the
895 int ret = -ENOENT; 895 int ret = -ENOENT;
896+ unsigned long flags; 896+ unsigned long flags;
897 897
898- down(&amp;cache_lock); 898- mutex_lock(&amp;cache_lock);
899+ spin_lock_irqsave(&amp;cache_lock, flags); 899+ spin_lock_irqsave(&amp;cache_lock, flags);
900 obj = __cache_find(id); 900 obj = __cache_find(id);
901 if (obj) { 901 if (obj) {
902 ret = 0; 902 ret = 0;
903 strcpy(name, obj-&gt;name); 903 strcpy(name, obj-&gt;name);
904 } 904 }
905- up(&amp;cache_lock); 905- mutex_unlock(&amp;cache_lock);
906+ spin_unlock_irqrestore(&amp;cache_lock, flags); 906+ spin_unlock_irqrestore(&amp;cache_lock, flags);
907 return ret; 907 return ret;
908 } 908 }