Skip to content

Commit

Permalink
change view to a unique_ptr<>
Browse files Browse the repository at this point in the history
Summary: We're going to extract out the interface as a virtual base, so we need to be able to reference it via a pointer.

Reviewed By: farnz

Differential Revision: D4020168

fbshipit-source-id: 4957eff80abb1af20c969aa434c6679ae44a9de2
  • Loading branch information
wez authored and Facebook Github Bot committed Oct 19, 2016
1 parent 3a31755 commit 3b57192
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 29 deletions.
8 changes: 4 additions & 4 deletions clockspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void w_clockspec_eval_readonly(struct read_locked_watchman_root *lock,
} else {
since->clock.ticks = it->second;
since->clock.is_fresh_instance = since->clock.ticks <
lock->root->inner.view.getLastAgeOutTickValue();
lock->root->inner.view->getLastAgeOutTickValue();
}
}

Expand All @@ -128,7 +128,7 @@ void w_clockspec_eval_readonly(struct read_locked_watchman_root *lock,
spec->clock.pid == proc_pid &&
spec->clock.root_number == lock->root->inner.number) {
since->clock.is_fresh_instance =
spec->clock.ticks < lock->root->inner.view.getLastAgeOutTickValue();
spec->clock.ticks < lock->root->inner.view->getLastAgeOutTickValue();
if (since->clock.is_fresh_instance) {
since->clock.ticks = 0;
} else {
Expand Down Expand Up @@ -179,7 +179,7 @@ void w_clockspec_eval(struct write_locked_watchman_root *lock,
} else {
since->clock.ticks = it->second;
since->clock.is_fresh_instance = since->clock.ticks <
lock->root->inner.view.getLastAgeOutTickValue();
lock->root->inner.view->getLastAgeOutTickValue();
}

// Bump the tick value and record it against the cursor.
Expand All @@ -204,7 +204,7 @@ void w_clockspec_eval(struct write_locked_watchman_root *lock,
spec->clock.pid == proc_pid &&
spec->clock.root_number == lock->root->inner.number) {
since->clock.is_fresh_instance =
spec->clock.ticks < lock->root->inner.view.getLastAgeOutTickValue();
spec->clock.ticks < lock->root->inner.view->getLastAgeOutTickValue();
if (since->clock.is_fresh_instance) {
since->clock.ticks = 0;
} else {
Expand Down
8 changes: 4 additions & 4 deletions cmds/subscribe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ void process_subscriptions(struct write_locked_watchman_root *lock) {
sub,
sub->name->buf,
sub->last_sub_tick,
root->inner.view.getMostRecentTickValue());
root->inner.view->getMostRecentTickValue());

if (sub->last_sub_tick == root->inner.view.getMostRecentTickValue()) {
if (sub->last_sub_tick == root->inner.view->getMostRecentTickValue()) {
continue;
}

Expand Down Expand Up @@ -86,7 +86,7 @@ void process_subscriptions(struct write_locked_watchman_root *lock) {

if (drop) {
// fast-forward over any notifications while in the drop state
sub->last_sub_tick = root->inner.view.getMostRecentTickValue();
sub->last_sub_tick = root->inner.view->getMostRecentTickValue();
w_log(
W_LOG_DBG,
"dropping subscription notifications for %s "
Expand All @@ -113,7 +113,7 @@ void process_subscriptions(struct write_locked_watchman_root *lock) {
}

w_run_subscription_rules(client, sub, lock);
sub->last_sub_tick = root->inner.view.getMostRecentTickValue();
sub->last_sub_tick = root->inner.view->getMostRecentTickValue();

} while (w_ht_next(client->subscriptions, &citer));

Expand Down
10 changes: 5 additions & 5 deletions query/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool time_generator(
struct read_locked_watchman_root* lock,
struct w_query_ctx* ctx,
int64_t* num_walked) {
return lock->root->inner.view.timeGenerator(query, ctx, num_walked);
return lock->root->inner.view->timeGenerator(query, ctx, num_walked);
}

static bool default_generators(
Expand All @@ -160,7 +160,7 @@ static bool default_generators(
// Suffix
if (query->suffixes) {
n = 0;
result = lock->root->inner.view.suffixGenerator(query, ctx, &n);
result = lock->root->inner.view->suffixGenerator(query, ctx, &n);
total += n;
if (!result) {
goto done;
Expand All @@ -170,7 +170,7 @@ static bool default_generators(

if (query->npaths) {
n = 0;
result = lock->root->inner.view.pathGenerator(query, ctx, &n);
result = lock->root->inner.view->pathGenerator(query, ctx, &n);
total += n;
if (!result) {
goto done;
Expand All @@ -180,7 +180,7 @@ static bool default_generators(

if (query->glob_tree) {
n = 0;
result = lock->root->inner.view.globGenerator(query, ctx, &n);
result = lock->root->inner.view->globGenerator(query, ctx, &n);
total += n;
if (!result) {
goto done;
Expand All @@ -192,7 +192,7 @@ static bool default_generators(
// files
if (!generated) {
n = 0;
result = lock->root->inner.view.allFilesGenerator(query, ctx, &n);
result = lock->root->inner.view->allFilesGenerator(query, ctx, &n);
total += n;
if (!result) {
goto done;
Expand Down
6 changes: 3 additions & 3 deletions root/ageout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void consider_age_out(struct write_locked_watchman_root *lock)

time(&now);

if (now <= lock->root->inner.view.getLastAgeOutTimeStamp() +
if (now <= lock->root->inner.view->getLastAgeOutTimeStamp() +
lock->root->gc_interval) {
// Don't check too often
return;
Expand All @@ -31,14 +31,14 @@ void w_root_perform_age_out(struct write_locked_watchman_root *lock,
int min_age) {
w_perf_t sample("age_out");

lock->root->inner.view.ageOut(sample, std::chrono::seconds(min_age));
lock->root->inner.view->ageOut(sample, std::chrono::seconds(min_age));

// Age out cursors too.
{
auto cursors = lock->root->inner.cursors.wlock();
auto it = cursors->begin();
while (it != cursors->end()) {
if (it->second < lock->root->inner.view.getLastAgeOutTickValue()) {
if (it->second < lock->root->inner.view->getLastAgeOutTickValue()) {
it = cursors->erase(it);
} else {
++it;
Expand Down
4 changes: 2 additions & 2 deletions root/dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ w_string watchman_dir::getFullPath() const {
const watchman_dir* w_root_resolve_dir_read(
struct read_locked_watchman_root* lock,
const w_string& dir_name) {
return lock->root->inner.view.resolveDir(dir_name);
return lock->root->inner.view->resolveDir(dir_name);
}

watchman_dir* w_root_resolve_dir(
struct write_locked_watchman_root* lock,
const w_string& dir_name,
bool create) {
return lock->root->inner.view.resolveDir(dir_name, create);
return lock->root->inner.view->resolveDir(dir_name, create);
}

watchman_file* watchman_dir::getChildFile(w_string name) const {
Expand Down
3 changes: 2 additions & 1 deletion root/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ void w_root_teardown(w_root_t *root) {
new (&root->inner) watchman_root::Inner(root->root_path);
}

watchman_root::Inner::Inner(const w_string& root_path) : view(root_path) {}
watchman_root::Inner::Inner(const w_string& root_path)
: view(watchman::make_unique<watchman::InMemoryView>(root_path)) {}

watchman_root::Inner::~Inner() {}

Expand Down
14 changes: 7 additions & 7 deletions root/stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void stat_path(
if (res && (err == ENOENT || err == ENOTDIR)) {
/* it's not there, update our state */
if (dir_ent) {
lock->root->inner.view.markDirDeleted(
lock->root->inner.view->markDirDeleted(
dir_ent, now, lock->root->inner.ticks, true);
w_log(
W_LOG_DBG,
Expand All @@ -83,20 +83,20 @@ void stat_path(
strerror(err), w_file_get_name(file)->len,
w_file_get_name(file)->buf);
file->exists = false;
lock->root->inner.view.markFileChanged(
lock->root->inner.view->markFileChanged(
file, now, lock->root->inner.ticks);
}
} else {
// It was created and removed before we could ever observe it
// in the filesystem. We need to generate a deleted file
// representation of it now, so that subscription clients can
// be notified of this event
file = lock->root->inner.view.getOrCreateChildFile(
file = lock->root->inner.view->getOrCreateChildFile(
dir, file_name, now, lock->root->inner.ticks);
w_log(W_LOG_DBG, "w_lstat(%s) -> %s and file node was NULL. "
"Generating a deleted node.\n", path, strerror(err));
file->exists = false;
lock->root->inner.view.markFileChanged(
lock->root->inner.view->markFileChanged(
file, now, lock->root->inner.ticks);
}

Expand All @@ -120,7 +120,7 @@ void stat_path(
path, err, strerror(err));
} else {
if (!file) {
file = lock->root->inner.view.getOrCreateChildFile(
file = lock->root->inner.view->getOrCreateChildFile(
dir, file_name, now, lock->root->inner.ticks);
}

Expand All @@ -143,7 +143,7 @@ void stat_path(
path
);
file->exists = true;
lock->root->inner.view.markFileChanged(
lock->root->inner.view->markFileChanged(
file, now, lock->root->inner.ticks);
}

Expand Down Expand Up @@ -210,7 +210,7 @@ void stat_path(
} else if (dir_ent) {
// We transitioned from dir to file (see fishy.php), so we should prune
// our former tree here
lock->root->inner.view.markDirDeleted(
lock->root->inner.view->markDirDeleted(
dir_ent, now, lock->root->inner.ticks, true);
}
if ((root->inner.watcher->flags & WATCHER_HAS_PER_FILE_NOTIFICATIONS) &&
Expand Down
2 changes: 1 addition & 1 deletion root/warnerr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void handle_open_errno(struct write_locked_watchman_root *lock,
}

stop_watching_dir(lock, dir);
lock->root->inner.view.markDirDeleted(
lock->root->inner.view->markDirDeleted(
dir, now, lock->root->inner.ticks, true);
}

Expand Down
2 changes: 1 addition & 1 deletion watcher/auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool w_watcher_init(w_root_t *root, char **errmsg) {
}

done:
root->inner.view.watcher = root->inner.watcher.get();
root->inner.view->watcher = root->inner.watcher.get();
w_log(
W_LOG_ERR,
"root %s using watcher mechanism %s (%s was requested)\n",
Expand Down
2 changes: 1 addition & 1 deletion watchman_root.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct watchman_root {
/* the watcher that we're using for this root */
std::unique_ptr<Watcher> watcher;

watchman::InMemoryView view;
std::unique_ptr<watchman::InMemoryView> view;

/* current tick */
uint32_t ticks{1};
Expand Down

0 comments on commit 3b57192

Please sign in to comment.