This is mostly copied from x86_64 with necessary modifications
I don't really want to be working with i386 since it doesn't support compare exchange instruction