Refactor System Calls and Process for Readability; Change FD to local counter and use it as hash #47

Merged
sb3923 merged 9 commits from task2/refactoring/saleh into master 2024-11-15 16:41:13 +00:00
6 changed files with 130 additions and 43 deletions
Showing only changes of commit ea3b3594ea - Show all commits

View File

@@ -406,7 +406,12 @@ syscall_close (int fd)
unsigned unsigned
fd_hash (const struct hash_elem *element, void *aux UNUSED) fd_hash (const struct hash_elem *element, void *aux UNUSED)
{ {
return hash_int (hash_entry (element, struct open_file, elem)->fd); /* We use the FD as the hash value. This is because the FD is incremented
sequentially and is therefore unique for each file. It positively affects
the performance of the hash table: 1. It is unique so no need to call
expensive hash functions. 2. It being sequential means that the hash table
is more likely to be weight balanced. */
return hash_entry (element, struct open_file, elem)->fd;
} }
/* Comparator function for the open_file table. Compares two entries based on /* Comparator function for the open_file table. Compares two entries based on