linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PPP synchronous tty: convert dead_sem to completion
@ 2007-12-08 15:09 Matthias Kaehlcke
  2007-12-09 17:04 ` Charlie Brady
  0 siblings, 1 reply; 3+ messages in thread
From: Matthias Kaehlcke @ 2007-12-08 15:09 UTC (permalink / raw)
  To: paulus, linux-ppp; +Cc: linux-kernel, Andrew Morton

PPP synchronous tty channel driver: convert the semaphore dead_sem to
a completion

Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>

--

diff --git a/drivers/net/ppp_synctty.c b/drivers/net/ppp_synctty.c
index f0c6a19..f7472c8 100644
--- a/drivers/net/ppp_synctty.c
+++ b/drivers/net/ppp_synctty.c
@@ -42,9 +42,9 @@
 #include <linux/if_ppp.h>
 #include <linux/ppp_channel.h>
 #include <linux/spinlock.h>
+#include <linux/completion.h>
 #include <linux/init.h>
 #include <asm/uaccess.h>
-#include <asm/semaphore.h>
 
 #define PPP_VERSION	"2.4.2"
 
@@ -70,7 +70,7 @@ struct syncppp {
 	struct tasklet_struct tsk;
 
 	atomic_t	refcnt;
-	struct semaphore dead_sem;
+	struct completion dead_cmp;
 	struct ppp_channel chan;	/* interface to generic ppp layer */
 };
 
@@ -195,7 +195,7 @@ static struct syncppp *sp_get(struct tty_struct *tty)
 static void sp_put(struct syncppp *ap)
 {
 	if (atomic_dec_and_test(&ap->refcnt))
-		up(&ap->dead_sem);
+		complete(&ap->dead_cmp);
 }
 
 /*
@@ -225,7 +225,7 @@ ppp_sync_open(struct tty_struct *tty)
 	tasklet_init(&ap->tsk, ppp_sync_process, (unsigned long) ap);
 
 	atomic_set(&ap->refcnt, 1);
-	init_MUTEX_LOCKED(&ap->dead_sem);
+	init_completion(&ap->dead_cmp);
 
 	ap->chan.private = ap;
 	ap->chan.ops = &sync_ops;
@@ -273,7 +273,7 @@ ppp_sync_close(struct tty_struct *tty)
 	 * by the time it returns.
 	 */
 	if (!atomic_dec_and_test(&ap->refcnt))
-		down(&ap->dead_sem);
+		wait_for_completion(&ap->dead_cmp);
 	tasklet_kill(&ap->tsk);
 
 	ppp_unregister_channel(&ap->chan);

-- 
Matthias Kaehlcke
Linux System Developer
Barcelona

      In itself, homosexuality is as limiting as heterosexuality: the
     ideal should be to be capable of loving a woman or a man; either,
      a human being, without  feeling fear, restraint, or obligation
                          (Simone de Beauvoir)
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-

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

* Re: [PATCH] PPP synchronous tty: convert dead_sem to completion
  2007-12-08 15:09 [PATCH] PPP synchronous tty: convert dead_sem to completion Matthias Kaehlcke
@ 2007-12-09 17:04 ` Charlie Brady
  2007-12-09 19:53   ` Matthias Kaehlcke
  0 siblings, 1 reply; 3+ messages in thread
From: Charlie Brady @ 2007-12-09 17:04 UTC (permalink / raw)
  To: Matthias Kaehlcke; +Cc: linux-ppp, linux-kernel


On Sat, 8 Dec 2007, Matthias Kaehlcke wrote:

> PPP synchronous tty channel driver: convert the semaphore dead_sem to
> a completion
>
> Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>

Excuse my ignorance please, but why is this a good idea? Should we not 
record the reason for changes?

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

* Re: [PATCH] PPP synchronous tty: convert dead_sem to completion
  2007-12-09 17:04 ` Charlie Brady
@ 2007-12-09 19:53   ` Matthias Kaehlcke
  0 siblings, 0 replies; 3+ messages in thread
From: Matthias Kaehlcke @ 2007-12-09 19:53 UTC (permalink / raw)
  To: Charlie Brady; +Cc: linux-ppp, linux-kernel

El Sun, Dec 09, 2007 at 12:04:48PM -0500 Charlie Brady ha dit:

>
> On Sat, 8 Dec 2007, Matthias Kaehlcke wrote:
>
>> PPP synchronous tty channel driver: convert the semaphore dead_sem to
>> a completion
>>
>> Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
>
> Excuse my ignorance please, but why is this a good idea? Should we not 
> record the reason for changes?

Semaphores can be used to signal completion of a job, but aren't the
optimal way to do so. According to LDD3 semaphores are optimized for
the 'available' case and performance suffers when using them as
completion. 

It is also clearer to use each synchronization mechanism according to
its purpose, i.e. semaphores for protection of critical sections and
completions for signalling that a job is done.

-- 
Matthias Kaehlcke
Linux System Developer
Barcelona

              You can't separate peace from freedom because no
               one can be at peace unless he has his freedom
                              (Malcolm X)
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-

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

end of thread, other threads:[~2007-12-09 19:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-08 15:09 [PATCH] PPP synchronous tty: convert dead_sem to completion Matthias Kaehlcke
2007-12-09 17:04 ` Charlie Brady
2007-12-09 19:53   ` Matthias Kaehlcke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).