move from semaphore to gcc builtin atomics, and do the spinlocking per item