How to implement a costate-safe data structures

I have to write a linked list that should be accessed by 2 different costates.

To keep the consistency of the data, I need to add a locking flag. The process of getting exclusive access to the list should involve atomic test and set function, please refer to this article:

is there a TestAndSet instruction in Dynamic C? otherwise how to implement a costate-safe linked list or queue in Dynamic C?