Ignore:
Timestamp:
Aug 28, 2020, 1:26:28 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
8e3034d
Parents:
8e2cb4a
Message:

Fixed some compilation errors.
Fixed file descriptor support in progress.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/http/filecache.cfa

    r8e2cb4a rd11d6eb  
    7373        cache_line * entries;
    7474        size_t size;
     75        int * rawfds;
     76        int nfds;
    7577} file_cache;
    7678
     
    98100}
    99101
    100 int put_file( cache_line & entry ) {
     102int put_file( cache_line & entry, int fd ) {
    101103        uint32_t idx = murmur3_32( (const uint8_t *)entry.file, strlen(entry.file), options.file_cache.hash_seed ) % file_cache.size;
    102104
     
    108110
    109111        file_cache.entries[idx] = entry;
     112        file_cache.entries[idx].fd = fd;
    110113        return i > 0 ? 1 : 0;
    111114}
     
    121124        size_t fcount = 0;
    122125        size_t fsize = 16;
    123         cache_line * raw = 0p;
    124         raw = alloc(raw, fsize, true);
     126        cache_line * raw = alloc(fsize);
    125127        // Step 1 get a dense array of all files
    126128        int walk(const char *fpath, const struct stat *sb, int typeflag) {
     
    131133                if(fcount > fsize) {
    132134                        fsize *= 2;
    133                         raw = alloc(raw, fsize, true);
     135                        raw = alloc(fsize, raw`realloc);
    134136                }
    135137
     
    162164        file_cache.entries = anew(file_cache.size);
    163165
     166        if(options.file_cache.fixed_fds) {
     167                file_cache.nfds   = fcount;
     168                file_cache.rawfds = alloc(fcount);
     169        }
     170
    164171        // Step 3 fill the cache
    165172        int conflicts = 0;
    166173        for(i; fcount) {
    167                 conflicts += put_file( raw[i] );
     174                int fd;
     175                if(options.file_cache.fixed_fds) {
     176                        file_cache.rawfds[i] = raw[i].fd;
     177                        fd = i;
     178                }
     179                else {
     180                        fd = raw[i].fd;
     181                }
     182                conflicts += put_file( raw[i], fd );
    168183        }
    169184        printf("Filled cache from path \"%s\" with %zu files\n", path, fcount);
     
    197212        }
    198213
    199         return [aalloc(extra), 0];
     214        size_t s = file_cache.nfds + extra;
     215        int * data = alloc(s, file_cache.rawfds`realloc);
     216        return [data, file_cache.nfds];
    200217}
    201218
Note: See TracChangeset for help on using the changeset viewer.