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,3 +1,12 @@
|
|||||||
|
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>
|
2011-01-08 Alin Rus <alin.codejunkie@gmail.com>
|
||||||
|
|
||||||
* posix/src/aio_misc.c: Fix rtems_aio_remove_req did not iterate
|
* posix/src/aio_misc.c: Fix rtems_aio_remove_req did not iterate
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ static int rtems_rtc_shell_main( int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 3) {
|
if (argc > 3) {
|
||||||
rv = sscanf( argv [3], "%" PRIu32, v);
|
rv = sscanf( argv [3], "%5" PRIu32, v);
|
||||||
|
|
||||||
if (rv == 1) {
|
if (rv == 1) {
|
||||||
tod.ticks = v [0];
|
tod.ticks = v [0];
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ static void rtems_shell_joel_usage(void)
|
|||||||
|
|
||||||
static int findOnPATH(
|
static int findOnPATH(
|
||||||
const char *userScriptName,
|
const char *userScriptName,
|
||||||
char *scriptFile
|
char *scriptFile,
|
||||||
|
size_t scriptFileLength
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int sc;
|
int sc;
|
||||||
@@ -56,7 +57,7 @@ static int findOnPATH(
|
|||||||
* qualified path name and just use it.
|
* qualified path name and just use it.
|
||||||
*/
|
*/
|
||||||
if ( userScriptName[0] == '/' ) {
|
if ( userScriptName[0] == '/' ) {
|
||||||
strcpy( scriptFile, userScriptName );
|
strncpy( scriptFile, userScriptName, PATH_MAX );
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* For now, the provided name is just turned into a fully
|
* 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? */
|
/* XXX should use strncat but what is the limit? */
|
||||||
getcwd( scriptFile, PATH_MAX );
|
getcwd( scriptFile, PATH_MAX );
|
||||||
strcat( scriptFile, "/" );
|
strncat( scriptFile, "/", PATH_MAX );
|
||||||
strcat(
|
strncat(
|
||||||
scriptFile,
|
scriptFile,
|
||||||
( (userScriptName[0] == '.' && userScriptName[1] == '/') ?
|
( (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
|
* NOTE: It is terrible that this is done twice but it
|
||||||
* seems to be the most expedient thing.
|
* 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 ) {
|
if ( sc ) {
|
||||||
fprintf( stderr, "%s: command not found\n", argv[0] );
|
fprintf( stderr, "%s: command not found\n", argv[0] );
|
||||||
return -1;
|
return -1;
|
||||||
@@ -258,7 +260,7 @@ int rtems_shell_script_file(
|
|||||||
/*
|
/*
|
||||||
* Find argv[0] on the path
|
* Find argv[0] on the path
|
||||||
*/
|
*/
|
||||||
sc = findOnPATH( argv[0], scriptFile );
|
sc = findOnPATH( argv[0], scriptFile, PATH_MAX );
|
||||||
if ( sc ) {
|
if ( sc ) {
|
||||||
fprintf( stderr, "%s: command not found\n", argv[0] );
|
fprintf( stderr, "%s: command not found\n", argv[0] );
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ int aio_cancel(int fildes, struct aiocb *aiocbp)
|
|||||||
pthread_mutex_unlock (&aio_request_queue.mutex);
|
pthread_mutex_unlock (&aio_request_queue.mutex);
|
||||||
return AIO_ALLDONE;
|
return AIO_ALLDONE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
AIO_printf ("Request on [WQ]\n");
|
AIO_printf ("Request on [WQ]\n");
|
||||||
|
|
||||||
pthread_mutex_lock (&r_chain->mutex);
|
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 (&r_chain->mutex);
|
||||||
pthread_mutex_unlock (&aio_request_queue.mutex);
|
pthread_mutex_unlock (&aio_request_queue.mutex);
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return AIO_ALLDONE;
|
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
|
* The license and distribution terms for this file may be
|
||||||
* found in the file LICENSE in this distribution or at
|
* found in the file LICENSE in this distribution or at
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <rtems/posix/aio_misc.h>
|
#include <rtems/posix/aio_misc.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
static void *rtems_aio_handle (void *arg);
|
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;
|
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
|
* rtems_aio_insert_prio
|
||||||
*
|
*
|
||||||
@@ -337,11 +369,11 @@ rtems_aio_enqueue (rtems_aio_request *req)
|
|||||||
r_chain->new_fd = 0;
|
r_chain->new_fd = 0;
|
||||||
pthread_mutex_init (&r_chain->mutex, NULL);
|
pthread_mutex_init (&r_chain->mutex, NULL);
|
||||||
pthread_cond_init (&r_chain->cond, NULL);
|
pthread_cond_init (&r_chain->cond, NULL);
|
||||||
pthread_cond_signal (&aio_request_queue.new_req);
|
|
||||||
++aio_request_queue.idle_threads;
|
|
||||||
} else
|
} else
|
||||||
/* just insert the request in the existing fd chain */
|
/* just insert the request in the existing fd chain */
|
||||||
rtems_aio_insert_prio (&r_chain->perfd, req);
|
rtems_aio_insert_prio (&r_chain->perfd, req);
|
||||||
|
if (aio_request_queue.idle_threads > 0)
|
||||||
|
pthread_cond_signal (&aio_request_queue.new_req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,6 +425,7 @@ rtems_aio_handle (void *arg)
|
|||||||
requests to this fd chain */
|
requests to this fd chain */
|
||||||
if (!rtems_chain_is_empty (chain)) {
|
if (!rtems_chain_is_empty (chain)) {
|
||||||
|
|
||||||
|
AIO_printf ("Get new request from not empty chain\n");
|
||||||
node = rtems_chain_first (chain);
|
node = rtems_chain_first (chain);
|
||||||
req = (rtems_aio_request *) node;
|
req = (rtems_aio_request *) node;
|
||||||
|
|
||||||
@@ -408,18 +441,21 @@ rtems_aio_handle (void *arg)
|
|||||||
|
|
||||||
switch (req->aiocbp->aio_lio_opcode) {
|
switch (req->aiocbp->aio_lio_opcode) {
|
||||||
case LIO_READ:
|
case LIO_READ:
|
||||||
|
AIO_printf ("read\n");
|
||||||
result = pread (req->aiocbp->aio_fildes,
|
result = pread (req->aiocbp->aio_fildes,
|
||||||
(void *) req->aiocbp->aio_buf,
|
(void *) req->aiocbp->aio_buf,
|
||||||
req->aiocbp->aio_nbytes, req->aiocbp->aio_offset);
|
req->aiocbp->aio_nbytes, req->aiocbp->aio_offset);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIO_WRITE:
|
case LIO_WRITE:
|
||||||
|
AIO_printf ("write\n");
|
||||||
result = pwrite (req->aiocbp->aio_fildes,
|
result = pwrite (req->aiocbp->aio_fildes,
|
||||||
(void *) req->aiocbp->aio_buf,
|
(void *) req->aiocbp->aio_buf,
|
||||||
req->aiocbp->aio_nbytes, req->aiocbp->aio_offset);
|
req->aiocbp->aio_nbytes, req->aiocbp->aio_offset);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIO_SYNC:
|
case LIO_SYNC:
|
||||||
|
AIO_printf ("sync\n");
|
||||||
result = fsync (req->aiocbp->aio_fildes);
|
result = fsync (req->aiocbp->aio_fildes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -448,15 +484,19 @@ rtems_aio_handle (void *arg)
|
|||||||
|
|
||||||
struct timespec timeout;
|
struct timespec timeout;
|
||||||
|
|
||||||
|
AIO_printf ("Chain is empty [WQ], wait for work\n");
|
||||||
|
|
||||||
pthread_mutex_unlock (&r_chain->mutex);
|
pthread_mutex_unlock (&r_chain->mutex);
|
||||||
pthread_mutex_lock (&aio_request_queue.mutex);
|
pthread_mutex_lock (&aio_request_queue.mutex);
|
||||||
|
|
||||||
if (rtems_chain_is_empty (chain))
|
if (rtems_chain_is_empty (chain))
|
||||||
{
|
{
|
||||||
clock_gettime (CLOCK_REALTIME, &timeout);
|
clock_gettime (CLOCK_REALTIME, &timeout);
|
||||||
timeout.tv_sec += 3;
|
timeout.tv_sec += 3;
|
||||||
timeout.tv_nsec = 0;
|
timeout.tv_nsec = 0;
|
||||||
result = pthread_cond_timedwait (&r_chain->cond,
|
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
|
/* If no requests were added to the chain we delete the fd chain from
|
||||||
the queue and start working with idle fd chains */
|
the queue and start working with idle fd chains */
|
||||||
@@ -469,10 +509,14 @@ rtems_aio_handle (void *arg)
|
|||||||
/* If the idle chain is empty sleep for 3 seconds and wait for a
|
/* If the idle chain is empty sleep for 3 seconds and wait for a
|
||||||
signal. The thread now becomes idle. */
|
signal. The thread now becomes idle. */
|
||||||
if (rtems_chain_is_empty (&aio_request_queue.idle_req)) {
|
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.idle_threads;
|
||||||
|
--aio_request_queue.active_threads;
|
||||||
clock_gettime (CLOCK_REALTIME, &timeout);
|
clock_gettime (CLOCK_REALTIME, &timeout);
|
||||||
timeout.tv_sec += 3;
|
timeout.tv_sec += 3;
|
||||||
timeout.tv_nsec = 0;
|
timeout.tv_nsec = 0;
|
||||||
|
|
||||||
result = pthread_cond_timedwait (&aio_request_queue.new_req,
|
result = pthread_cond_timedwait (&aio_request_queue.new_req,
|
||||||
&aio_request_queue.mutex,
|
&aio_request_queue.mutex,
|
||||||
&timeout);
|
&timeout);
|
||||||
@@ -480,34 +524,33 @@ rtems_aio_handle (void *arg)
|
|||||||
/* If no new fd chain was added in the idle requests
|
/* If no new fd chain was added in the idle requests
|
||||||
then this thread is finished */
|
then this thread is finished */
|
||||||
if (result == ETIMEDOUT) {
|
if (result == ETIMEDOUT) {
|
||||||
|
AIO_printf ("Etimeout\n");
|
||||||
|
--aio_request_queue.idle_threads;
|
||||||
pthread_mutex_unlock (&aio_request_queue.mutex);
|
pthread_mutex_unlock (&aio_request_queue.mutex);
|
||||||
return NULL;
|
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
|
/* Otherwise move this chain to the working chain and
|
||||||
/* If there was a request added in the initial fd chain then release
|
start the loop all over again */
|
||||||
the mutex and process it */
|
AIO_printf ("Work on idle\n");
|
||||||
pthread_mutex_unlock (&aio_request_queue.mutex);
|
--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");
|
AIO_printf ("Thread finished\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user