Changeset d11d6eb for benchmark/io/http/filecache.cfa
- Timestamp:
- Aug 28, 2020, 1:26:28 PM (4 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/filecache.cfa
r8e2cb4a rd11d6eb 73 73 cache_line * entries; 74 74 size_t size; 75 int * rawfds; 76 int nfds; 75 77 } file_cache; 76 78 … … 98 100 } 99 101 100 int put_file( cache_line & entry ) {102 int put_file( cache_line & entry, int fd ) { 101 103 uint32_t idx = murmur3_32( (const uint8_t *)entry.file, strlen(entry.file), options.file_cache.hash_seed ) % file_cache.size; 102 104 … … 108 110 109 111 file_cache.entries[idx] = entry; 112 file_cache.entries[idx].fd = fd; 110 113 return i > 0 ? 1 : 0; 111 114 } … … 121 124 size_t fcount = 0; 122 125 size_t fsize = 16; 123 cache_line * raw = 0p; 124 raw = alloc(raw, fsize, true); 126 cache_line * raw = alloc(fsize); 125 127 // Step 1 get a dense array of all files 126 128 int walk(const char *fpath, const struct stat *sb, int typeflag) { … … 131 133 if(fcount > fsize) { 132 134 fsize *= 2; 133 raw = alloc( raw, fsize, true);135 raw = alloc(fsize, raw`realloc); 134 136 } 135 137 … … 162 164 file_cache.entries = anew(file_cache.size); 163 165 166 if(options.file_cache.fixed_fds) { 167 file_cache.nfds = fcount; 168 file_cache.rawfds = alloc(fcount); 169 } 170 164 171 // Step 3 fill the cache 165 172 int conflicts = 0; 166 173 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 ); 168 183 } 169 184 printf("Filled cache from path \"%s\" with %zu files\n", path, fcount); … … 197 212 } 198 213 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]; 200 217 } 201 218
Note: See TracChangeset
for help on using the changeset viewer.