__down_trylock : why call wake_up?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I am trying to udnerstand the code of semaphores..
following the function down_trylock .. i got to __down_trylock..

    spin_lock_irqsave(&semaphore_lock, flags);
    sleepers = sem->sleepers + 1;
    sem->sleepers = 0;

    /*
     * Add "everybody else" and us into it. They aren't
     * playing, because we own the spinlock.
     */
    if (!atomic_add_negative(sleepers, &sem->count))

----->>>   wake_up(&sem->wait);  <<<----

    spin_unlock_irqrestore(&semaphore_lock, flags);
    return 1;

Why is it waking up the sleeping process here? Isnt down_trylock supposed
to 'try to' acquire the sem, and if cant then to simply return imm.
And shouldnt wake_up be called only when 'releasing' a semaphore via the
up() function call?

-Learner


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux