Changeset 303c94c in mainline


Ignore:
Timestamp:
2006-03-23T21:13:37Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
38ee55b
Parents:
a0bb10ef
Message:

Improved futexes. (kernel part)

Location:
generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • generic/include/synch/futex.h

    ra0bb10ef r303c94c  
    4444
    4545extern void futex_init(void);
    46 extern __native sys_futex_sleep(__address uaddr);
     46extern __native sys_futex_sleep_timeout(__address uaddr, __u32 usec, int trydown);
    4747extern __native sys_futex_wakeup(__address uaddr);
    4848
  • generic/src/synch/futex.c

    ra0bb10ef r303c94c  
    3030 * Kernel backend for futexes.
    3131 * Deallocation of orphaned kernel-side futex structures is not currently implemented.
    32  * Timeouting futexes are currently not implemented.
    3332 */
    3433
    3534#include <synch/futex.h>
    3635#include <synch/rwlock.h>
     36#include <synch/spinlock.h>
    3737#include <synch/synch.h>
    3838#include <mm/frame.h>
    3939#include <mm/page.h>
    4040#include <mm/slab.h>
     41#include <proc/thread.h>
    4142#include <genarch/mm/page_pt.h>
    4243#include <genarch/mm/page_ht.h>
     
    9192 *
    9293 * @param uaddr Userspace address of the futex counter.
    93  *
    94  * @return One of ESYNCH_OK_ATOMIC and ESYNCH_OK_BLOCKED. See synch.h.
     94 * @param usec If non-zero, number of microseconds this thread is willing to sleep.
     95 * @param trydown If usec is zero and trydown is non-zero, conditional operation will be attempted.
     96 *
     97 * @return One of ESYNCH_TIMEOUT, ESYNCH_OK_ATOMIC and ESYNCH_OK_BLOCKED. See synch.h.
    9598 *         If there is no physical mapping for uaddr ENOENT is returned.
    9699 */
    97 __native sys_futex_sleep(__address uaddr)
     100__native sys_futex_sleep_timeout(__address uaddr, __u32 usec, int trydown)
    98101{
    99102        futex_t *futex;
     
    101104        link_t *item;
    102105        pte_t *t;
    103        
     106        ipl_t ipl;
     107       
     108        ipl = interrupts_disable();
     109
    104110        /*
    105111         * Find physical address of futex counter.
     
    109115        if (!t || !PTE_VALID(t) || !PTE_PRESENT(t)) {
    110116                page_table_unlock(AS, true);
     117                interrupts_restore(ipl);
    111118                return (__native) ENOENT;
    112119        }
     
    114121        page_table_unlock(AS, true);
    115122       
     123        interrupts_restore(ipl);       
     124
    116125        /*
    117126         * Find the respective futex structure
     
    149158        }
    150159       
    151         return (__native) waitq_sleep(&futex->wq);
     160        return (__native) waitq_sleep_timeout(&futex->wq, usec, trydown);
    152161}
    153162
     
    165174        link_t *item;
    166175        pte_t *t;
     176        ipl_t ipl;
     177       
     178        ipl = interrupts_disable();
    167179       
    168180        /*
     
    173185        if (!t || !PTE_VALID(t) || !PTE_PRESENT(t)) {
    174186                page_table_unlock(AS, true);
     187                interrupts_restore(ipl);
    175188                return (__native) ENOENT;
    176189        }
     
    178191        page_table_unlock(AS, true);
    179192       
     193        interrupts_restore(ipl);
     194
    180195        /*
    181196         * Find the respective futex structure.
     
    187202        }
    188203        rwlock_read_unlock(&futex_ht_lock);
    189        
     204
    190205        if (!futex)
    191206                return (__native) ENOENT;       
Note: See TracChangeset for help on using the changeset viewer.