Add _t suffix to types

This commit is contained in:
Justin R. Cutler 2016-04-02 16:35:45 -04:00
parent f6ef16f80f
commit e1a83ea77a
3 changed files with 24 additions and 21 deletions

View File

@ -36,9 +36,10 @@ struct coroutine {
};
static void coroutine_entry_point(coroutine *, coroutine_function *)
static void coroutine_entry_point(coroutine_t *, coroutine_function_t *)
__attribute__ ((noreturn));
static void coroutine_entry_point(coroutine *c, coroutine_function *function)
static void coroutine_entry_point(coroutine_t *c,
coroutine_function_t *function)
{
/* run function until it returns */
void *retval = function(c, c->data);
@ -53,7 +54,7 @@ static void coroutine_entry_point(coroutine *c, coroutine_function *function)
}
static int stack_allocate(coroutine *coro, size_t stack_pages)
static int stack_allocate(coroutine_t *coro, size_t stack_pages)
{
int error = -1;
size_t page_size = sysconf(_SC_PAGE_SIZE);
@ -78,7 +79,7 @@ static int stack_allocate(coroutine *coro, size_t stack_pages)
}
static void stack_free(coroutine *coro)
static void stack_free(coroutine_t *coro)
{
if (NULL != coro->context.uc_stack.ss_sp) {
(void) munmap(coro->context.uc_stack.ss_sp,
@ -87,9 +88,10 @@ static void stack_free(coroutine *coro)
}
coroutine *coroutine_create(coroutine_function *function, size_t stack_pages)
coroutine_t *coroutine_create(coroutine_function_t *function,
size_t stack_pages)
{
coroutine *coro;
coroutine_t *coro;
coro = calloc(1, sizeof(*coro));
if (NULL == coro) {
@ -116,7 +118,7 @@ fail:
}
void coroutine_destroy(coroutine *coro)
void coroutine_destroy(coroutine_t *coro)
{
if (NULL != coro) {
stack_free(coro);
@ -125,13 +127,13 @@ void coroutine_destroy(coroutine *coro)
}
bool coroutine_ended(const coroutine *coro)
bool coroutine_ended(const coroutine_t *coro)
{
return (NULL == coro) || !!(coro->status & COROUTINE_ENDED);
}
void *coroutine_resume(coroutine *coro, void *value)
void *coroutine_resume(coroutine_t *coro, void *value)
{
if (NULL == coro) {
return NULL;
@ -142,7 +144,7 @@ void *coroutine_resume(coroutine *coro, void *value)
}
void *coroutine_yield(coroutine *coro, void *value)
void *coroutine_yield(coroutine_t *coro, void *value)
{
if (NULL == coro) {
return NULL;

View File

@ -13,7 +13,7 @@
#include <threadless/coroutine.h>
static void *fibonacci_generator(coroutine *coro, void *data)
static void *fibonacci_generator(coroutine_t *coro, void *data)
{
size_t x = 0;
size_t y = 1;
@ -37,7 +37,7 @@ static void *fibonacci_generator(coroutine *coro, void *data)
}
static void *output_coroutine(coroutine *coro, void *data)
static void *output_coroutine(coroutine_t *coro, void *data)
{
size_t *value = data;
@ -53,8 +53,8 @@ static void *output_coroutine(coroutine *coro, void *data)
static int run(void)
{
int error = -1;
coroutine *fibonacci = NULL;
coroutine *output = NULL;
coroutine_t *fibonacci = NULL;
coroutine_t *output = NULL;
fibonacci = coroutine_create(fibonacci_generator, 1);
if (NULL == fibonacci) {

View File

@ -12,7 +12,7 @@
#include <stddef.h>
/** Opaque coroutine type */
typedef struct coroutine coroutine;
typedef struct coroutine coroutine_t;
/** Coroutine function type
* @param[in,out] coro coroutine
@ -20,7 +20,7 @@ typedef struct coroutine coroutine;
* @returns user-defined pointer (which should correspond to value(s) passed to
* coroutine_yield())
*/
typedef void *(coroutine_function)(coroutine *coro, void *data);
typedef void *(coroutine_function_t)(coroutine_t *coro, void *data);
#ifdef __cplusplus
extern "C" {
@ -34,14 +34,15 @@ extern "C" {
* @post upon success, return value may be passed to coroutine_resume()
* @post upon success, return value must be passed to coroutine_destroy()
*/
coroutine *coroutine_create(coroutine_function *function, size_t stack_pages);
coroutine_t *coroutine_create(coroutine_function_t *function,
size_t stack_pages);
/** Destroy a coroutine
* @param[in,out] coro coroutine to destroy
* @pre @p coro must have been returned by coroutine_create()
* @post @p coro may no longer be used
*/
void coroutine_destroy(coroutine *coro);
void coroutine_destroy(coroutine_t *coro);
/** Test if a coroutine has ended
* @param[in] coro coroutine to test
@ -49,7 +50,7 @@ void coroutine_destroy(coroutine *coro);
* @retval false coroutine has not ended
* @pre @p coro must have been returned by coroutine_create()
*/
bool coroutine_ended(const coroutine *coro);
bool coroutine_ended(const coroutine_t *coro);
/** Resume a coroutine, passing a value to coroutine_yield()
* @param[in,out] coro coroutine to resume
@ -58,7 +59,7 @@ bool coroutine_ended(const coroutine *coro);
* @returns value passed by @p coro to coroutine_yield()
* @pre @p coro must have been returned by coroutine_create()
*/
void *coroutine_resume(coroutine *coro, void *value);
void *coroutine_resume(coroutine_t *coro, void *value);
/** Yield from a coroutine, passing a value to coroutine_resume()
* @param[in,out] coro coroutine to yield from
@ -66,7 +67,7 @@ void *coroutine_resume(coroutine *coro, void *value);
* @returns value passed by @p coro to coroutine_resume()
* @pre @p coro must have been returned by coroutine_create()
*/
void *coroutine_yield(coroutine *coro, void *value);
void *coroutine_yield(coroutine_t *coro, void *value);
#ifdef __cplusplus
}