#include <common/hashtable/utils.hpp>
#include <common/macros.hpp>
#include <common/optional.hpp>
+#include <common/urcu.hpp>
#include <fcntl.h>
#include <inttypes.h>
#include <urcu/rculfhash.h>
/* 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;
return entry;
error:
unsuspendable_fd_destroy(entry);
- return NULL;
+ return nullptr;
}
static void fs_handle_tracked_log(struct fs_handle_tracked *handle)
const char *path;
pthread_mutex_lock(&handle->lock);
- lttng_inode_borrow_location(handle->inode, NULL, &path);
+ lttng_inode_borrow_location(handle->inode, nullptr, &path);
if (handle->fd >= 0) {
DBG_NO_LOC(" %s [active, fd %d%s]",
pthread_mutex_lock(&seed.lock);
if (!seed.initialized) {
- seed.value = (unsigned long) time(NULL);
+ seed.value = (unsigned long) time(nullptr);
seed.initialized = true;
}
pthread_mutex_unlock(&seed.lock);
CDS_INIT_LIST_HEAD(&tracker->suspended_handles);
tracker->capacity = capacity;
tracker->unsuspendable_fds = cds_lfht_new(
- DEFAULT_HT_SIZE, 1, 0, CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, NULL);
+ DEFAULT_HT_SIZE, 1, 0, CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, nullptr);
if (!tracker->unsuspendable_fds) {
ERR("Failed to create fd-tracker's unsuspendable_fds hash table");
goto error;
return tracker;
error:
fd_tracker_destroy(tracker);
- return NULL;
+ return nullptr;
}
void fd_tracker_log(struct fd_tracker *tracker)
{
struct fs_handle_tracked *handle;
- struct unsuspendable_fd *unsuspendable_fd;
- struct cds_lfht_iter iter;
pthread_mutex_lock(&tracker->lock);
DBG_NO_LOC("File descriptor tracker");
}
DBG_NO_LOC(" Tracked unsuspendable file descriptors");
- rcu_read_lock();
- cds_lfht_for_each_entry (
- tracker->unsuspendable_fds, &iter, unsuspendable_fd, tracker_node) {
+
+ for (auto *unsuspendable_fd :
+ lttng::urcu::lfht_iteration_adapter<struct unsuspendable_fd,
+ decltype(unsuspendable_fd::tracker_node),
+ &unsuspendable_fd::tracker_node>(
+ *tracker->unsuspendable_fds)) {
DBG_NO_LOC(" %s [active, fd %d]",
unsuspendable_fd->name ?: "Unnamed",
unsuspendable_fd->fd);
}
- rcu_read_unlock();
+
if (!UNSUSPENDABLE_COUNT(tracker)) {
DBG_NO_LOC(" None");
}
pthread_mutex_unlock(&tracker->lock);
if (tracker->unsuspendable_fds) {
- ret = cds_lfht_destroy(tracker->unsuspendable_fds, NULL);
+ ret = cds_lfht_destroy(tracker->unsuspendable_fds, nullptr);
LTTNG_ASSERT(!ret);
}
mode_t *mode)
{
int ret;
- struct fs_handle_tracked *handle = NULL;
+ struct fs_handle_tracked *handle = nullptr;
struct stat fd_stat;
struct open_properties properties = { .flags = flags,
.mode = {
handle->tracker = tracker;
- ret = pthread_mutex_init(&handle->lock, NULL);
+ ret = pthread_mutex_init(&handle->lock, nullptr);
if (ret) {
PERROR("Failed to initialize handle mutex while creating fs handle");
goto error_mutex_init;
fd_tracker_track(tracker, handle);
end:
pthread_mutex_unlock(&tracker->lock);
- return handle ? &handle->parent : NULL;
+ return handle ? &handle->parent : nullptr;
error:
if (handle->inode) {
lttng_inode_put(handle->inode);
pthread_mutex_destroy(&handle->lock);
error_mutex_init:
free(handle);
- handle = NULL;
+ handle = nullptr;
goto end;
}
int ret, user_ret, i, fds_to_suspend;
unsigned int active_fds;
struct unsuspendable_fd **entries;
+ const lttng::urcu::read_lock_guard read_lock;
entries = calloc<unsuspendable_fd *>(fd_count);
if (!entries) {
*/
for (i = 0; i < fd_count; i++) {
struct unsuspendable_fd *entry =
- unsuspendable_fd_create(names ? names[i] : NULL, out_fds[i]);
+ unsuspendable_fd_create(names ? names[i] : nullptr, out_fds[i]);
if (!entry) {
ret = -1;
entries[i] = entry;
}
- rcu_read_lock();
for (i = 0; i < fd_count; i++) {
struct cds_lfht_node *node;
struct unsuspendable_fd *entry = entries[i];
if (node != &entry->tracker_node) {
ret = -EEXIST;
- rcu_read_unlock();
goto end_free_entries;
}
- entries[i] = NULL;
+ entries[i] = nullptr;
}
tracker->count.unsuspendable += fd_count;
- rcu_read_unlock();
ret = user_ret;
end_unlock:
pthread_mutex_unlock(&tracker->lock);
void *user_data)
{
int i, ret, user_ret;
- int *fds = NULL;
+ int *fds = nullptr;
+ const lttng::urcu::read_lock_guard read_lock;
/*
* Maintain a local copy of fds_in as the user's callback may modify its
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);
tracker->count.unsuspendable -= fd_count;
ret = 0;
end_unlock:
- rcu_read_unlock();
pthread_mutex_unlock(&tracker->lock);
free(fds);
end:
static int fs_handle_tracked_close(struct fs_handle *_handle)
{
int ret = 0;
- const char *path = NULL;
+ const char *path = nullptr;
struct fs_handle_tracked *handle =
lttng::utils::container_of(_handle, &fs_handle_tracked::parent);
- struct lttng_directory_handle *inode_directory_handle = NULL;
+ struct lttng_directory_handle *inode_directory_handle = nullptr;
if (!handle) {
ret = -EINVAL;
pthread_mutex_lock(&handle->tracker->lock);
pthread_mutex_lock(&handle->lock);
if (handle->inode) {
- lttng_inode_borrow_location(handle->inode, NULL, &path);
+ lttng_inode_borrow_location(handle->inode, nullptr, &path);
/*
* Here a reference to the inode's directory handle is acquired
* to prevent the last reference to it from being released while