I looked on to the patch (very quick look) and there are some problems i think. For example
bool getUnloadLock() const { return i_unloadActiveLockCount || i_unloadExplicitLock; }
...
void incUnloadActiveLock() { ++i_unloadActiveLockCount; }
If we want to have this working under multithreaded environment it will need real locking (mutex or other primitive) because this and similar operations are not atomic what can cause problems in real multithreaded environment. Even simple ++ -- operations are not atomic! It is good to keep this in mind. It can be solved by some fast mutex or using atomic operations (special CPU instructions for this purposes).