An important part of futexes, which the article mentions only in passing, is that the kernel will also check a condition atomically with the wait operation; if the condition isn't satisfied the wait will not be performed. This avoids races between a thread that unlocks the mutex right after another thread has invoked the system call.
Effectively, inside the kernel the algorithm is
lock wait queue
if (*var == val)
add myself to wait queue
unlock wait queue
wait until queue wakes me up
else
unlock wait queue