Thread-safe linked list review
Is there a more performant way to get thread-safety for this data structure?


It all depends on how the list will be used. Just a few examples:


Reads are more common than writes - use separate read/write locks.
Average list is short - use copy-on-write array instead of linked list.
Average list is long - use more efficient search method.
Lots of threads access list - use mutex instead of spinlock to avoid wasted cycles.
Lots of elements is added/removed in bulk - use external lock.


Have you actually measured performance in real world scenarios and identified bottlenecks? It looks like most of it is prematurely optimized.

__attribute__((always_inline))


Is this really necessary? Does it bring any measurable performance gain?

while (__sync_lock_test_and_set(lock, 1))
    while (*lock)


I do not understand this second while loop. Why are you checking the value twice?

#define MY_LISTLOCK_LOCK MYSpinLock *MY_macro_lock = &amp;(list-&gt;_lockLL); MYSpinLockLock(MY_macro_lock)
#define MY_LISTLOCK_UNLOCK MYSpinLockUnlock(MY_macro_lock)


Avoid macros which can be replaced with functions.

MYBool


Use bool from stdbool.h.