Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p_mutex_*: Implement init/lock/unlock/etc: #162

Closed
wants to merge 2 commits into from

Commits on Jun 23, 2015

  1. p_mutex_*: Implement init/lock/unlock/etc:

    Implement the p_mutex functions.
    
    p_mutex_t is a uint32_t* -- We waste 23 bytes on it, but it's a
    nice round size.
    
    This follows in the form that pthreads uses. Each of these functions
    does a quick NULL check to be sure things aren't bad (except for
    p_mutex_create, which checks that we're not trying to initialize an
    empty p_mutex_t)
    
    Signed-off-by: Morgan Gangwere <[email protected]>
    indrora committed Jun 23, 2015
    Configuration menu
    Copy the full SHA
    854cd98 View commit details
    Browse the repository at this point in the history
  2. p_mutex_lock / p_mutex_trylock: race proofing.

    Change up locking logic such that race conditions are
    less of a problem.
    
    in p_mutex_lock: spin until a lock is gotten *and* it
    equals 1 with two nested loops and atomic operations only.
    
    in p_mutex_trylock: fail early, but an atomic branch will
    cause a small check to see if a race happened *and* the thread
    asking for the mutex actually got the lock. No loops, only
    returns.
    
    Signed-off-by: Morgan Gangwere <[email protected]>
    indrora committed Jun 23, 2015
    Configuration menu
    Copy the full SHA
    c399aa6 View commit details
    Browse the repository at this point in the history