chore: Renamed global lock functions

This commit is contained in:
2026-06-29 15:09:54 +01:00
parent a72becf656
commit a9c7b8cfd3

View File

@@ -30,10 +30,13 @@ static bool _msg_buffer_used[INCPHUB_MSG_BUFFER_COUNT];
// === Private function declarations ===
static bool public_enter(TickType_t maxDelay);
static void public_exit();
static bool global_lock(TickType_t max_delay);
static void global_unlock();
/// @remark Returns NULL if not found
static incphub_cli_t *find_empty_client();
/// @remark Returns NULL if not found
static incphub_cli_t *find_client_with_port(ntl_port_t port);
/// @remark Returns NULL if not found
static uint8_t *find_unused_buffer();
@@ -56,20 +59,20 @@ int register_client(incphub_cli_t **cli_ptr, ntl_port_t port, TaskHandle_t task)
return INCPHUB_EINVAL;
// == Enter ==
if (!public_enter(portMAX_DELAY))
if (!global_lock(portMAX_DELAY))
return INCPHUB_EAGAIN;
// Prevent double binding of ports
if (find_client_with_port(port) != NULL)
{
public_exit();
global_unlock();
return INCPHUB_EBUSY;
}
incphub_cli_t *client = find_empty_client();
if (client == NULL)
{
public_exit();
global_unlock();
return INCPHUB_EBUSY;
}
@@ -80,7 +83,7 @@ int register_client(incphub_cli_t **cli_ptr, ntl_port_t port, TaskHandle_t task)
// Save to passed pointer
*cli_ptr = client;
public_exit();
global_unlock();
return INCPHUB_OK;
}
@@ -94,14 +97,14 @@ int get_msg_buffer(uint8_t **buffer_ptr, size_t len)
return INCPHUB_ENOMEM;
// == Enter ==
if (!public_enter(portMAX_DELAY))
if (!global_lock(portMAX_DELAY))
return INCPHUB_EAGAIN;
//TODO: Allow buffer to be given by another layer (below NIL)
uint8_t *buf = find_unused_buffer();
if (buf == NULL)
{
public_exit();
global_unlock();
return INCPHUB_ENOMEM;
}
@@ -111,7 +114,7 @@ int get_msg_buffer(uint8_t **buffer_ptr, size_t len)
// Return buffer
*buffer_ptr = buf;
public_exit();
global_unlock();
return INCPHUB_OK;
}
@@ -124,21 +127,21 @@ int get_client_with_port(ntl_port_t port, incphub_cli_t **client_ptr)
return INCPHUB_EINVAL;
// == Enter ==
if (!public_enter(portMAX_DELAY))
if (!global_lock(portMAX_DELAY))
return INCPHUB_EAGAIN;
// Map port to client
incphub_cli_t *client = find_client_with_port(port);
if (client == NULL)
{
public_exit();
global_unlock();
return INCPHUB_ENOTFOUND;
}
// Return client
*client_ptr = client;
public_exit();
global_unlock();
return INCPHUB_OK;
}
@@ -161,12 +164,12 @@ int dequeue_message_ingest(uint8_t **buffer_ptr, size_t *length_ptr)
// === Private function definitions ===
static bool public_enter(TickType_t maxDelay)
static bool global_lock(TickType_t max_delay)
{
return xSemaphoreTake(_incphub_lock, maxDelay) == pdTRUE;
return xSemaphoreTake(_incphub_lock, max_delay) == pdTRUE;
}
static void public_exit()
static void global_unlock()
{
xSemaphoreGive(_incphub_lock);
}