lib: controller: add mutex around endpoint vector lookup

In previous version of the code the discovery thread could add an endpoint,
causing the endpoint vector to be re-allocated at the exact time a foreground
thread was looking up an endpoint. This version gets around this possible issue
by using a mutex in the lookup process. Note, actual endpoint class accesses are
fine because they use a pointer to the endpoint class and the endpoint class itself
is never moved in memory.