pipes: Simplify task_pipe_put() API family

Changes the pipe API so that the timeout parameter must be specified
when invoking task_pipe_put() thereby obsoletingg the following APIs:
	task_pipe_put_wait()
	task_pipe_put_wait_timeout()
	_task_pipe_put()

Change-Id: Ie5693716828e9d8681434c0d130792279ab97acc
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
This commit is contained in:
Peter Mitsis 2015-12-04 13:54:01 -05:00 committed by Anas Nashif
commit f5d90e1584
8 changed files with 89 additions and 136 deletions

View file

@ -232,8 +232,8 @@ to a consuming task.
data_item = ... ;
/* write the entire data item to the pipe */
task_pipe_put_wait(DATA_PIPE, &data_item, sizeof(data_item),
&amount_written, _ALL_N);
task_pipe_put(DATA_PIPE, &data_item, sizeof(data_item),
&amount_written, _ALL_N, TICKS_UNLIMITED);
}
}
@ -305,14 +305,7 @@ APIs
The following Pipe APIs are provided by :file:`microkernel.h`:
:c:func:`task_pipe_put()`
Writes data to a pipe, or fails & continues if unable to write data.
:c:func:`task_pipe_put_wait()`
Writes data to a pipe, or waits if unable to write data.
:c:func:`task_pipe_put_wait_timeout()`
Writes data to a pipe, or waits for
a specified time period if unable to write data.
Writes data to a pipe, with time limited waiting.
:c:func:`task_pipe_block_put()`
Writes data to a pipe from a memory pool block.
@ -325,4 +318,4 @@ The following Pipe APIs are provided by :file:`microkernel.h`:
:c:func:`task_pipe_get_wait_timeout()`
Reads data from a pipe, or waits for
data for a specified time period if data isn't there.
data for a specified time period if data isn't there.

View file

@ -35,12 +35,6 @@ extern "C" {
/**
* @cond internal
*/
extern int _task_pipe_put(kpipe_t id,
void *pBuffer,
int iNbrBytesToWrite,
int *piNbrBytesWritten,
K_PIPE_OPTION Option,
int32_t TimeOut);
/**
* @internal
@ -63,55 +57,29 @@ extern int _task_pipe_put(kpipe_t id,
/**
* @brief Pipe write request
*
* Attempt to write data from a memory buffer area to the specified pipe.
* Fail immediately if it is not possible.
*
* @param i Pipe ID
* @param b Buffer
* @param n Number of bytes to write
* @param pn Pointer to number of bytes written
* @param o Pipe options
*
* @return RC_OK, RC_INCOMPLETE, RC_FAIL, or RC_ALIGNMENT
*/
#define task_pipe_put(i, b, n, pn, o) \
_task_pipe_put(i, b, n, pn, o, TICKS_NONE)
/**
* @brief Pipe write request with unlimited wait
*
* Attempt to write data from a memory buffer area to the
* specified pipe and wait forever until it succeeds.
*
* @param i Pipe ID
* @param b Buffer
* @param n Number of bytes to write
* @param pn Pointer to number of bytes written
* @param o Pipe options
*
* @return RC_OK, RC_INCOMPLETE or RC_ALIGNMENT
*/
#define task_pipe_put_wait(i, b, n, pn, o) \
_task_pipe_put(i, b, n, pn, o, TICKS_UNLIMITED)
/**
* @brief Pipe write request with timeout
*
* Attemp to write data from a memory buffer area to the
* specified pipe with a timeout option.
*
* @param id Pipe ID
* @param b Buffer
* @param n Number of bytes to write
* @param pn Pointer to number of bytes written
* @param o Pipe options
* @param t Timeout
* @param buffer Buffer
* @param bytes_to_write Number of bytes to write
* @param bytes_written Pointer to number of bytes written
* @param options Pipe options
* @param timeout Affects the action taken should the pipe be full. If
* TICKS_NONE, then return immediately. If TICKS_UNLIMITED, then wait as long
* as necessary. Otherwise wait up to the specified number of ticks before
* timing out.
*
* @return RC_OK, RC_INCOMPLETE, RC_FAIL, RC_TIME, or RC_ALIGNMENT
* @retval RC_OK Successfully wrote data to pipe
* @retval RC_ALIGNMENT Data is improperly aligned
* @retval RC_INCOMPLETE Only some of the data was written to the pipe when
* @a options = _ALL_N
* @retval RC_TIME Timed out waiting to write to pipe
* @retval RC_FAIL Failed to immediately write to pipe when
* @a timeout = TICKS_NONE
*/
#define task_pipe_put_wait_timeout(id, b, n, pn, o, t) \
_task_pipe_put(id, b, n, pn, o, t)
extern int task_pipe_put(kpipe_t id, void *buffer, int bytes_to_write,
int *bytes_written, K_PIPE_OPTION options, int32_t timeout);
extern int _task_pipe_get(kpipe_t id,
void *pBuffer,

View file

@ -102,57 +102,49 @@ int _task_pipe_get(kpipe_t Id, void *pBuffer,
return A.Time.rcode;
}
/**
* @brief Pipe write request
*
* This routine attempts to write data from a memory buffer area to the
* specified pipe.
*
* @return RC_OK, RC_INCOMPLETE, RC_FAIL, RC_TIME, or RC_ALIGNMENT
*/
int _task_pipe_put(kpipe_t Id, void *pBuffer,
int iNbrBytesToWrite, int *piNbrBytesWritten,
K_PIPE_OPTION Option, int32_t TimeOut)
int task_pipe_put(kpipe_t id, void *buffer,
int bytes_to_write, int *bytes_written,
K_PIPE_OPTION options, int32_t timeout)
{
struct k_args A;
/*
* some users do not check the FUNCTION return value,
* but immediately use iNbrBytesWritten; make sure it always
* but immediately use bytes_written; make sure it always
* has a good value, even when we return failure immediately
* (see below)
*/
*piNbrBytesWritten = 0;
*bytes_written = 0;
if (unlikely(iNbrBytesToWrite % SIZEOFUNIT_TO_OCTET(1))) {
if (unlikely(bytes_to_write % SIZEOFUNIT_TO_OCTET(1))) {
return RC_ALIGNMENT;
}
if (unlikely(iNbrBytesToWrite == 0)) {
if (unlikely(bytes_to_write == 0)) {
/*
* not allowed because enlisted requests with zero size
* will hang in _k_pipe_process()
*/
return RC_FAIL;
}
if (unlikely(Option == _0_TO_N && TimeOut != TICKS_NONE)) {
if (unlikely(options == _0_TO_N && timeout != TICKS_NONE)) {
return RC_FAIL;
}
A.priority = _k_current_task->priority;
A.Comm = _K_SVC_PIPE_PUT_REQUEST;
A.Time.ticks = TimeOut;
A.Time.ticks = timeout;
A.args.pipe_req.req_info.pipe.id = Id;
A.args.pipe_req.req_type.sync.total_size = iNbrBytesToWrite;
A.args.pipe_req.req_type.sync.data_ptr = pBuffer;
A.args.pipe_req.req_info.pipe.id = id;
A.args.pipe_req.req_type.sync.total_size = bytes_to_write;
A.args.pipe_req.req_type.sync.data_ptr = buffer;
_k_pipe_option_set(&A.args, Option);
_k_pipe_option_set(&A.args, options);
_k_pipe_request_type_set(&A.args, _SYNCREQ);
KERNEL_ENTRY(&A);
*piNbrBytesWritten = A.args.pipe_ack.xferred_size;
*bytes_written = A.args.pipe_ack.xferred_size;
return A.Time.rcode;
}

View file

@ -212,8 +212,8 @@ int pipeput(kpipe_t pipe, K_PIPE_OPTION option, int size, int count, uint32_t *t
int size2xfer = min(size, size2xfer_total - sizexferd_total);
int ret;
ret = task_pipe_put_wait(pipe, data_bench, size2xfer,
&sizexferd, option);
ret = task_pipe_put(pipe, data_bench, size2xfer,
&sizexferd, option, TICKS_UNLIMITED);
if (RC_OK != ret) {
return 1;
}

View file

@ -89,7 +89,7 @@ static pfunc func_array[] = {
(pfunc)_task_sem_take,
(pfunc)_task_sem_group_take,
/* pipe functions */
(pfunc)_task_pipe_put,
(pfunc)task_pipe_put,
(pfunc)_task_pipe_get,
(pfunc)_task_pipe_block_put,
/* mailbox functions */

View file

@ -32,9 +32,9 @@ Sample Output:
Starting pipe tests
===================================================================
Testing task_pipe_put() ...
Testing task_pipe_put_wait() ...
Testing task_pipe_put_wait_timeout() ...
Testing task_pipe_put(TICKS_NONE) ...
Testing task_pipe_put(TICKS_UNLIMITED) ...
Testing task_pipe_put(timeout) ...
Testing task_pipe_get() ...
Testing task_pipe_get_wait() ...
Testing task_pipe_get_wait_timeout() ...

View file

@ -21,8 +21,6 @@
* This modules tests the following target pipe routines:
*
* task_pipe_put()
* task_pipe_put_wait()
* task_pipe_put_wait_timeout()
* task_pipe_get()
* task_pipe_get_wait()
* task_pipe_get_wait_timeout()
@ -320,9 +318,9 @@ int pipePutHelper(void)
/**
*
* @brief Test task_pipe_put()
* @brief Test task_pipe_put(TICKS_NONE)
*
* This routine tests the task_pipe_put() API.
* This routine tests the task_pipe_put(TICKS_NONE) API.
*
* @param singleItems testcase list (one item in the pipe)
* @param nSingles number of items in testcase
@ -344,7 +342,8 @@ int pipePutTestWork(SIZE_EXPECT *singleItems, int nSingles,
for (i = 0; i < nSingles; i++) {
rv = task_pipe_put(pipeId, txBuffer, singleItems[i].size,
&bytesWritten, singleItems[i].options);
&bytesWritten, singleItems[i].options,
TICKS_NONE);
if (rv != singleItems[i].rcode) {
TC_ERROR("task_pipe_put(%d) : Expected %d not %d.\n"
" bytesWritten = %d, Iteration: %d\n",
@ -377,7 +376,7 @@ int pipePutTestWork(SIZE_EXPECT *singleItems, int nSingles,
for (i = 0; i < nMany; i++) {
rv = task_pipe_put(pipeId, txBuffer, manyItems[i].size,
&bytesWritten, manyItems[i].options);
&bytesWritten, manyItems[i].options, TICKS_NONE);
if (rv != manyItems[i].rcode) {
TC_ERROR("task_pipe_put(%d) : Expected %d not %d.\n"
" bytesWritten = %d, iteration: %d\n",
@ -409,9 +408,9 @@ int pipePutTestWork(SIZE_EXPECT *singleItems, int nSingles,
/**
*
* @brief Test task_pipe_put()
* @brief Test task_pipe_put(TICKS_NONE)
*
* This routine tests the task_pipe_put() API.
* This routine tests the task_pipe_put(TICKS_NONE) API.
*
* @return TC_PASS on success, TC_FAIL on failure
*/
@ -446,7 +445,7 @@ int pipePutTest(void)
/**
*
* @brief Help test task_pipe_put_wait()
* @brief Help test task_pipe_put(TICKS_UNLIMITED)
*
* @return TC_PASS on success, TC_FAIL on failure
*/
@ -510,19 +509,19 @@ int pipePutWaitHelper(void)
/**
*
* @brief Test task_pipe_put_wait()
* @brief Test task_pipe_put(TICKS_UNLIMITED)
*
* @return TC_PASS on success, TC_FAIL on failure
*/
int pipePutWaitTest(void)
{
int rv; /* return code from task_pipe_put_wait() */
int rv; /* return code from task_pipe_put() */
int bytesWritten; /* # of bytes written to pipe */
/* 1. Fill the pipe */
rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N);
rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N, TICKS_UNLIMITED);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n",
@ -532,9 +531,9 @@ int pipePutWaitTest(void)
task_sem_give(altSem); /* Wake the alternate task */
/* 2. task_pipe_put_wait() will force a context switch to AlternateTask(). */
rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N);
/* 2. task_pipe_put() will force a context switch to AlternateTask(). */
rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N, TICKS_UNLIMITED);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n",
@ -542,9 +541,9 @@ int pipePutWaitTest(void)
return TC_FAIL;
}
/* 3. task_pipe_put_wait() will force a context switch to AlternateTask(). */
rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _1_TO_N);
/* 3. task_pipe_put() will force a context switch to AlternateTask(). */
rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _1_TO_N, TICKS_UNLIMITED);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n",
@ -553,8 +552,8 @@ int pipePutWaitTest(void)
}
/* This should return immediately as _0_TO_N with a wait is an error. */
rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _0_TO_N);
rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _0_TO_N, TICKS_UNLIMITED);
if ((rv != RC_FAIL) || (bytesWritten != 0)) {
TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n",
@ -634,19 +633,19 @@ int pipePutTimeoutHelper(void)
/**
*
* @brief Test task_pipe_put_wait_timeout()
* @brief Test task_pipe_put(timeout)
*
* @return TC_PASS on success, TC_FAIL on failure
*/
int pipePutTimeoutTest(void)
{
int rv; /* return code from task_pipe_put_wait_timeout() */
int bytesWritten; /* # of bytes written to task_pipe_put_wait_timeout() */
int rv; /* return code from task_pipe_put() */
int bytesWritten; /* # of bytes written to task_pipe_put() */
/* 1. Fill the pipe */
rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N, ONE_SECOND);
rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N, ONE_SECOND);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n",
@ -656,8 +655,8 @@ int pipePutTimeoutTest(void)
/* Timeout while waiting to put data into the pipe */
rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N, ONE_SECOND);
rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N, ONE_SECOND);
if ((rv != RC_TIME) || (bytesWritten != 0)) {
TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n",
@ -665,8 +664,8 @@ int pipePutTimeoutTest(void)
return TC_FAIL;
}
rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _1_TO_N, ONE_SECOND);
rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _1_TO_N, ONE_SECOND);
if ((rv != RC_TIME) || (bytesWritten != 0)) {
TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n",
@ -676,9 +675,9 @@ int pipePutTimeoutTest(void)
task_sem_give(altSem); /* Wake the alternate task */
/* 2. task_pipe_put_wait() will force a context switch to AlternateTask(). */
rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N, ONE_SECOND);
/* 2. task_pipe_put() will force a context switch to AlternateTask(). */
rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N, ONE_SECOND);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n",
@ -686,9 +685,9 @@ int pipePutTimeoutTest(void)
return TC_FAIL;
}
/* 3. task_pipe_put_wait() will force a context switch to AlternateTask(). */
rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _1_TO_N, ONE_SECOND);
/* 3. task_pipe_put() will force a context switch to AlternateTask(). */
rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _1_TO_N, ONE_SECOND);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n",
@ -697,8 +696,8 @@ int pipePutTimeoutTest(void)
}
/* This should return immediately as _0_TO_N with a wait is an error. */
rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _0_TO_N);
rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _0_TO_N, TICKS_UNLIMITED);
if ((rv != RC_FAIL) || (bytesWritten != 0)) {
TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n",
@ -774,8 +773,8 @@ int pipeGetTest(void)
int pipeGetWaitHelperWork(SIZE_EXPECT *items, int nItems)
{
int i; /* loop counter */
int rv; /* return value from task_pipe_put_wait() */
int bytesSent; /* # of bytes sent to task_pipe_put_wait() */
int rv; /* return value from task_pipe_put() */
int bytesSent; /* # of bytes sent to task_pipe_put() */
for (i = 0; i < nItems; i++) {
/*
@ -785,8 +784,9 @@ int pipeGetWaitHelperWork(SIZE_EXPECT *items, int nItems)
*/
bytesSent = 0;
rv = task_pipe_put_wait(pipeId, rxBuffer, items[i].size,
&bytesSent, items[i].options);
rv = task_pipe_put(pipeId, rxBuffer, items[i].size,
&bytesSent, items[i].options,
TICKS_UNLIMITED);
if ((rv != items[i].rcode) || (bytesSent != items[i].sent)) {
TC_ERROR("Expected return value %d, got %d\n"
"Expected bytesSent = %d, got %d\n",
@ -990,19 +990,19 @@ int RegressionTask(void)
microObjectsInit();
TC_PRINT("Testing task_pipe_put() ...\n");
TC_PRINT("Testing task_pipe_put(TICKS_NONE) ...\n");
tcRC = pipePutTest();
if (tcRC != TC_PASS) {
return TC_FAIL;
}
TC_PRINT("Testing task_pipe_put_wait() ...\n");
TC_PRINT("Testing task_pipe_put(TICKS_UNLIMITED) ...\n");
tcRC = pipePutWaitTest();
if (tcRC != TC_PASS) {
return TC_FAIL;
}
TC_PRINT("Testing task_pipe_put_wait_timeout() ...\n");
TC_PRINT("Testing task_pipe_put(timeout) ...\n");
tcRC = pipePutTimeoutTest();
if (tcRC != TC_PASS) {
return TC_FAIL;

View file

@ -33,9 +33,9 @@ Sample Output:
Starting pipe tests
===================================================================
Testing task_pipe_put() ...
Testing task_pipe_put_wait() ...
Testing task_pipe_put_wait_timeout() ...
Testing task_pipe_put(TICKS_NONE) ...
Testing task_pipe_put(TICKS_UNLIMITED) ...
Testing task_pipe_put(timeout) ...
Testing task_pipe_get() ...
Testing task_pipe_get_wait() ...
Testing task_pipe_get_wait_timeout() ...