diff options
| author | root <root> | 2011-07-18 02:59:58 +0000 | 
|---|---|---|
| committer | root <root> | 2011-07-18 02:59:58 +0000 | 
| commit | 96045cbe9a089897107decefa9ff97d0d3b2810e (patch) | |
| tree | 986553ac3cf61d4548b0e744a8dc3d4ba6da1f2b | |
| parent | 7b5974c9e146f327c9a27f1d97d7fb6a8b95d15d (diff) | |
*** empty log message ***rel-4_0
| -rw-r--r-- | eio.c | 43 | ||||
| -rw-r--r-- | eio.pod | 36 | 
2 files changed, 35 insertions, 44 deletions
| @@ -235,13 +235,13 @@ static void eio_destroy (eio_req *req);  #define EIO_BUFSIZE 65536  #define dBUF	 				\ -  char *eio_buf;				\ -  ETP_WORKER_LOCK (self);			\ -  self->dbuf = eio_buf = malloc (EIO_BUFSIZE);	\ -  ETP_WORKER_UNLOCK (self);			\ +  char *eio_buf = malloc (EIO_BUFSIZE);		\    errno = ENOMEM;				\    if (!eio_buf)					\ -    return -1; +    return -1 + +#define FUBd					\ +  free (eio_buf)  #define EIO_TICKS ((1000000 + 1023) >> 10) @@ -257,16 +257,6 @@ static int eio_finish (eio_req *req);  static void eio_execute (struct etp_worker *self, eio_req *req);  #define ETP_EXECUTE(wrk,req) eio_execute (wrk,req) -#define ETP_WORKER_CLEAR(req)	\ -  if (wrk->dbuf)		\ -    {				\ -      free (wrk->dbuf);		\ -      wrk->dbuf = 0;		\ -    } - -#define ETP_WORKER_COMMON \ -  void *dbuf; -  /*****************************************************************************/  #define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) @@ -317,7 +307,9 @@ typedef struct etp_worker    /* locked by reslock, reqlock or wrklock */    ETP_REQ *req; /* currently processed request */ +#ifdef ETP_WORKER_COMMON    ETP_WORKER_COMMON +#endif  } etp_worker;  static etp_worker wrk_first; /* NOT etp */ @@ -330,7 +322,6 @@ static etp_worker wrk_first; /* NOT etp */  static void ecb_cold  etp_worker_clear (etp_worker *wrk)  { -  ETP_WORKER_CLEAR (wrk);  }  static void ecb_cold @@ -999,6 +990,8 @@ eio__readahead (int fd, off_t offset, size_t count, etp_worker *self)        todo   -= len;      } +  FUBd; +    errno = 0;    return count;  } @@ -1007,7 +1000,7 @@ eio__readahead (int fd, off_t offset, size_t count, etp_worker *self)  /* sendfile always needs emulation */  static eio_ssize_t -eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) +eio__sendfile (int ofd, int ifd, off_t offset, size_t count)  {    eio_ssize_t written = 0;    eio_ssize_t res; @@ -1153,6 +1146,8 @@ eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self)            res    += cnt;            count  -= cnt;          } + +      FUBd;      }    return res; @@ -2027,7 +2022,7 @@ eio_execute (etp_worker *self, eio_req *req)                                        : write     (req->int1, req->ptr2, req->size); break;        case EIO_READAHEAD: req->result = readahead     (req->int1, req->offs, req->size); break; -      case EIO_SENDFILE:  req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size, self); break; +      case EIO_SENDFILE:  req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break;        case EIO_STAT:      ALLOC (sizeof (EIO_STRUCT_STAT));                            req->result = stat      (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; @@ -2427,16 +2422,6 @@ eio_grp_add (eio_req *grp, eio_req *req)  eio_ssize_t  eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count)  { -  etp_worker wrk; -  eio_ssize_t ret; - -  wrk.dbuf = 0; - -  ret = eio__sendfile (ofd, ifd, offset, count, &wrk); - -  if (wrk.dbuf) -    free (wrk.dbuf); - -  return ret; +  return eio__sendfile (ofd, ifd, offset, count);  } @@ -47,21 +47,24 @@ time differences throughout libeio.  =head2 FORK SUPPORT -Calling C<fork ()> is fully supported by this module - but you must not -rely on this. It is currently implemented in these steps: - -  1. wait till all requests in "execute" state have been handled -     (basically requests that are already handed over to the kernel). -  2. fork -  3. in the parent, continue business as usual, done -  4. in the child, destroy all ready and pending requests and free the -     memory used by the worker threads. This gives you a fully empty -     libeio queue. - -Note, however, since libeio does use threads, the above guarantee doesn't -cover your libc, for example, malloc and other libc functions are not -fork-safe, so there is very little you can do after a fork, and in fact, -the above might crash, and thus change. +Usage of pthreads in a program changes the semantics of fork +considerably. Specifically, only async-safe functions can be called after +fork. Libeio uses pthreads, so this applies, and makes using fork hard for +anything but relatively fork + exec uses. + +This library only works in the process that initialised it: Forking is +fully supported, but using libeio in any other process than the one that +called C<eio_init> is not. + +You might get around by not I<using> libeio before (or after) forking in +the parent, and using it in the child afterwards. You could also try to +call the L<eio_init> function again in the child, which will brutally +reinitialise all data structures, which isn't POSIX conformant, but +typically works. + +Otherwise, the only recommendation you should follow is: treat fork code +the same way you treat signal handlers, and only ever call C<eio_init> in +the process that uses it, and only once ever.  =head1 INITIALISATION/INTEGRATION @@ -81,6 +84,9 @@ failure it returns C<-1> and sets C<errno> appropriately.  It accepts two function pointers specifying callbacks as argument, both of  which can be C<0>, in which case the callback isn't called. +There is currently no way to change these callbacks later, or to +"uninitialise" the library again. +  =item want_poll callback  The C<want_poll> callback is invoked whenever libeio wants attention (i.e. | 
