Refactor `register_tcp_functions_as_names()` such that either all or no (in error cases) registrations happen atomically (while holding the `tcp_function_lock` write lock). Also ensure that the TCP function block is nit already registered.
This avoids situations, where some registrations were performed and then they were just removed without holding a lock in between or checking ref counts.