Tinkerforge/generators — pull request #32 by NobodysNightmare (2013-01-30 10:42:52+00:00)
Title: C#: improve locking

This Pull Request is smaller than I thought, but still worth sharing :)

After a long time I finally took a look at the new locking.
Here are my findings:
The method IPConnection.Write() was always called in the same way:
1. aquire the socketLock
2. check if the IPConnections socket is connected, if not throw an exception
3. call IPConnection.Write()

For this reason I included steps one and two in the Write-method, as the socketLock was only neccessary to make the socket-check and the socket-use atomic.
This yielded two benefits:
1. The Device did those checks on IPConnection before which was an encapsulation break, so the Device-code became cleaner and more understandable
2. It was now possible to get rid of the socketWriterLock, as its purpose was now fully fulfilled by the socketLock.

Hope you like to pull this, even if it does not fix any bugs, but only makes code more readable and maintainable (and a tiny tiny little bit faster ^^)