Added merge() function to BagOStuff for CAS-like functionality.

* merge() will use CAS if supported or use locking otherwise
* The lock()/unlock() methods now have a default implementation
* added unit tests for merge

Change-Id: Ic27088488f8532f149cb4b36e156516f22880134
Merge "Added merge() function to BagOStuff for CAS-like functionality."