Cleanup pthread code for data layers

While creating a new data layer class needed for my Siamese network, I noticed that the
pthread code wasn't particularely clean.

Thus I
- Got rid of the needless friend functions. Previously the threads were defined as a friend function.
This forced to pass a pointer to the current layer, and do needless casts and pointer checks.
- Created an InternalThread class that makes it easy to create a class requiring a single thread (such as DataLayer, ImageDataLayer...).
It is done by inheriting the InternalThread class, and overriding the InternalThreadEntry virtual function to
define the thread's code. It has the necessary mechanism to start and wait for a thread.

This is my first contribution to Caffe, I hope I followed all the guidelines properly ;)

Cheers,
Arnaud