udf: Move handling of uniqueID into a helper function and protect it by a s_alloc_mutex