News for hackers. Stuff that matters.
Re:A spin lock in C that does not require a machine level ex... by nkurz on Sunday May 04, 2014 @08:33PM (#7696454)
Here's a copy of the functions in question so that it's easier to see what people are talking about:

  void 
  spin_lock(struct spin_lock_state *state, int locker_id,
            void (*spin_wait_callback)()) {
    for (;;) {
      if (state->g2 == locker_id) {
        return;
      }
      while (state->g2 != SPIN_LOCK_NO_LOCKER) {
        if (spin_wait_callback != NULL) {
          spin_wait_callback();
        }
        continue;
      }
      state->g1 = locker_id;
      if (state->g2 == SPIN_LOCK_NO_LOCKER) {
        state->g2 = state->g1;
        if (state->g1 == locker_id) {
          if (state->g2 == locker_id) {
            return;
          }
        }
      }
    }
  }

  void
  spin_unlock(struct spin_lock_state *state, int locker_id)
  {
    state->g2 = SPIN_LOCK_NO_LOCKER;
  }

There are no comments on this comment yet.