Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 063a74b9 in mainline


Ignore:
Timestamp:
2013-09-07T22:17:45Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
7de18418
Parents:
a74d0ad
Message:

Futexes have the lock/unlock semantics and therefore need to use barriers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/futex.c

    ra74d0ad r063a74b9  
    3535#include <futex.h>
    3636#include <atomic.h>
     37#include <libarch/barrier.h>
    3738#include <libc.h>
    3839#include <sys/types.h>
     
    5960int futex_trydown(futex_t *futex)
    6061{
    61         return cas(futex, 1, 0);
     62        int rc;
     63
     64        rc = cas(futex, 1, 0);
     65        CS_ENTER_BARRIER();
     66
     67        return rc;
    6268}
    6369
     
    7379int futex_down(futex_t *futex)
    7480{
    75         if ((atomic_signed_t) atomic_predec(futex) < 0)
     81        atomic_signed_t nv;
     82
     83        nv = (atomic_signed_t) atomic_predec(futex);
     84        CS_ENTER_BARRIER();
     85        if (nv < 0)
    7686                return __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->count);
    7787       
     
    8999int futex_up(futex_t *futex)
    90100{
     101        CS_LEAVE_BARRIER();
     102
    91103        if ((atomic_signed_t) atomic_postinc(futex) < 0)
    92104                return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->count);
Note: See TracChangeset for help on using the changeset viewer.