Ignore:
Timestamp:
Nov 8, 2009, 11:43:38 PM (12 years ago)
Author:
charles
Message:

(trunk libT) #2551 "better buffer cache management": apply jch's prefetch-base.patch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r9417 r9495  
    209209}
    210210
     211/* Like pread and pwrite, except that the position is undefined afterwards.
     212   And of course they are not thread-safe. */
     213
     214#ifdef SYS_DARWIN
     215 #define HAVE_PREAD
     216 #define HAVE_PWRITE
     217#endif
     218
     219ssize_t
     220tr_pread( int fd, void *buf, size_t count, off_t offset )
     221{
     222#ifdef HAVE_PREAD
     223    return pread( fd, buf, count, offset );
     224#else
     225    const off_t lrc = lseek( fd, offset, SEEK_SET );
     226    if( lrc < 0 )
     227        return -1;
     228    return read( fd, buf, count );
     229#endif
     230}
     231
     232ssize_t
     233tr_pwrite( int fd, void *buf, size_t count, off_t offset )
     234{
     235#ifdef HAVE_PWRITE
     236    return pwrite( fd, buf, count, offset );
     237#else
     238    const off_t lrc = lseek( fd, offset, SEEK_SET );
     239    if( lrc < 0 )
     240        return -1;
     241    return write( fd, buf, count );
     242#endif
     243}
     244
     245int
     246tr_prefetch( int fd, off_t offset, size_t count )
     247{
     248#ifdef HAVE_POSIX_FADVISE
     249    return posix_fadvise( fd, offset, count, POSIX_FADV_WILLNEED );
     250#elif defined(SYS_DARWIN)
     251    int val;
     252    struct radvisory radv;
     253    radv.ra_offset = offset;
     254    radv.ra_count = count;
     255    return fcntl( fd, F_RDADVISE, &radv );
     256#else
     257    return 0;
     258#endif
     259}
     260
    211261int
    212262tr_open_file_for_writing( const char * filename )
Note: See TracChangeset for help on using the changeset viewer.