You take pending before exclusive (which should always be possible because you have reserved by then), and you should check pending before taking a shared lock (no need to check exclusive, because they got pending before exclusive).
Shared forces writers to wait; Reserved prevents new readers from upgrading to write; Pending prevents new readers from starting; and exclusive forces everyone else to wait.