Added some code which helps troubleshooting issues caused by
non-threadsafe usage of guarded allocator.

Also added small chunk of code to check consistency of begin/end
threaded malloc.

All this additional checks are commented and wouldn't affect on
builds, however found them helpful to troubleshoot issues so
decided to commit it to SVN.

git-svn-id: https://svn.blender.org/svnroot/bf-blender/trunk/blender@54066 954f8c5b-7b00-dc11-b283-0030488c597c
Fix threading issues of viewport rendering when using movies/generated images

Issue was caused by the fact that guarded allocator is not thread-safe and
generated images/movies could allocate memory when loading pixels to Cycles.

Currently solved by switching memory allocator to using mutex lock (the same
as sued for jobs) when viewport rendering is used.

Nicer solution would be to make guarded allocator thread-safe by using atomic
operations and lock-free lists, but that's more serious change.

git-svn-id: https://svn.blender.org/svnroot/bf-blender/trunk/blender@54067 954f8c5b-7b00-dc11-b283-0030488c597c