<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def current_segment(self):
 """ Return the currently active segment. In a multithreading environment, this will make sure the segment returned is the one created by the same thread. """

        entity = self.get_trace_entity()
        if self._is_subsegment(entity):
            return entity.parent_segment
        else:
            return entity