public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* semaphore understanding: sys_semtimedop()
@ 2005-05-16 20:17 Patrick Plattes
  2005-05-22  5:21 ` randy_dunlap
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Plattes @ 2005-05-16 20:17 UTC (permalink / raw)
  To: linux-kernel

Hello,

i have a question about this little code snippet, found in
sys_semtimedop() (ipc/sem.c):

        for (sop = sops; sop < sops + nsops; sop++) {
                if (sop->sem_num >= max)
                        max = sop->sem_num;
                if (sop->sem_flg & SEM_UNDO)
                        undos++;
                if (sop->sem_op < 0)
                        decrease = 1;
                if (sop->sem_op > 0)
                        alter = 1;
        }
        alter |= decrease;

The variable decrease will never be used again in this 
function, so why this intricate code? Isn't this much easier and works
also:

        for (sop = sops; sop < sops + nsops; sop++) {
                if (sop->sem_num >= max)
                        max = sop->sem_num;
                if (sop->sem_flg & SEM_UNDO)
                        undos++;
                if (sop->sem_op != 0)
                        alter = 1;
        }

Maybe i'm totally wrong, so please correct me and don't shoot me up,
'cause i'm not a os developer.

Thanks,
  Patrick

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

* Re: semaphore understanding: sys_semtimedop()
  2005-05-16 20:17 semaphore understanding: sys_semtimedop() Patrick Plattes
@ 2005-05-22  5:21 ` randy_dunlap
  2005-05-22  6:49   ` Manfred Spraul
  0 siblings, 1 reply; 3+ messages in thread
From: randy_dunlap @ 2005-05-22  5:21 UTC (permalink / raw)
  To: Patrick Plattes; +Cc: linux-kernel, manfred

On Mon, 16 May 2005 22:17:04 +0200 Patrick Plattes wrote:

| Hello,
| 
| i have a question about this little code snippet, found in
| sys_semtimedop() (ipc/sem.c):
| 
|         for (sop = sops; sop < sops + nsops; sop++) {
|                 if (sop->sem_num >= max)
|                         max = sop->sem_num;
|                 if (sop->sem_flg & SEM_UNDO)
|                         undos++;
|                 if (sop->sem_op < 0)
|                         decrease = 1;
|                 if (sop->sem_op > 0)
|                         alter = 1;
|         }
|         alter |= decrease;
| 
| The variable decrease will never be used again in this 
| function, so why this intricate code? Isn't this much easier and works
| also:
| 
|         for (sop = sops; sop < sops + nsops; sop++) {
|                 if (sop->sem_num >= max)
|                         max = sop->sem_num;
|                 if (sop->sem_flg & SEM_UNDO)
|                         undos++;
|                 if (sop->sem_op != 0)
|                         alter = 1;
|         }
| 
| Maybe i'm totally wrong, so please correct me and don't shoot me up,
| 'cause i'm not a os developer.

Looks like a reasonable and correct optimization to me.

Let's see what Manfred thinks or has to say...

---
~Randy

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

* Re: semaphore understanding: sys_semtimedop()
  2005-05-22  5:21 ` randy_dunlap
@ 2005-05-22  6:49   ` Manfred Spraul
  0 siblings, 0 replies; 3+ messages in thread
From: Manfred Spraul @ 2005-05-22  6:49 UTC (permalink / raw)
  To: randy_dunlap; +Cc: Patrick Plattes, linux-kernel

randy_dunlap wrote:

>On Mon, 16 May 2005 22:17:04 +0200 Patrick Plattes wrote:
>
>| The variable decrease will never be used again in this 
>| function, so why this intricate code? Isn't this much easier and works
>| also:
>| 
>|         for (sop = sops; sop < sops + nsops; sop++) {
>|                 if (sop->sem_num >= max)
>|                         max = sop->sem_num;
>|                 if (sop->sem_flg & SEM_UNDO)
>|                         undos++;
>|                 if (sop->sem_op != 0)
>|                         alter = 1;
>|         }
>| 
>| Maybe i'm totally wrong, so please correct me and don't shoot me up,
>| 'cause i'm not a os developer.
>
>Looks like a reasonable and correct optimization to me.
>
>  
>
It looks correct:
decrease was added during 2.1 development: it's not in 2.0.40, it's in 
2.2.26: I think the idea was that operations with decrease can cause 
other threads to block, therefore a different wakeup strategy was used. 
The wakeup implementation was rewritten, but the loop remained unchanged.
I'll write a patch, thanks Patrick.

--
    Manfred

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

end of thread, other threads:[~2005-05-22  6:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-16 20:17 semaphore understanding: sys_semtimedop() Patrick Plattes
2005-05-22  5:21 ` randy_dunlap
2005-05-22  6:49   ` Manfred Spraul

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