core:mutex: add atomic mutex and unlock function

To implement synchronization barriers I could use a function to unlock one mutex and lock another atomically. Atomically hereby means that the current thread won't get yielded after releasing the first mutex, not before it locks the other one.

This PR is based and on  #728 by @BytesGalore. It does a major refactoring of mutex.c, but hopefully does not break stuff. :)

I'll add a test in form of another PR once I implemented pthread_barriers, which is going to use this function.