X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Ffd-tracker%2Ffd-tracker.cpp;h=0c24eab5ea016e74b51e818af1bbcbb02c5b24ff;hb=0114db0ec2407029052eb61a0189c9b1cd64d520;hp=e511d6901884cb7992f7da3b6020a1b8625c9b4d;hpb=9730eb85b37e03a16008bbfc93dcb3a4b26ce934;p=lttng-tools.git diff --git a/src/common/fd-tracker/fd-tracker.cpp b/src/common/fd-tracker/fd-tracker.cpp index e511d6901..0c24eab5e 100644 --- a/src/common/fd-tracker/fd-tracker.cpp +++ b/src/common/fd-tracker/fd-tracker.cpp @@ -16,16 +16,16 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include -#include "fd-tracker.h" -#include "inode.h" +#include "fd-tracker.hpp" +#include "inode.hpp" /* Tracker lock must be taken by the user. */ #define TRACKED_COUNT(tracker) \ @@ -80,6 +80,7 @@ struct fd_tracker { struct lttng_unlinked_file_pool *unlinked_file_pool; }; +namespace { struct open_properties { int flags; LTTNG_OPTIONAL(mode_t) mode; @@ -124,13 +125,16 @@ struct unsuspendable_fd { struct rcu_head rcu_head; }; -static struct { +struct { pthread_mutex_t lock; bool initialized; unsigned long value; } seed = { .lock = PTHREAD_MUTEX_INITIALIZER, + .initialized = false, + .value = 0, }; +} /* namespace */ static int match_fd(struct cds_lfht_node *node, const void *key); static void unsuspendable_fd_destroy(struct unsuspendable_fd *entry); @@ -159,8 +163,8 @@ static int fd_tracker_restore_handle( /* Match function of the tracker's unsuspendable_fds hash table. */ static int match_fd(struct cds_lfht_node *node, const void *key) { - struct unsuspendable_fd *entry = caa_container_of( - node, struct unsuspendable_fd, tracker_node); + struct unsuspendable_fd *entry = lttng::utils::container_of( + node, &unsuspendable_fd::tracker_node); return hash_match_key_ulong( (void *) (unsigned long) entry->fd, (void *) key); @@ -186,7 +190,7 @@ static void unsuspendable_fd_destroy(struct unsuspendable_fd *entry) static struct unsuspendable_fd *unsuspendable_fd_create( const char *name, int fd) { - struct unsuspendable_fd *entry = (unsuspendable_fd *) zmalloc(sizeof(*entry)); + struct unsuspendable_fd *entry = zmalloc(); if (!entry) { goto error; @@ -363,7 +367,7 @@ end: struct fd_tracker *fd_tracker_create(const char *unlinked_file_path, unsigned int capacity) { - struct fd_tracker *tracker = (fd_tracker *) zmalloc(sizeof(struct fd_tracker)); + struct fd_tracker *tracker = zmalloc(); if (!tracker) { goto end; @@ -524,7 +528,7 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker, } } - handle = (fs_handle_tracked *) zmalloc(sizeof(*handle)); + handle = zmalloc(); if (!handle) { goto end; } @@ -618,7 +622,7 @@ int fd_tracker_open_unsuspendable_fd(struct fd_tracker *tracker, unsigned int active_fds; struct unsuspendable_fd **entries; - entries = (unsuspendable_fd **) zmalloc(fd_count * sizeof(*entries)); + entries = calloc(fd_count); if (!entries) { ret = -1; goto end; @@ -717,7 +721,7 @@ int fd_tracker_close_unsuspendable_fd(struct fd_tracker *tracker, * Maintain a local copy of fds_in as the user's callback may modify its * contents (e.g. setting the fd(s) to -1 after close). */ - fds = (int *) malloc(sizeof(*fds) * fd_count); + fds = malloc(sizeof(*fds) * fd_count); if (!fds) { ret = -1; goto end; @@ -753,8 +757,8 @@ int fd_tracker_close_unsuspendable_fd(struct fd_tracker *tracker, ret = -EINVAL; goto end_unlock; } - entry = caa_container_of( - node, struct unsuspendable_fd, tracker_node); + entry = lttng::utils::container_of( + node, &unsuspendable_fd::tracker_node); cds_lfht_del(tracker->unsuspendable_fds, node); unsuspendable_fd_destroy(entry); @@ -821,7 +825,7 @@ static int fs_handle_tracked_get_fd(struct fs_handle *_handle) { int ret; struct fs_handle_tracked *handle = - container_of(_handle, struct fs_handle_tracked, parent); + lttng::utils::container_of(_handle, &fs_handle_tracked::parent); /* * TODO This should be optimized as it is a fairly hot path. @@ -862,7 +866,7 @@ end: static void fs_handle_tracked_put_fd(struct fs_handle *_handle) { struct fs_handle_tracked *handle = - container_of(_handle, struct fs_handle_tracked, parent); + lttng::utils::container_of(_handle, &fs_handle_tracked::parent); pthread_mutex_lock(&handle->lock); handle->in_use = false; @@ -873,7 +877,7 @@ static int fs_handle_tracked_unlink(struct fs_handle *_handle) { int ret; struct fs_handle_tracked *handle = - container_of(_handle, struct fs_handle_tracked, parent); + lttng::utils::container_of(_handle, &fs_handle_tracked::parent); pthread_mutex_lock(&handle->tracker->lock); pthread_mutex_lock(&handle->lock); @@ -888,7 +892,7 @@ static int fs_handle_tracked_close(struct fs_handle *_handle) int ret = 0; const char *path = NULL; struct fs_handle_tracked *handle = - container_of(_handle, struct fs_handle_tracked, parent); + lttng::utils::container_of(_handle, &fs_handle_tracked::parent); struct lttng_directory_handle *inode_directory_handle = NULL; if (!handle) {