[PyTorch] Update Synchronized<T>::withLock() to return the type/value from the aceepted callable (#74060)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74060
Currently, `void c10::Synchronized<T>::withLock(CB)` accepts a callback but returns `void`. For a callback (CB) returning a value, `withLock()` can not be used to retrieve the returned value. This change makes it possible for the caller to retrieve that value. The only gotcha is that if the value has only move semantics (such as `std::unique_ptr<T>`, then this won't work as currently written). To be able to do that, one needs to use `std::enable_if<T>` to enable a separate overload that works only for moveable types (detectable using `std::is_move_constructible<T>`).
ghstack-source-id: 150555297
Test Plan:
Built model tracer using the command:
```
buck build -c pt.disable_per_op_profiling=0 -c pt.enable_record_kernel_dtype=1 --show-output xplat/caffe2/fb/model_tracer:model_tracer
```
Reviewed By: JacobSzwejbka
Differential Revision: D34645509
fbshipit-source-id: 9a4bd5d1d78a5026826c7ed9ee04ea743cafcc10
(cherry picked from commit f3893dec44cb361ef1ffc1f56b9b6f94be5c9b83)