Initialised shared_files global hash table, w/ G
This commit is contained in:
@@ -134,6 +134,9 @@ thread_start (void)
|
|||||||
t))
|
t))
|
||||||
PANIC ("Failed to initialise child results table for main thread.");
|
PANIC ("Failed to initialise child results table for main thread.");
|
||||||
|
|
||||||
|
if (!hash_init (&shared_files, shared_file_hash, shared_file_less, NULL))
|
||||||
|
PANIC ("Failed to initialise shared pages table.");
|
||||||
|
|
||||||
/* Create the idle thread. */
|
/* Create the idle thread. */
|
||||||
struct semaphore idle_started;
|
struct semaphore idle_started;
|
||||||
sema_init (&idle_started, 0);
|
sema_init (&idle_started, 0);
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
#include "page.h"
|
#include "page.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include "filesys/file.h"
|
#include "filesys/file.h"
|
||||||
#include "threads/malloc.h"
|
#include "threads/malloc.h"
|
||||||
#include "threads/palloc.h"
|
#include "threads/palloc.h"
|
||||||
#include "userprog/process.h"
|
#include "userprog/process.h"
|
||||||
#include "vm/frame.h"
|
#include "vm/frame.h"
|
||||||
|
|
||||||
static struct hash shared_files;
|
|
||||||
|
|
||||||
static struct shared_file_entry *shared_file_get (struct file *file);
|
static struct shared_file_entry *shared_file_get (struct file *file);
|
||||||
|
static unsigned shared_page_hash (const struct hash_elem *e, void *aux UNUSED);
|
||||||
|
static bool shared_page_less (const struct hash_elem *a_,
|
||||||
|
const struct hash_elem *b_, void *aux UNUSED);
|
||||||
|
|
||||||
/* Hashing function needed for the SPT table. Returns a hash for an entry,
|
/* Hashing function needed for the SPT table. Returns a hash for an entry,
|
||||||
based on its upage. */
|
based on its upage. */
|
||||||
@@ -135,14 +135,14 @@ shared_file_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
|||||||
|
|
||||||
/* Hashing function needed for the shared pages table. Returns a hash for an
|
/* Hashing function needed for the shared pages table. Returns a hash for an
|
||||||
entry based on its user virtual address (upage) pointer. */
|
entry based on its user virtual address (upage) pointer. */
|
||||||
unsigned
|
static unsigned
|
||||||
shared_page_hash (const struct hash_elem *e, void *aux UNUSED)
|
shared_page_hash (const struct hash_elem *e, void *aux UNUSED)
|
||||||
{
|
{
|
||||||
return hash_ptr (hash_entry (e, struct shared_page_entry, elem)->upage);
|
return hash_ptr (hash_entry (e, struct shared_page_entry, elem)->upage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Less function needed for the shared pages table. */
|
/* Less function needed for the shared pages table. */
|
||||||
bool
|
static bool
|
||||||
shared_page_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
shared_page_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
||||||
void *aux UNUSED)
|
void *aux UNUSED)
|
||||||
{
|
{
|
||||||
@@ -238,5 +238,5 @@ page_set_swap (struct thread *owner, void *upage, size_t swap_slot)
|
|||||||
size_t
|
size_t
|
||||||
page_get_swap (struct thread *owner, void *upage)
|
page_get_swap (struct thread *owner, void *upage)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include "threads/thread.h"
|
#include "threads/thread.h"
|
||||||
#include "filesys/off_t.h"
|
#include "filesys/off_t.h"
|
||||||
|
|
||||||
|
struct hash shared_files;
|
||||||
|
|
||||||
enum page_type {
|
enum page_type {
|
||||||
PAGE_EXECUTABLE,
|
PAGE_EXECUTABLE,
|
||||||
PAGE_EMPTY
|
PAGE_EMPTY
|
||||||
@@ -47,6 +49,12 @@ struct page_entry *page_insert (struct file *file, off_t ofs, void *upage,
|
|||||||
struct page_entry *page_get (void *upage);
|
struct page_entry *page_get (void *upage);
|
||||||
bool page_load (struct page_entry *page, bool writable);
|
bool page_load (struct page_entry *page, bool writable);
|
||||||
void page_cleanup (struct hash_elem *e, void *aux);
|
void page_cleanup (struct hash_elem *e, void *aux);
|
||||||
|
|
||||||
|
unsigned shared_file_hash (const struct hash_elem *e, void *aux);
|
||||||
|
bool shared_file_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
||||||
|
void *aux);
|
||||||
|
struct shared_page_entry *shared_page_get (struct file *file, void *upage);
|
||||||
|
|
||||||
void page_set_swap (struct thread *, void *, size_t);
|
void page_set_swap (struct thread *, void *, size_t);
|
||||||
size_t page_get_swap (struct thread *, void *);
|
size_t page_get_swap (struct thread *, void *);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user