diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2012-01-25 00:36:55 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2012-01-25 00:36:55 -0800 |
commit | e94e1cc72fa6eb95549493788e72219922785733 (patch) | |
tree | 1cac0e597ba57b933f08dd4298125268f14d85b5 /autoload.h | |
parent | 4dfe36feb16923b454ea2e44cc512adaff879127 (diff) |
New file autoload.h that will ultimately handle autoloading completions and functions
Diffstat (limited to 'autoload.h')
-rw-r--r-- | autoload.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/autoload.h b/autoload.h new file mode 100644 index 00000000..dc3445e4 --- /dev/null +++ b/autoload.h @@ -0,0 +1,75 @@ +/** \file autoload.h + + The classes responsible for autoloading functions and completions. +*/ + +#ifndef FISH_PARSE_UTIL_H +#define FISH_PARSE_UTIL_H + +#include <wchar.h> +#include <map> +#include <set> +#include <list> +#include "common.h" + +extern const time_t kFishDefaultStalenessInterval; + +/** A class responsible for recording an attempt to access a file. */ +class file_access_attempt_t { +public: + time_t mod_time; /** The modification time of the file */ + time_t last_checked; /** When we last checked the file */ + bool accessible; /** Whether we believe we could access this file */ + bool stale; /** Whether the access attempt is stale */ + int error; /** If we could not access the file, the error code */ +}; + +class file_access_node_t; + +/** A predicate to compare dereferenced pointers */ +struct dereference_less_t { + template <typename ptr_t> + bool operator()(ptr_t p1, ptr_t p2) const { return *p1 < *p2; } +}; + + +/** A class responsible for tracking accesses to files, including auto-expiration. */ +class access_tracker_t { + private: + + file_access_node_t * while_locked_find_node(const wcstring &str) const; + void vacuum_one_node(void); + void promote_node(file_access_node_t *); + + file_access_attempt_t attempt_access(const wcstring& path) const; + + unsigned int node_count; + typedef std::set<file_access_node_t *, dereference_less_t> access_set_t; + access_set_t access_set; + file_access_node_t *mouth; + + /* Lock for thread safety */ + pthread_mutex_t lock; + + /** How long until a file access attempt is considered stale. */ + const time_t stale_interval; + + /** Mode for waccess calls */ + const int mode; + + public: + + /** Constructor, that takes a staleness interval */ + access_tracker_t(time_t stale, int the_mode); + + /** Destructor */ + ~access_tracker_t(); + + /** Attempt to access the given file, if the last cached access is stale. Caches and returns the access attempt. */ + file_access_attempt_t access_file(const wcstring &path); + + /** Returns whether there is a cached access (even if stale), without touching the disk; if the result is true, return by reference that access attempt. */ + bool access_file_only_cached(const wcstring &path, file_access_attempt_t &attempt); +}; + +#endif |