File indexing completed on 2025-05-11 08:24:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #ifdef HAVE_CONFIG_H
0041 #include "config.h"
0042 #endif
0043
0044 #include <aio.h>
0045 #include <rtems/posix/aio_misc.h>
0046 #include <errno.h>
0047 #include <stdlib.h>
0048 #include <rtems/seterr.h>
0049
0050 int aio_cancel( int fildes, struct aiocb *aiocbp )
0051 {
0052 rtems_chain_control *idle_req_chain = &aio_request_queue.idle_req;
0053 rtems_chain_control *work_req_chain = &aio_request_queue.work_req;
0054 rtems_aio_request_chain *r_chain;
0055 int result;
0056
0057 pthread_mutex_lock( &aio_request_queue.mutex );
0058
0059 if ( fcntl( fildes, F_GETFD ) < 0 ) {
0060 pthread_mutex_unlock( &aio_request_queue.mutex );
0061 rtems_set_errno_and_return_minus_one( EBADF );
0062 }
0063
0064
0065 if ( aiocbp == NULL ) {
0066 AIO_printf( "Cancel all requests\n" );
0067
0068 r_chain = rtems_aio_search_fd( work_req_chain, fildes, 0 );
0069 if ( r_chain == NULL ) {
0070 AIO_printf( "Request chain not on [WQ]\n" );
0071
0072 if ( !rtems_chain_is_empty( idle_req_chain ) ) {
0073 r_chain = rtems_aio_search_fd( idle_req_chain, fildes, 0 );
0074 if ( r_chain == NULL ) {
0075 pthread_mutex_unlock( &aio_request_queue.mutex );
0076 return AIO_ALLDONE;
0077 }
0078
0079 AIO_printf( "Request chain on [IQ]\n" );
0080
0081 rtems_chain_extract( &r_chain->next_fd );
0082 rtems_aio_remove_fd( r_chain );
0083 pthread_mutex_destroy( &r_chain->mutex );
0084 pthread_cond_destroy( &r_chain->cond );
0085 free( r_chain );
0086
0087 pthread_mutex_unlock( &aio_request_queue.mutex );
0088 return AIO_CANCELED;
0089 }
0090
0091 pthread_mutex_unlock( &aio_request_queue.mutex );
0092 return AIO_ALLDONE;
0093 }
0094
0095 AIO_printf( "Request chain on [WQ]\n" );
0096
0097 pthread_mutex_lock( &r_chain->mutex );
0098 rtems_chain_extract( &r_chain->next_fd );
0099 rtems_aio_remove_fd( r_chain );
0100 pthread_mutex_unlock( &r_chain->mutex );
0101 pthread_mutex_unlock( &aio_request_queue.mutex );
0102 return AIO_CANCELED;
0103 } else {
0104 AIO_printf( "Cancel request\n" );
0105
0106 if( aiocbp->aio_fildes != fildes ) {
0107 pthread_mutex_unlock( &aio_request_queue.mutex );
0108 rtems_set_errno_and_return_minus_one( EINVAL );
0109 }
0110
0111 r_chain = rtems_aio_search_fd( work_req_chain, fildes, 0 );
0112 if ( r_chain == NULL ) {
0113 if ( !rtems_chain_is_empty( idle_req_chain ) ) {
0114 r_chain = rtems_aio_search_fd( idle_req_chain, fildes, 0 );
0115 if (r_chain == NULL) {
0116 pthread_mutex_unlock( &aio_request_queue.mutex );
0117 rtems_set_errno_and_return_minus_one( EINVAL );
0118 }
0119
0120 AIO_printf( "Request on [IQ]\n" );
0121
0122 result = rtems_aio_remove_req( &r_chain->perfd, aiocbp );
0123 pthread_mutex_unlock( &aio_request_queue.mutex );
0124 return result;
0125 } else {
0126 pthread_mutex_unlock( &aio_request_queue.mutex );
0127 return AIO_ALLDONE;
0128 }
0129 }
0130
0131 AIO_printf( "Request on [WQ]\n" );
0132
0133 pthread_mutex_lock( &r_chain->mutex );
0134 result = rtems_aio_remove_req( &r_chain->perfd, aiocbp );
0135 pthread_mutex_unlock( &r_chain->mutex );
0136 pthread_mutex_unlock( &aio_request_queue.mutex );
0137 return result;
0138 }
0139 return AIO_ALLDONE;
0140 }
0141