Do you actually need to unblock the other task and then close the port? It is perfectly possible to furtle with the low-level pin configuration while the port is open.
I have had a situation where some production test code needed to test the operation of serial port pins at a time where the port was already open by another task. This code worked:
/* Do something horrid to test that RTS and CTS are looped back if appropriate */
switch (port) {
case 1: // RS232 lower
_bsp_serial_io_init(3, IO_PERIPHERAL_PIN_MUX_DISABLE);
lwgpio_init(&pinRTS, LWGPIO_PORT_E | LWGPIO_PIN7, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_LOW);
lwgpio_init(&pinCTS, LWGPIO_PORT_E | LWGPIO_PIN6, LWGPIO_DIR_INPUT, LWGPIO_VALUE_LOW);
lwgpio_set_functionality(&pinRTS, LWGPIO_MUX_E7_GPIO);
lwgpio_set_functionality(&pinCTS, LWGPIO_MUX_E6_GPIO);
lwgpio_set_value(&pinRTS, LWGPIO_VALUE_LOW); _time_delay(10);
if (lwgpio_get_value(&pinCTS) != LWGPIO_VALUE_LOW) result = false;
lwgpio_set_value(&pinRTS, LWGPIO_VALUE_HIGH); _time_delay(10);
if (lwgpio_get_value(&pinCTS) != LWGPIO_VALUE_HIGH) result = false;
_bsp_serial_io_init(3, IO_PERIPHERAL_PIN_MUX_ENABLE);
break;
etc...