using a struct for the spinlock and cleaned up the comments a little.
added atomicflag and coverted spinlock to use it.