public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] documentation: Make sample code and documentation consistent
@ 2016-03-07  8:02 Yao Dongdong
  2016-03-07 19:58 ` Paul E. McKenney
  0 siblings, 1 reply; 2+ messages in thread
From: Yao Dongdong @ 2016-03-07  8:02 UTC (permalink / raw)
  To: paulmck, josh, corbet; +Cc: linux-kernel, linux-doc

In the chapter 'analogy with reader-writer locking', the sample
code uses spinlock_t in reader-writer case. Just correct it so
that we can read the document easily.

Signed-off-by: Yao Dongdong <yaodongdong@huawei.com>
---
 Documentation/RCU/whatisRCU.txt |   22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt
index dc49c67..e33304e 100644
--- a/Documentation/RCU/whatisRCU.txt
+++ b/Documentation/RCU/whatisRCU.txt
@@ -681,22 +681,30 @@ Although RCU can be used in many different ways, a very common use of
 RCU is analogous to reader-writer locking.  The following unified
 diff shows how closely related RCU and reader-writer locking can be.

+	@@ -5,5 +5,5 @@ struct el {
+		int data;
+		/* Other data fields */
+	};
+	-rwlock_t listmutex;
+	+spinlock_t listmutex;
+	struct el head;
+
 	@@ -13,15 +14,15 @@
 		struct list_head *lp;
 		struct el *p;

-	-	read_lock();
+	-	read_lock(&listmutex);
 	-	list_for_each_entry(p, head, lp) {
 	+	rcu_read_lock();
 	+	list_for_each_entry_rcu(p, head, lp) {
 			if (p->key == key) {
 				*result = p->data;
-	-			read_unlock();
+	-			read_unlock(&listmutex);
 	+			rcu_read_unlock();
 				return 1;
 			}
 		}
-	-	read_unlock();
+	-	read_unlock(&listmutex);
 	+	rcu_read_unlock();
 		return 0;
 	 }
@@ -732,7 +740,7 @@ Or, for those who prefer a side-by-side listing:
  5   int data;                          5   int data;
  6   /* Other data fields */            6   /* Other data fields */
  7 };                                   7 };
- 8 spinlock_t listmutex;                8 spinlock_t listmutex;
+ 8 rwlock_t listmutex;                  8 spinlock_t listmutex;
  9 struct el head;                      9 struct el head;

  1 int search(long key, int *result)    1 int search(long key, int *result)
@@ -740,15 +748,15 @@ Or, for those who prefer a side-by-side listing:
  3   struct list_head *lp;              3   struct list_head *lp;
  4   struct el *p;                      4   struct el *p;
  5                                      5
- 6   read_lock();                       6   rcu_read_lock();
+ 6   read_lock(&listmutex);             6   rcu_read_lock();
  7   list_for_each_entry(p, head, lp) { 7   list_for_each_entry_rcu(p, head, lp) {
  8     if (p->key == key) {             8     if (p->key == key) {
  9       *result = p->data;             9       *result = p->data;
-10       read_unlock();                10       rcu_read_unlock();
+10       read_unlock(&listmutex);      10       rcu_read_unlock();
 11       return 1;                     11       return 1;
 12     }                               12     }
 13   }                                 13   }
-14   read_unlock();                    14   rcu_read_unlock();
+14   read_unlock(&listmutex);          14   rcu_read_unlock();
 15   return 0;                         15   return 0;
 16 }                                   16 }

--
1.7.9.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] documentation: Make sample code and documentation consistent
  2016-03-07  8:02 [PATCH] documentation: Make sample code and documentation consistent Yao Dongdong
@ 2016-03-07 19:58 ` Paul E. McKenney
  0 siblings, 0 replies; 2+ messages in thread
From: Paul E. McKenney @ 2016-03-07 19:58 UTC (permalink / raw)
  To: Yao Dongdong; +Cc: josh, corbet, linux-kernel, linux-doc

On Mon, Mar 07, 2016 at 04:02:14PM +0800, Yao Dongdong wrote:
> In the chapter 'analogy with reader-writer locking', the sample
> code uses spinlock_t in reader-writer case. Just correct it so
> that we can read the document easily.
> 
> Signed-off-by: Yao Dongdong <yaodongdong@huawei.com>

Good catch, queued for review.

							Thanx, Paul

> ---
>  Documentation/RCU/whatisRCU.txt |   22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt
> index dc49c67..e33304e 100644
> --- a/Documentation/RCU/whatisRCU.txt
> +++ b/Documentation/RCU/whatisRCU.txt
> @@ -681,22 +681,30 @@ Although RCU can be used in many different ways, a very common use of
>  RCU is analogous to reader-writer locking.  The following unified
>  diff shows how closely related RCU and reader-writer locking can be.
> 
> +	@@ -5,5 +5,5 @@ struct el {
> +		int data;
> +		/* Other data fields */
> +	};
> +	-rwlock_t listmutex;
> +	+spinlock_t listmutex;
> +	struct el head;
> +
>  	@@ -13,15 +14,15 @@
>  		struct list_head *lp;
>  		struct el *p;
> 
> -	-	read_lock();
> +	-	read_lock(&listmutex);
>  	-	list_for_each_entry(p, head, lp) {
>  	+	rcu_read_lock();
>  	+	list_for_each_entry_rcu(p, head, lp) {
>  			if (p->key == key) {
>  				*result = p->data;
> -	-			read_unlock();
> +	-			read_unlock(&listmutex);
>  	+			rcu_read_unlock();
>  				return 1;
>  			}
>  		}
> -	-	read_unlock();
> +	-	read_unlock(&listmutex);
>  	+	rcu_read_unlock();
>  		return 0;
>  	 }
> @@ -732,7 +740,7 @@ Or, for those who prefer a side-by-side listing:
>   5   int data;                          5   int data;
>   6   /* Other data fields */            6   /* Other data fields */
>   7 };                                   7 };
> - 8 spinlock_t listmutex;                8 spinlock_t listmutex;
> + 8 rwlock_t listmutex;                  8 spinlock_t listmutex;
>   9 struct el head;                      9 struct el head;
> 
>   1 int search(long key, int *result)    1 int search(long key, int *result)
> @@ -740,15 +748,15 @@ Or, for those who prefer a side-by-side listing:
>   3   struct list_head *lp;              3   struct list_head *lp;
>   4   struct el *p;                      4   struct el *p;
>   5                                      5
> - 6   read_lock();                       6   rcu_read_lock();
> + 6   read_lock(&listmutex);             6   rcu_read_lock();
>   7   list_for_each_entry(p, head, lp) { 7   list_for_each_entry_rcu(p, head, lp) {
>   8     if (p->key == key) {             8     if (p->key == key) {
>   9       *result = p->data;             9       *result = p->data;
> -10       read_unlock();                10       rcu_read_unlock();
> +10       read_unlock(&listmutex);      10       rcu_read_unlock();
>  11       return 1;                     11       return 1;
>  12     }                               12     }
>  13   }                                 13   }
> -14   read_unlock();                    14   rcu_read_unlock();
> +14   read_unlock(&listmutex);          14   rcu_read_unlock();
>  15   return 0;                         15   return 0;
>  16 }                                   16 }
> 
> --
> 1.7.9.5
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-07 19:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-07  8:02 [PATCH] documentation: Make sample code and documentation consistent Yao Dongdong
2016-03-07 19:58 ` Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox