X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Ffd-tracker%2Ffd-tracker.cpp;h=7f4c2b5b2b698f81116570d94380720c7ceda7c6;hb=HEAD;hp=e610118e9a8d1a3217d24b9cd7ce0ec42159af64;hpb=cd9adb8b829564212158943a0d279bb35322ab30;p=lttng-tools.git diff --git a/src/common/fd-tracker/fd-tracker.cpp b/src/common/fd-tracker/fd-tracker.cpp index e610118e9..7f4c2b5b2 100644 --- a/src/common/fd-tracker/fd-tracker.cpp +++ b/src/common/fd-tracker/fd-tracker.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -27,22 +28,22 @@ #include /* Tracker lock must be taken by the user. */ -#define TRACKED_COUNT(tracker) \ - (tracker->count.suspendable.active + tracker->count.suspendable.suspended + \ - tracker->count.unsuspendable) +#define TRACKED_COUNT(tracker) \ + ((tracker)->count.suspendable.active + (tracker)->count.suspendable.suspended + \ + (tracker)->count.unsuspendable) /* Tracker lock must be taken by the user. */ -#define ACTIVE_COUNT(tracker) (tracker->count.suspendable.active + tracker->count.unsuspendable) +#define ACTIVE_COUNT(tracker) ((tracker)->count.suspendable.active + (tracker)->count.unsuspendable) /* Tracker lock must be taken by the user. */ -#define SUSPENDED_COUNT(tracker) (tracker->count.suspendable.suspended) +#define SUSPENDED_COUNT(tracker) ((tracker)->count.suspendable.suspended) /* Tracker lock must be taken by the user. */ #define SUSPENDABLE_COUNT(tracker) \ - (tracker->count.suspendable.active + tracker->count.suspendable.suspended) + ((tracker)->count.suspendable.active + (tracker)->count.suspendable.suspended) /* Tracker lock must be taken by the user. */ -#define UNSUSPENDABLE_COUNT(tracker) (tracker->count.unsuspendable) +#define UNSUSPENDABLE_COUNT(tracker) ((tracker)->count.unsuspendable) struct fd_tracker { pthread_mutex_t lock; @@ -424,14 +425,18 @@ void fd_tracker_log(struct fd_tracker *tracker) } DBG_NO_LOC(" Tracked unsuspendable file descriptors"); - rcu_read_lock(); - cds_lfht_for_each_entry ( - tracker->unsuspendable_fds, &iter, unsuspendable_fd, tracker_node) { - DBG_NO_LOC(" %s [active, fd %d]", - unsuspendable_fd->name ?: "Unnamed", - unsuspendable_fd->fd); - } - rcu_read_unlock(); + + { + lttng::urcu::read_lock_guard read_lock; + + cds_lfht_for_each_entry ( + tracker->unsuspendable_fds, &iter, unsuspendable_fd, tracker_node) { + DBG_NO_LOC(" %s [active, fd %d]", + unsuspendable_fd->name ?: "Unnamed", + unsuspendable_fd->fd); + } + } + if (!UNSUSPENDABLE_COUNT(tracker)) { DBG_NO_LOC(" None"); } @@ -599,6 +604,7 @@ int fd_tracker_open_unsuspendable_fd(struct fd_tracker *tracker, int ret, user_ret, i, fds_to_suspend; unsigned int active_fds; struct unsuspendable_fd **entries; + lttng::urcu::read_lock_guard read_lock; entries = calloc(fd_count); if (!entries) { @@ -650,7 +656,6 @@ int fd_tracker_open_unsuspendable_fd(struct fd_tracker *tracker, entries[i] = entry; } - rcu_read_lock(); for (i = 0; i < fd_count; i++) { struct cds_lfht_node *node; struct unsuspendable_fd *entry = entries[i]; @@ -664,13 +669,11 @@ int fd_tracker_open_unsuspendable_fd(struct fd_tracker *tracker, if (node != &entry->tracker_node) { ret = -EEXIST; - rcu_read_unlock(); goto end_free_entries; } entries[i] = nullptr; } tracker->count.unsuspendable += fd_count; - rcu_read_unlock(); ret = user_ret; end_unlock: pthread_mutex_unlock(&tracker->lock); @@ -692,6 +695,7 @@ int fd_tracker_close_unsuspendable_fd(struct fd_tracker *tracker, { int i, ret, user_ret; int *fds = nullptr; + lttng::urcu::read_lock_guard read_lock; /* * Maintain a local copy of fds_in as the user's callback may modify its @@ -705,7 +709,6 @@ int fd_tracker_close_unsuspendable_fd(struct fd_tracker *tracker, memcpy(fds, fds_in, sizeof(*fds) * fd_count); pthread_mutex_lock(&tracker->lock); - rcu_read_lock(); /* Let the user close the file descriptors. */ user_ret = close(user_data, fds_in); @@ -743,7 +746,6 @@ int fd_tracker_close_unsuspendable_fd(struct fd_tracker *tracker, tracker->count.unsuspendable -= fd_count; ret = 0; end_unlock: - rcu_read_unlock(); pthread_mutex_unlock(&tracker->lock); free(fds); end: