forked from Imagelibrary/rtems
2011-01-17 Alin Rus <alin.codejunkie@gmail.com>
* posix/src/aio_cancel.c: Fixed ending of if braces. 2011-01-17 Alin Rus <alin.codejunkie@gmail.com> * posix/src/aio_misc.c: Add debug information. Fixed idle_threads/ active_threads issues. Fixed infinite loop in rtems_aio_handle().
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
2011-01-17 Alin Rus <alin.codejunkie@gmail.com>
|
||||
|
||||
* posix/src/aio_cancel.c: Fixed ending of if braces.
|
||||
|
||||
2011-01-17 Alin Rus <alin.codejunkie@gmail.com>
|
||||
|
||||
* posix/src/aio_misc.c: Add debug information. Fixed idle_threads/
|
||||
active_threads issues. Fixed infinite loop in rtems_aio_handle().
|
||||
|
||||
2011-01-08 Alin Rus <alin.codejunkie@gmail.com>
|
||||
|
||||
|
||||
* posix/src/aio_misc.c: Fix rtems_aio_remove_req did not iterate
|
||||
over chain.
|
||||
* posix/src/aio_cancel.c: Add debug information. Add check for
|
||||
|
||||
@@ -125,7 +125,7 @@ static int rtems_rtc_shell_main( int argc, char **argv)
|
||||
}
|
||||
|
||||
if (argc > 3) {
|
||||
rv = sscanf( argv [3], "%" PRIu32, v);
|
||||
rv = sscanf( argv [3], "%5" PRIu32, v);
|
||||
|
||||
if (rv == 1) {
|
||||
tod.ticks = v [0];
|
||||
|
||||
@@ -46,7 +46,8 @@ static void rtems_shell_joel_usage(void)
|
||||
|
||||
static int findOnPATH(
|
||||
const char *userScriptName,
|
||||
char *scriptFile
|
||||
char *scriptFile,
|
||||
size_t scriptFileLength
|
||||
)
|
||||
{
|
||||
int sc;
|
||||
@@ -56,7 +57,7 @@ static int findOnPATH(
|
||||
* qualified path name and just use it.
|
||||
*/
|
||||
if ( userScriptName[0] == '/' ) {
|
||||
strcpy( scriptFile, userScriptName );
|
||||
strncpy( scriptFile, userScriptName, PATH_MAX );
|
||||
} else {
|
||||
/*
|
||||
* For now, the provided name is just turned into a fully
|
||||
@@ -66,11 +67,12 @@ static int findOnPATH(
|
||||
|
||||
/* XXX should use strncat but what is the limit? */
|
||||
getcwd( scriptFile, PATH_MAX );
|
||||
strcat( scriptFile, "/" );
|
||||
strcat(
|
||||
strncat( scriptFile, "/", PATH_MAX );
|
||||
strncat(
|
||||
scriptFile,
|
||||
( (userScriptName[0] == '.' && userScriptName[1] == '/') ?
|
||||
&userScriptName[2] : userScriptName)
|
||||
&userScriptName[2] : userScriptName),
|
||||
PATH_MAX
|
||||
);
|
||||
}
|
||||
|
||||
@@ -187,7 +189,7 @@ int rtems_shell_main_joel(
|
||||
* NOTE: It is terrible that this is done twice but it
|
||||
* seems to be the most expedient thing.
|
||||
*/
|
||||
sc = findOnPATH( argv[getopt_reent.optind], scriptFile );
|
||||
sc = findOnPATH( argv[getopt_reent.optind], scriptFile, PATH_MAX );
|
||||
if ( sc ) {
|
||||
fprintf( stderr, "%s: command not found\n", argv[0] );
|
||||
return -1;
|
||||
@@ -258,7 +260,7 @@ int rtems_shell_script_file(
|
||||
/*
|
||||
* Find argv[0] on the path
|
||||
*/
|
||||
sc = findOnPATH( argv[0], scriptFile );
|
||||
sc = findOnPATH( argv[0], scriptFile, PATH_MAX );
|
||||
if ( sc ) {
|
||||
fprintf( stderr, "%s: command not found\n", argv[0] );
|
||||
return -1;
|
||||
|
||||
@@ -113,7 +113,7 @@ int aio_cancel(int fildes, struct aiocb *aiocbp)
|
||||
pthread_mutex_unlock (&aio_request_queue.mutex);
|
||||
return AIO_ALLDONE;
|
||||
}
|
||||
|
||||
}
|
||||
AIO_printf ("Request on [WQ]\n");
|
||||
|
||||
pthread_mutex_lock (&r_chain->mutex);
|
||||
@@ -121,7 +121,6 @@ int aio_cancel(int fildes, struct aiocb *aiocbp)
|
||||
pthread_mutex_unlock (&r_chain->mutex);
|
||||
pthread_mutex_unlock (&aio_request_queue.mutex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return AIO_ALLDONE;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
|
||||
* Copyright 2010-2011, Alin Rus <alin.codejunkie@gmail.com>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <rtems/posix/aio_misc.h>
|
||||
#include <errno.h>
|
||||
|
||||
static void *rtems_aio_handle (void *arg);
|
||||
|
||||
@@ -123,6 +124,37 @@ rtems_aio_search_fd (rtems_chain_control *chain, int fildes, int create)
|
||||
return r_chain;
|
||||
}
|
||||
|
||||
/*
|
||||
* rtems_aio_move_to_work
|
||||
*
|
||||
* Move chain of requests from IQ to WQ
|
||||
*
|
||||
* Input parameters:
|
||||
* r_chain - chain of requests
|
||||
*
|
||||
* Output paramteres:
|
||||
* NONE
|
||||
*/
|
||||
|
||||
void
|
||||
rtems_aio_move_to_work (rtems_aio_request_chain *r_chain)
|
||||
{
|
||||
rtems_aio_request_chain *temp;
|
||||
rtems_chain_node *node;
|
||||
|
||||
node = rtems_chain_first (&aio_request_queue.work_req);
|
||||
temp = (rtems_aio_request_chain *) node;
|
||||
|
||||
while (temp->fildes < r_chain->fildes &&
|
||||
!rtems_chain_is_tail (&aio_request_queue.work_req, node)) {
|
||||
node = rtems_chain_next (node);
|
||||
temp = (rtems_aio_request_chain *) node;
|
||||
}
|
||||
|
||||
rtems_chain_insert (rtems_chain_previous (node), &r_chain->next_fd);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* rtems_aio_insert_prio
|
||||
*
|
||||
@@ -291,7 +323,7 @@ rtems_aio_enqueue (rtems_aio_request *req)
|
||||
r_chain->new_fd = 0;
|
||||
pthread_mutex_init (&r_chain->mutex, NULL);
|
||||
pthread_cond_init (&r_chain->cond, NULL);
|
||||
|
||||
|
||||
AIO_printf ("New thread \n");
|
||||
result = pthread_create (&thid, &aio_request_queue.attr,
|
||||
rtems_aio_handle, (void *) r_chain);
|
||||
@@ -337,11 +369,11 @@ rtems_aio_enqueue (rtems_aio_request *req)
|
||||
r_chain->new_fd = 0;
|
||||
pthread_mutex_init (&r_chain->mutex, NULL);
|
||||
pthread_cond_init (&r_chain->cond, NULL);
|
||||
pthread_cond_signal (&aio_request_queue.new_req);
|
||||
++aio_request_queue.idle_threads;
|
||||
} else
|
||||
/* just insert the request in the existing fd chain */
|
||||
rtems_aio_insert_prio (&r_chain->perfd, req);
|
||||
if (aio_request_queue.idle_threads > 0)
|
||||
pthread_cond_signal (&aio_request_queue.new_req);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,7 +417,7 @@ rtems_aio_handle (void *arg)
|
||||
if (result != 0)
|
||||
return NULL;
|
||||
|
||||
chain = &r_chain->perfd;
|
||||
chain = &r_chain->perfd;
|
||||
|
||||
/* If the locked chain is not empty, take the first
|
||||
request extract it, unlock the chain and process
|
||||
@@ -393,6 +425,7 @@ rtems_aio_handle (void *arg)
|
||||
requests to this fd chain */
|
||||
if (!rtems_chain_is_empty (chain)) {
|
||||
|
||||
AIO_printf ("Get new request from not empty chain\n");
|
||||
node = rtems_chain_first (chain);
|
||||
req = (rtems_aio_request *) node;
|
||||
|
||||
@@ -408,18 +441,21 @@ rtems_aio_handle (void *arg)
|
||||
|
||||
switch (req->aiocbp->aio_lio_opcode) {
|
||||
case LIO_READ:
|
||||
AIO_printf ("read\n");
|
||||
result = pread (req->aiocbp->aio_fildes,
|
||||
(void *) req->aiocbp->aio_buf,
|
||||
req->aiocbp->aio_nbytes, req->aiocbp->aio_offset);
|
||||
break;
|
||||
|
||||
case LIO_WRITE:
|
||||
AIO_printf ("write\n");
|
||||
result = pwrite (req->aiocbp->aio_fildes,
|
||||
(void *) req->aiocbp->aio_buf,
|
||||
req->aiocbp->aio_nbytes, req->aiocbp->aio_offset);
|
||||
break;
|
||||
|
||||
case LIO_SYNC:
|
||||
AIO_printf ("sync\n");
|
||||
result = fsync (req->aiocbp->aio_fildes);
|
||||
break;
|
||||
|
||||
@@ -445,19 +481,23 @@ rtems_aio_handle (void *arg)
|
||||
If there was no request added sleep for 3 seconds and
|
||||
wait for a signal on chain, this will unlock the queue.
|
||||
The fd chain is already unlocked */
|
||||
|
||||
|
||||
struct timespec timeout;
|
||||
|
||||
AIO_printf ("Chain is empty [WQ], wait for work\n");
|
||||
|
||||
pthread_mutex_unlock (&r_chain->mutex);
|
||||
pthread_mutex_lock (&aio_request_queue.mutex);
|
||||
|
||||
if (rtems_chain_is_empty (chain))
|
||||
{
|
||||
clock_gettime (CLOCK_REALTIME, &timeout);
|
||||
timeout.tv_sec += 3;
|
||||
timeout.tv_nsec = 0;
|
||||
result = pthread_cond_timedwait (&r_chain->cond,
|
||||
&aio_request_queue.mutex, &timeout);
|
||||
|
||||
&aio_request_queue.mutex,
|
||||
&timeout);
|
||||
|
||||
/* If no requests were added to the chain we delete the fd chain from
|
||||
the queue and start working with idle fd chains */
|
||||
if (result == ETIMEDOUT) {
|
||||
@@ -469,10 +509,14 @@ rtems_aio_handle (void *arg)
|
||||
/* If the idle chain is empty sleep for 3 seconds and wait for a
|
||||
signal. The thread now becomes idle. */
|
||||
if (rtems_chain_is_empty (&aio_request_queue.idle_req)) {
|
||||
AIO_printf ("Chain is empty [IQ], wait for work\n");
|
||||
|
||||
++aio_request_queue.idle_threads;
|
||||
--aio_request_queue.active_threads;
|
||||
clock_gettime (CLOCK_REALTIME, &timeout);
|
||||
timeout.tv_sec += 3;
|
||||
timeout.tv_nsec = 0;
|
||||
|
||||
result = pthread_cond_timedwait (&aio_request_queue.new_req,
|
||||
&aio_request_queue.mutex,
|
||||
&timeout);
|
||||
@@ -480,34 +524,33 @@ rtems_aio_handle (void *arg)
|
||||
/* If no new fd chain was added in the idle requests
|
||||
then this thread is finished */
|
||||
if (result == ETIMEDOUT) {
|
||||
AIO_printf ("Etimeout\n");
|
||||
--aio_request_queue.idle_threads;
|
||||
pthread_mutex_unlock (&aio_request_queue.mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Otherwise move this chain to the working chain and
|
||||
start the loop all over again */
|
||||
--aio_request_queue.idle_threads;
|
||||
node = rtems_chain_first (&aio_request_queue.idle_req);
|
||||
rtems_chain_extract (node);
|
||||
r_chain = rtems_aio_search_fd (&aio_request_queue.work_req,
|
||||
((rtems_aio_request_chain *)node)->fildes,
|
||||
1);
|
||||
r_chain->new_fd = 0;
|
||||
pthread_mutex_init (&r_chain->mutex, NULL);
|
||||
pthread_cond_init (&r_chain->cond, NULL);
|
||||
|
||||
r_chain->perfd = ((rtems_aio_request_chain *)node)->perfd;
|
||||
}
|
||||
else
|
||||
/* If there was a request added in the initial fd chain then release
|
||||
the mutex and process it */
|
||||
pthread_mutex_unlock (&aio_request_queue.mutex);
|
||||
/* Otherwise move this chain to the working chain and
|
||||
start the loop all over again */
|
||||
AIO_printf ("Work on idle\n");
|
||||
--aio_request_queue.idle_threads;
|
||||
++aio_request_queue.active_threads;
|
||||
|
||||
node = rtems_chain_first (&aio_request_queue.idle_req);
|
||||
rtems_chain_extract (node);
|
||||
|
||||
r_chain = (rtems_aio_request_chain *) node;
|
||||
rtems_aio_move_to_work (r_chain);
|
||||
|
||||
}
|
||||
}
|
||||
/* If there was a request added in the initial fd chain then release
|
||||
the mutex and process it */
|
||||
pthread_mutex_unlock (&aio_request_queue.mutex);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AIO_printf ("Thread finished\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user