aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/autoload.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/autoload.h')
-rw-r--r--src/autoload.h70
1 files changed, 31 insertions, 39 deletions
diff --git a/src/autoload.h b/src/autoload.h
index ef55fd94..efa8c16d 100644
--- a/src/autoload.h
+++ b/src/autoload.h
@@ -11,17 +11,17 @@
#include "common.h"
#include "lru.h"
-/// Recording an attempt to access a file.
+/// Record of an attempt to access a file.
struct file_access_attempt_t {
- /// modification time of the file
+ /// Modification time of the file
time_t mod_time;
- /// when we last checked the file
+ /// When we last checked the file
time_t last_checked;
- /// whether we believe we could access this file
+ /// Whether or not we believe we can access this file
bool accessible;
- /// whether the access attempt is stale
+ /// The access attempt is stale
bool stale;
- /// if we could not access the file, the error code
+ /// If we cannot access the file, the error code encountered.
int error;
};
file_access_attempt_t access_file(const wcstring &path, int mode);
@@ -33,9 +33,10 @@ struct autoload_function_t : public lru_node_t {
is_loaded(false),
is_placeholder(false),
is_internalized(false) {}
- /// the last access attempt
+
+ /// The last access attempt recorded
file_access_attempt_t access;
- /// whether we have actually loaded this function
+ /// Have we actually loaded this function?
bool is_loaded;
/// Whether we are a placeholder that stands in for "no such function". If this is true, then
/// is_loaded must be false.
@@ -51,24 +52,23 @@ struct builtin_script_t {
class env_vars_snapshot_t;
-/// A class that represents a path from which we can autoload, and the autoloaded contents.
+/// Class representing a path from which we can autoload and the autoloaded contents.
class autoload_t : private lru_cache_t<autoload_function_t> {
private:
- // Lock for thread safety.
+ /// Lock for thread safety.
pthread_mutex_t lock;
- // The environment variable name.
+ /// The environment variable name.
const wcstring env_var_name;
- // Builtin script array.
+ /// Builtin script array.
const struct builtin_script_t *const builtin_scripts;
- // Builtin script count.
+ /// Builtin script count.
const size_t builtin_script_count;
- // The path from which we most recently autoloaded.
+ /// The path from which we most recently autoloaded.
wcstring last_path;
- // That path, tokenized (split on separators).
+ /// the most reecently autoloaded path, tokenized (split on separators).
wcstring_list_t last_path_tokenized;
-
- // A table containing all the files that are currently being loaded. This is here to help
- // prevent recursion.
+ /// A table containing all the files that are currently being loaded.
+ /// This is here to help prevent recursion.
std::set<wcstring> is_loading_set;
void remove_all_functions(void) { this->evict_all_nodes(); }
@@ -82,39 +82,31 @@ class autoload_t : private lru_cache_t<autoload_function_t> {
bool allow_eviction);
protected:
- // Overridable callback for when a command is removed.
+ /// Overridable callback for when a command is removed.
virtual void command_removed(const wcstring &cmd) {}
public:
- // Create an autoload_t for the given environment variable name.
+ /// Create an autoload_t for the given environment variable name.
autoload_t(const wcstring &env_var_name_var, const builtin_script_t *scripts,
size_t script_count);
- virtual ~autoload_t(); // destructor
-
- // Autoload the specified file, if it exists in the specified path. Do not load it multiple
- // times unless its timestamp changes or parse_util_unload is called.
- //
- // Autoloading one file may unload another.
- //
- // \param cmd the filename to search for. The suffix '.fish' is always added to this name
- // \param on_unload a callback function to run if a suitable file is found, which has not
- // already been run. unload will also be called for old files which are unloaded.
- // \param reload wheter to recheck file timestamps on already loaded files
+ virtual ~autoload_t();
+
+ /// Autoload the specified file, if it exists in the specified path. Do not load it multiple
+ /// times unless its timestamp changes or parse_util_unload is called.
+ /// Autoloading one file may unload another.
+ /// @param cmd the filename to search for. The suffix '.fish' is always added to this name
+ /// @param reload wheter to recheck file timestamps on already loaded files
int load(const wcstring &cmd, bool reload);
- // Check whether we have tried loading the given command. Does not do any I/O.
+ /// Check whether we have tried loading the given command. Does not do any I/O.
bool has_tried_loading(const wcstring &cmd);
- // Tell the autoloader that the specified file, in the specified path, is no longer loaded.
- //
- // \param cmd the filename to search for. The suffix '.fish' is always added to this name
- // \param on_unload a callback function which will be called before (re)loading a file, may be
- // used to unload the previous file.
- // \return non-zero if the file was removed, zero if the file had not yet been loaded
+ /// Tell the autoloader that the specified file, in the specified path, is no longer loaded.
+ /// Returns non-zero if the file was removed, zero if the file had not yet been loaded
int unload(const wcstring &cmd);
- // Check whether the given command could be loaded, but do not load it.
+ /// Check whether the given command could be loaded, but do not load it.
bool can_load(const wcstring &cmd, const env_vars_snapshot_t &vars);
};
#endif