Skip to content

Commit 4312aad

Browse files
authored
[api] Refactor mutex API to use lock/unlock verbs. (#14)
1 parent cf2436b commit 4312aad

6 files changed

Lines changed: 15 additions & 15 deletions

File tree

include/poski/osal/os_mutex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pos_error_t pos_mutex_init(struct pos_mutex * mutex);
6060
* @retval POS_EBUSY Returned without waiting.
6161
* @retval POS_TIMEOUT Waiting period timed out.
6262
*/
63-
pos_error_t pos_mutex_take(struct pos_mutex * mutex, pos_time_t timeout);
63+
pos_error_t pos_mutex_lock(struct pos_mutex * mutex, pos_time_t timeout);
6464

6565
/**
6666
* @brief Unlock a mutex.
@@ -76,7 +76,7 @@ pos_error_t pos_mutex_take(struct pos_mutex * mutex, pos_time_t timeout);
7676
*
7777
* @return N/A
7878
*/
79-
pos_error_t pos_mutex_give(struct pos_mutex * mutex);
79+
pos_error_t pos_mutex_unlock(struct pos_mutex * mutex);
8080

8181
#ifdef __cplusplus
8282
}

targets/freertos/os_mutex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pos_error_t pos_mutex_init(struct pos_mutex * mu)
3737
return (mu->handle == NULL) ? POS_BAD_MUTEX : POS_OK;
3838
}
3939

40-
pos_error_t pos_mutex_take(struct pos_mutex * mu, pos_time_t timeout)
40+
pos_error_t pos_mutex_lock(struct pos_mutex * mu, pos_time_t timeout)
4141
{
4242
BaseType_t ret;
4343

@@ -55,7 +55,7 @@ pos_error_t pos_mutex_take(struct pos_mutex * mu, pos_time_t timeout)
5555
return ret == pdPASS ? POS_OK : POS_TIMEOUT;
5656
}
5757

58-
pos_error_t pos_mutex_give(struct pos_mutex * mu)
58+
pos_error_t pos_mutex_unlock(struct pos_mutex * mu)
5959
{
6060
assert(!pos_hw_in_isr());
6161

targets/posix/os_mutex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pos_error_t pos_mutex_init(struct pos_mutex * mu)
4040
return (ret) ? POS_BAD_MUTEX : POS_OK;
4141
}
4242

43-
pos_error_t pos_mutex_give(struct pos_mutex * mu)
43+
pos_error_t pos_mutex_unlock(struct pos_mutex * mu)
4444
{
4545
int ret = (pthread_mutex_unlock(&mu->lock));
4646
SuccessOrExit(ret);
@@ -49,7 +49,7 @@ pos_error_t pos_mutex_give(struct pos_mutex * mu)
4949
return map_posix_to_osal_error(ret);
5050
}
5151

52-
pos_error_t pos_mutex_take(struct pos_mutex * mu, pos_time_t timeout)
52+
pos_error_t pos_mutex_lock(struct pos_mutex * mu, pos_time_t timeout)
5353
{
5454
int ret;
5555

targets/rt-thread/os_mutex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pos_error_t pos_mutex_init(struct pos_mutex * mu)
3737
return (mu->handle == NULL) ? POS_BAD_MUTEX : POS_OK;
3838
}
3939

40-
pos_error_t pos_mutex_take(struct pos_mutex * mu, pos_time_t timeout)
40+
pos_error_t pos_mutex_lock(struct pos_mutex * mu, pos_time_t timeout)
4141
{
4242
rt_err_t ret;
4343

@@ -53,7 +53,7 @@ pos_error_t pos_mutex_take(struct pos_mutex * mu, pos_time_t timeout)
5353
return ret == RT_EOK ? POS_OK : POS_BAD_MUTEX;
5454
}
5555

56-
pos_error_t pos_mutex_give(struct pos_mutex * mu)
56+
pos_error_t pos_mutex_unlock(struct pos_mutex * mu)
5757
{
5858
assert(!pos_hw_in_isr());
5959

targets/zephyr/os_mutex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pos_error_t pos_mutex_init(struct pos_mutex * mutex)
2424
return POS_OK;
2525
}
2626

27-
pos_error_t pos_mutex_take(struct pos_mutex * mutex, pos_time_t timeout)
27+
pos_error_t pos_mutex_lock(struct pos_mutex * mutex, pos_time_t timeout)
2828
{
2929
k_timeout_t tmo;
3030
if (timeout == POS_TIME_FOREVER) {
@@ -45,7 +45,7 @@ pos_error_t pos_mutex_take(struct pos_mutex * mutex, pos_time_t timeout)
4545
}
4646
}
4747

48-
pos_error_t pos_mutex_give(struct pos_mutex * mutex)
48+
pos_error_t pos_mutex_unlock(struct pos_mutex * mutex)
4949
{
5050
int err = k_mutex_unlock(&mutex->mutex);
5151
return (err == 0) ? POS_OK : POS_ERROR;

tests/test_os_mutex.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ uint8_t s_buffer[TEST_ITERATIONS];
4949
void test_mutex_nested(uint8_t test_value, int task, bool recursive, int round)
5050
{
5151
TEST_LOG("task %d: LOCK START ROUND %d\n", task, round);
52-
SuccessOrQuit(pos_mutex_take(&task1_mtx, POS_TIME_FOREVER), "pos_mutex_take: error waiting for task1_mutex.");
52+
SuccessOrQuit(pos_mutex_lock(&task1_mtx, POS_TIME_FOREVER), "pos_mutex_lock: error waiting for task1_mutex.");
5353
for (int i = 0; i < TEST_ITERATIONS; i++)
5454
{
5555
if (recursive)
5656
{
5757
TEST_LOG("task %d: take #%d RECURSIVE\n", task, i);
58-
SuccessOrQuit(pos_mutex_take(&task1_mtx, POS_TIME_FOREVER),
59-
"pos_mutex_take: error waiting for task1_mutex.");
58+
SuccessOrQuit(pos_mutex_lock(&task1_mtx, POS_TIME_FOREVER),
59+
"pos_mutex_lock: error waiting for task1_mutex.");
6060
}
6161
// TEST_LOG("task %d: b[%d]=0x%02x --> 0x%02x\n", task, i, s_buffer[i], test_value);
6262
VerifyOrQuit(s_buffer[i] != test_value, "unexpected value: mutex did not protect resource");
@@ -70,13 +70,13 @@ void test_mutex_nested(uint8_t test_value, int task, bool recursive, int round)
7070
if (recursive)
7171
{
7272
TEST_LOG("task %d: give #%d RECURSIVE\n", task, i);
73-
SuccessOrQuit(pos_mutex_give(&task1_mtx), "pos_mutex_give: error releasing task1_mutex.");
73+
SuccessOrQuit(pos_mutex_unlock(&task1_mtx), "pos_mutex_unlock: error releasing task1_mutex.");
7474
}
7575
}
7676
// Clear out buffer in case this task reclaims the resource again
7777
memset(&s_buffer, 0, sizeof(s_buffer));
7878
TEST_LOG("task %d: LOCK END ROUND %d\n", task, round);
79-
SuccessOrQuit(pos_mutex_give(&task1_mtx), "pos_mutex_give: error releasing task1_mutex.");
79+
SuccessOrQuit(pos_mutex_unlock(&task1_mtx), "pos_mutex_unlock: error releasing task1_mutex.");
8080

8181
pos_task_sleep(10);
8282
}

0 commit comments

Comments
 (0)