| 1 |
145 |
lanttu |
/*
|
| 2 |
|
|
* Copyright (c) 2010, Mentor Graphics Corporation
|
| 3 |
|
|
* All rights reserved.
|
| 4 |
|
|
*
|
| 5 |
|
|
* Redistribution and use in source and binary forms, with or without
|
| 6 |
|
|
* modification, are permitted provided that the following conditions are met:
|
| 7 |
|
|
*
|
| 8 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
| 9 |
|
|
* this list of conditions and the following disclaimer.
|
| 10 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
| 11 |
|
|
* this list of conditions and the following disclaimer in the documentation
|
| 12 |
|
|
* and/or other materials provided with the distribution.
|
| 13 |
|
|
* 3. Neither the name of the <ORGANIZATION> nor the names of its contributors
|
| 14 |
|
|
* may be used to endorse or promote products derived from this software
|
| 15 |
|
|
* without specific prior written permission.
|
| 16 |
|
|
*
|
| 17 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 18 |
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 19 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 20 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
| 21 |
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
| 22 |
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
| 23 |
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 24 |
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 25 |
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 26 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 27 |
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
| 28 |
|
|
*/
|
| 29 |
|
|
|
| 30 |
|
|
|
| 31 |
|
|
|
| 32 |
|
|
#include <openmcapi.h>
|
| 33 |
|
|
|
| 34 |
|
|
void mcapi_copy_request(mcapi_request_t *dest_req, mcapi_request_t *src_req);
|
| 35 |
|
|
mcapi_boolean_t __mcapi_test(mcapi_request_t *request, size_t *size,
|
| 36 |
|
|
mcapi_status_t *mcapi_status);
|
| 37 |
|
|
|
| 38 |
|
|
/*************************************************************************
|
| 39 |
|
|
*
|
| 40 |
|
|
* FUNCTION
|
| 41 |
|
|
*
|
| 42 |
|
|
* mcapi_wait
|
| 43 |
|
|
*
|
| 44 |
|
|
* DESCRIPTION
|
| 45 |
|
|
*
|
| 46 |
|
|
* Blocking API routine that waits for a non-blocking operation to
|
| 47 |
|
|
* complete. The routine returns if the specific operation has
|
| 48 |
|
|
* completed or been canceled, or if the call to mcapi_wait times
|
| 49 |
|
|
* out on completion of the respective operation.
|
| 50 |
|
|
*
|
| 51 |
|
|
* INPUTS
|
| 52 |
|
|
*
|
| 53 |
|
|
* *request A pointer to the request structure filled
|
| 54 |
|
|
* in by the specific operation waiting for
|
| 55 |
|
|
* completion.
|
| 56 |
|
|
* *size A pointer to memory that will be filled in
|
| 57 |
|
|
* with the number of bytes sent/received if
|
| 58 |
|
|
* the operation in question is a send or
|
| 59 |
|
|
* receive operation.
|
| 60 |
|
|
* *mcapi_status A pointer to memory that will be filled in
|
| 61 |
|
|
* with the status of the call.
|
| 62 |
|
|
* timeout The number milliseconds to wait for
|
| 63 |
|
|
* completion of the respective operation
|
| 64 |
|
|
* before returning from mcapi_wait().
|
| 65 |
|
|
* A value of MCAPI_TIMEOUT_INFINITE indicates no
|
| 66 |
|
|
* timeout.
|
| 67 |
|
|
*
|
| 68 |
|
|
* OUTPUTS
|
| 69 |
|
|
*
|
| 70 |
|
|
* MCAPI_TRUE The operation has completed.
|
| 71 |
|
|
* MCAPI_FALSE An error has occurred.
|
| 72 |
|
|
*
|
| 73 |
|
|
*************************************************************************/
|
| 74 |
|
|
mcapi_boolean_t mcapi_wait(mcapi_request_t *request, size_t *size,
|
| 75 |
|
|
mcapi_status_t *mcapi_status,
|
| 76 |
|
|
mcapi_timeout_t timeout)
|
| 77 |
|
|
{
|
| 78 |
|
|
MCAPI_GLOBAL_DATA *node_data;
|
| 79 |
|
|
mcapi_request_t req_copy;
|
| 80 |
|
|
mcapi_boolean_t ret_val = MCAPI_FALSE;
|
| 81 |
|
|
|
| 82 |
|
|
/* Ensure the status value is valid. */
|
| 83 |
|
|
if (mcapi_status)
|
| 84 |
|
|
{
|
| 85 |
|
|
/* Get the lock. */
|
| 86 |
|
|
mcapi_lock_node_data();
|
| 87 |
|
|
|
| 88 |
|
|
/* Check to see if the request has completed. */
|
| 89 |
|
|
ret_val = __mcapi_test(request, size, mcapi_status);
|
| 90 |
|
|
|
| 91 |
|
|
/* If the request has not been completed. */
|
| 92 |
|
|
if ( (*mcapi_status == MCAPI_PENDING) && (ret_val == MCAPI_FALSE) )
|
| 93 |
|
|
{
|
| 94 |
|
|
/* Get a pointer to the global node list. */
|
| 95 |
|
|
node_data = mcapi_get_node_data();
|
| 96 |
|
|
|
| 97 |
|
|
/* Replicate the target request structure. */
|
| 98 |
|
|
memcpy(&req_copy, request, sizeof(mcapi_request_t));
|
| 99 |
|
|
|
| 100 |
|
|
/* Suspend until the operation completes or timeout occurs. */
|
| 101 |
|
|
MCAPI_Suspend_Task(node_data, &req_copy, &req_copy.mcapi_cond,
|
| 102 |
|
|
timeout);
|
| 103 |
|
|
|
| 104 |
|
|
/* Copy the status of the request into the original request
|
| 105 |
|
|
* structure so a subsequent call to test will pass. If the
|
| 106 |
|
|
* original request structure was on the request list, the
|
| 107 |
|
|
* status will already be set, but not all request structures
|
| 108 |
|
|
* get put on the list.
|
| 109 |
|
|
*/
|
| 110 |
|
|
request->mcapi_status = req_copy.mcapi_status;
|
| 111 |
|
|
|
| 112 |
|
|
/* The wait operation timed out before the operation being
|
| 113 |
|
|
* tested could finish.
|
| 114 |
|
|
*/
|
| 115 |
|
|
if (req_copy.mcapi_status == MCAPI_PENDING)
|
| 116 |
|
|
{
|
| 117 |
|
|
*mcapi_status = MCAPI_TIMEOUT;
|
| 118 |
|
|
|
| 119 |
|
|
/* Remove the request from the list. */
|
| 120 |
|
|
mcapi_remove(&node_data->mcapi_local_req_queue, &req_copy);
|
| 121 |
|
|
}
|
| 122 |
|
|
|
| 123 |
|
|
/* The operation completed or was canceled. */
|
| 124 |
|
|
else
|
| 125 |
|
|
{
|
| 126 |
|
|
*mcapi_status = req_copy.mcapi_status;
|
| 127 |
|
|
}
|
| 128 |
|
|
|
| 129 |
|
|
/* Only return MCAPI_TRUE if the operation completed
|
| 130 |
|
|
* successfully.
|
| 131 |
|
|
*/
|
| 132 |
|
|
if (*mcapi_status == MCAPI_SUCCESS)
|
| 133 |
|
|
{
|
| 134 |
|
|
ret_val = MCAPI_TRUE;
|
| 135 |
|
|
|
| 136 |
|
|
/* If the request was a send or receive, record the number
|
| 137 |
|
|
* of bytes sent or received.
|
| 138 |
|
|
*/
|
| 139 |
|
|
if ( (req_copy.mcapi_type == MCAPI_REQ_TX_FIN) ||
|
| 140 |
|
|
(req_copy.mcapi_type == MCAPI_REQ_RX_FIN) )
|
| 141 |
|
|
{
|
| 142 |
|
|
*size = req_copy.mcapi_byte_count;
|
| 143 |
|
|
}
|
| 144 |
|
|
}
|
| 145 |
|
|
}
|
| 146 |
|
|
|
| 147 |
|
|
/* Release the lock. */
|
| 148 |
|
|
mcapi_unlock_node_data();
|
| 149 |
|
|
}
|
| 150 |
|
|
|
| 151 |
|
|
return (ret_val);
|
| 152 |
|
|
|
| 153 |
|
|
}
|