Boost logo

Boost :

From: Suresh (suiyengar_at_[hidden])
Date: 2008-05-02 01:44:13


Hello,

I am working on incorporating async I/O in postgres. I had the foll. doubts in async operation.

If I do

  for(i=0;i<MAX;i++){
                bzero( (char *)&aiocb1[i], sizeof(struct aiocb) );
                aiocb1[i].aio_fildes = fd;
                aiocb1[i].aio_nbytes = BUF_SIZE;
                aiocb1[i].aio_buf = malloc(BUF_SIZE+1);
                aiocb1[i].aio_offset = off+100; //next_offset;
                aiocb1[i].aio_lio_opcode = LIO_READ;
                sigemptyset(&sig_act[i].sa_mask);
                sig_act[i].sa_flags = SA_SIGINFO;
                sig_act[i].sa_sigaction = aio_completion_handler;
                aiocb1[i].aio_sigevent.sigev_notify = SIGEV_SIGNAL;
                aiocb1[i].aio_sigevent.sigev_signo = SIGIO;
                aiocb1[i].aio_sigevent.sigev_value.sival_ptr = &aiocb1[i];
                ret = sigaction( SIGIO, &sig_act[i], NULL );

                off+=100;
                list[i]=&aiocb1[i];
        }

void aio_completion_handler( int signo, siginfo_t *info, void *context ){
        int i=0,ret;

        if (info->si_signo == SIGIO) {
        .....
      }
}

It calls the aio_completion handler once when all the i/o requests are completed and we check the signal and proceed. The same method if I use for callback using threads, then it calls the aio_completion handler MAX times instead of calling it only once.

 aiocb1[i].aio_sigevent.sigev_notify = SIGEV_THREAD;
 aiocb1[i].aio_sigevent._sigev_un._sigev_thread._function = aio_completion_handler;
....

void aio_completion_handler( sigval_t sigval )
{
...
}

How do I do something similar to signal mechanism whereing a check if the signal is mine and then only proceed.

In short, how do I guarantee that aio_completion_handler is called only once in case of list AIO. Please help me out of this.

Thanks and regards,
Suresh

           

---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.

       
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk