Come around limitation of CSingleLock don't accept NULL
Sure, that seems fine.


Obviously you should be using std::unique_ptr&lt;CSingleLock&gt; (and std::make_unique) instead of raw new and delete.
If you have access to C++17, Folly, or Boost, consider using std::optional&lt;CSingleLock&gt; to eliminate the heap allocation.
If you're not using unique_ptr, you might want to =delete your copy constructor and copy assignment operator (or in C++03, make them private), to ensure that nobody accidentally creates a copy of your object — which if they did would lead to a double-free.




You've also made your member variable _singleLock public, presumably by accident. If you actually want it to be public, consider giving it a more user-friendly name. It's best to keep it private, though.



A simpler approach would be to create a dummy lock, which (assuming either CSingleLock or CMutex is immovable) would actually fix the copyability problem as well.

class CSingleLockEx
{
    CMutex dummy_;
    CSingleLock lk_;
public:
    CSingleLockEx(CSyncObject *obj, bool initialLock = false) :
        lk_((obj ? *obj : dummy_), initialLock)
    {}
};


This way you end up locking something either way (and unlocking something in the destructor as well), but at least when obj==nullptr the "something" you're locking will definitely be uncontended. So I wouldn't expect a noticeable performance hit.