The Dispatch framework does not provide a spinlock, likely for good reason. Here a spinlock protocol and class implementation are defined with simple code. The Playground can be used to try it out.
There really is no good use for a spinlock given that Dispatch already allows for sync
logic which
handles locking and priority inversion concerns. While a spinlock is waiting with the sleep calls no
other work can be done on the main queue. It is essentially the same as using sync
to put work on
another queue while locking the current queue as a consequence.