mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 10:03:50 +01:00
Merge pull request #5642 from lebrush/cib-peek
core/cib: add peek capabilities
This commit is contained in:
commit
1e17eece1f
@ -86,6 +86,22 @@ static inline int cib_get(cib_t *__restrict cib)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the index of the next item in buffer without removing it.
|
||||||
|
*
|
||||||
|
* @param[in,out] cib corresponding *cib* to buffer.
|
||||||
|
* Must not be NULL.
|
||||||
|
* @return index of next item, -1 if the buffer is empty
|
||||||
|
*/
|
||||||
|
static inline int cib_peek(cib_t *__restrict cib)
|
||||||
|
{
|
||||||
|
if (cib->write_count > cib->read_count) {
|
||||||
|
return (int) (cib->read_count & cib->mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get index for item in buffer to put to.
|
* @brief Get index for item in buffer to put to.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -36,6 +36,20 @@ static void test_cib_get(void)
|
|||||||
TEST_ASSERT_EQUAL_INT(-1, cib_get(&cib));
|
TEST_ASSERT_EQUAL_INT(-1, cib_get(&cib));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_cib_peek(void)
|
||||||
|
{
|
||||||
|
cib_init(&cib, TEST_CIB_SIZE);
|
||||||
|
TEST_ASSERT_EQUAL_INT(-1, cib_peek(&cib));
|
||||||
|
TEST_ASSERT_EQUAL_INT(0, cib_put(&cib));
|
||||||
|
TEST_ASSERT_EQUAL_INT(0, cib_peek(&cib));
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, cib_put(&cib));
|
||||||
|
TEST_ASSERT_EQUAL_INT(0, cib_peek(&cib));
|
||||||
|
TEST_ASSERT_EQUAL_INT(0, cib_get(&cib));
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, cib_peek(&cib));
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, cib_get(&cib));
|
||||||
|
TEST_ASSERT_EQUAL_INT(-1, cib_peek(&cib));
|
||||||
|
}
|
||||||
|
|
||||||
static void test_cib_avail(void)
|
static void test_cib_avail(void)
|
||||||
{
|
{
|
||||||
TEST_ASSERT_EQUAL_INT(0, cib_avail(&cib));
|
TEST_ASSERT_EQUAL_INT(0, cib_avail(&cib));
|
||||||
@ -83,6 +97,7 @@ Test *tests_core_cib_tests(void)
|
|||||||
new_TestFixture(test_cib_put_and_get),
|
new_TestFixture(test_cib_put_and_get),
|
||||||
new_TestFixture(test_empty_cib),
|
new_TestFixture(test_empty_cib),
|
||||||
new_TestFixture(test_singleton_cib),
|
new_TestFixture(test_singleton_cib),
|
||||||
|
new_TestFixture(test_cib_peek),
|
||||||
};
|
};
|
||||||
|
|
||||||
EMB_UNIT_TESTCALLER(core_cib_tests, set_up, NULL, fixtures);
|
EMB_UNIT_TESTCALLER(core_cib_tests, set_up, NULL, fixtures);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user