HPCC-8631 Added CriticalSection usage

Also namespaced the functions since CriticalSection is on the
global scope.

Signed-off-by: Philip Schwartz <philip.schwartz@lexisnexis.com>