lib: tree: Add thread safety to the tree structure

Signed-off-by: Bart Kuivenhoven <bemkuivenhoven@gmail.com>