Add a mmap destroy function to cleanup all mmap hash table entries upon thread exit
This commit is contained in:
@@ -397,6 +397,8 @@ thread_exit (void)
|
||||
process_exit ();
|
||||
#endif
|
||||
|
||||
mmap_destroy ();
|
||||
|
||||
/* Remove thread from all threads list, set our status to dying,
|
||||
and schedule another process. That process will destroy us
|
||||
when it calls thread_schedule_tail(). */
|
||||
|
||||
@@ -33,3 +33,21 @@ mmap_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
||||
|
||||
return a->mapping < b->mapping;
|
||||
}
|
||||
|
||||
/* Cleans up the mmap table for the current thread. Frees the memory allocated
|
||||
for the mmap entry. */
|
||||
static void
|
||||
mmap_cleanup (struct hash_elem *e, void *aux UNUSED)
|
||||
{
|
||||
struct mmap_entry *mmap = hash_entry (e, struct mmap_entry, elem);
|
||||
file_close (mmap->file);
|
||||
free (mmap);
|
||||
}
|
||||
|
||||
/* Destroys the mmap table for the current thread. Frees all the memory
|
||||
allocated for the mmap entries. */
|
||||
void
|
||||
mmap_destroy (void)
|
||||
{
|
||||
hash_destroy (&thread_current ()->mmap_files, mmap_cleanup);
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <hash.h>
|
||||
#include "threads/thread.h"
|
||||
#include "filesys/file.h"
|
||||
|
||||
/* A mapping identifier type. */
|
||||
typedef unsigned mapid_t;
|
||||
@@ -17,5 +18,6 @@ struct mmap_entry {
|
||||
};
|
||||
|
||||
bool mmap_init (void);
|
||||
void mmap_destroy (void);
|
||||
|
||||
#endif /* vm/mmap.h */
|
||||
|
||||
Reference in New Issue
Block a user