static void init_notification_thread_command(struct notification_thread_command *cmd) { memset(cmd, 0, sizeof(*cmd)); CDS_INIT_LIST_HEAD(&cmd->cmd_list_node); lttng_waiter_init(&cmd->reply_waiter); }
struct cds_list_head *deq_pop_r(struct deq *p) { struct cds_list_head *e; if (cds_list_empty(&p->chain)) e = NULL; else { e = p->chain.next; cds_list_del(e); CDS_INIT_LIST_HEAD(e); } return e; }
static void test_create_kernel_stream(void) { struct ltt_kernel_stream *stream; stream = trace_kernel_create_stream("stream1", 0); ok(stream != NULL, "Create kernel stream"); ok(stream->fd == -1 && stream->state == 0, "Validate kernel stream"); /* Init list in order to avoid sefaults from cds_list_del */ CDS_INIT_LIST_HEAD(&stream->list); trace_kernel_destroy_stream(stream); }
struct cds_list_head *deq_pop_l(struct deq *p) { struct cds_list_head *e; spin_lock(&p->lock); if (cds_list_empty(&p->chain)) e = NULL; else { e = p->chain.prev; cds_list_del(e); CDS_INIT_LIST_HEAD(e); } spin_unlock(&p->lock); return e; }
struct cds_list_head *pdeq_pop_l(struct pdeq *d) { struct cds_list_head *e; spin_lock(&d->llock); e = deq_pop_l(&d->ldeq); if (e == NULL) { spin_lock(&d->rlock); e = deq_pop_l(&d->rdeq); cds_list_splice(&d->rdeq.chain, &d->ldeq.chain); CDS_INIT_LIST_HEAD(&d->rdeq.chain); spin_unlock(&d->rlock); } spin_unlock(&d->llock); return e; }
//\begin{snippet}[labelbase=ln:SMPdesign:locktdeq:pop_push,commandchars=\\\@\$] struct cds_list_head *pdeq_pop_l(struct pdeq *d) //\lnlbl{popl:b} { struct cds_list_head *e; spin_lock(&d->llock); //\lnlbl{popl:acq:l} e = deq_pop_l(&d->ldeq); //\lnlbl{popl:deq:ll} if (e == NULL) { spin_lock(&d->rlock); //\lnlbl{popl:acq:r} e = deq_pop_l(&d->rdeq); //\lnlbl{popl:deq:lr} cds_list_splice(&d->rdeq.chain, &d->ldeq.chain);//\lnlbl{popl:move} CDS_INIT_LIST_HEAD(&d->rdeq.chain); //\lnlbl{popl:init:r} spin_unlock(&d->rlock); //\lnlbl{popl:rel:r} } //\lnlbl{popl:skip} spin_unlock(&d->llock); //\lnlbl{popl:rel:l} return e; } //\lnlbl{popl:e}
static int enqueue_dropped_notification( struct lttng_notification_channel *channel) { int ret = 0; struct pending_notification *pending_notification; struct cds_list_head *last_element = channel->pending_notifications.list.prev; pending_notification = caa_container_of(last_element, struct pending_notification, node); if (!pending_notification->notification) { /* * The last enqueued notification indicates dropped * notifications; there is nothing to do as we group * dropped notifications together. */ goto end; } if (channel->pending_notifications.count >= DEFAULT_CLIENT_MAX_QUEUED_NOTIFICATIONS_COUNT && pending_notification->notification) { /* * Discard the last enqueued notification to indicate * that notifications were dropped at this point. */ lttng_notification_destroy( pending_notification->notification); pending_notification->notification = NULL; goto end; } pending_notification = zmalloc(sizeof(*pending_notification)); if (!pending_notification) { ret = -1; goto end; } CDS_INIT_LIST_HEAD(&pending_notification->node); cds_list_add(&pending_notification->node, &channel->pending_notifications.list); channel->pending_notifications.count++; end: return ret; }
static void test_create_kernel_channel(void) { struct ltt_kernel_channel *chan; struct lttng_channel attr; memset(&attr, 0, sizeof(attr)); chan = trace_kernel_create_channel(&attr); ok(chan != NULL, "Create kernel channel"); ok(chan->fd == -1 && chan->enabled == 1 && chan->stream_count == 0 && chan->channel->attr.overwrite == attr.attr.overwrite, "Validate kernel channel"); /* Init list in order to avoid sefaults from cds_list_del */ CDS_INIT_LIST_HEAD(&chan->list); trace_kernel_destroy_channel(chan); }
struct cds_list_head *pdeq_pop_r(struct pdeq *d) //\lnlbl{popr:b} { struct cds_list_head *e; spin_lock(&d->rlock); //\lnlbl{popr:acq:r1} e = deq_pop_r(&d->rdeq); //\lnlbl{popr:deq:rr1} if (e == NULL) { //\lnlbl{popr:check1} spin_unlock(&d->rlock); //\lnlbl{popr:rel:r1} spin_lock(&d->llock); //\lnlbl{popr:acq:l} spin_lock(&d->rlock); //\lnlbl{popr:acq:r2} e = deq_pop_r(&d->rdeq); //\lnlbl{popr:deq:rr2} if (e == NULL) { //\lnlbl{popr:check2} e = deq_pop_r(&d->ldeq); //\lnlbl{popr:deq:rl} cds_list_splice(&d->ldeq.chain, &d->rdeq.chain);//\lnlbl{popr:move} CDS_INIT_LIST_HEAD(&d->ldeq.chain); //\lnlbl{popr:init:l} } spin_unlock(&d->llock); //\lnlbl{popr:rel:l} } //\lnlbl{popr:skip2} spin_unlock(&d->rlock); //\lnlbl{popr:rel:r2} return e; } //\lnlbl{popr:e}
static int enqueue_notification_from_current_message( struct lttng_notification_channel *channel) { int ret = 0; struct lttng_notification *notification; struct pending_notification *pending_notification; if (channel->pending_notifications.count >= DEFAULT_CLIENT_MAX_QUEUED_NOTIFICATIONS_COUNT) { /* Drop the notification. */ ret = enqueue_dropped_notification(channel); goto end; } pending_notification = zmalloc(sizeof(*pending_notification)); if (!pending_notification) { ret = -1; goto error; } CDS_INIT_LIST_HEAD(&pending_notification->node); notification = create_notification_from_current_message(channel); if (!notification) { ret = -1; goto error; } pending_notification->notification = notification; cds_list_add(&pending_notification->node, &channel->pending_notifications.list); channel->pending_notifications.count++; end: return ret; error: free(pending_notification); goto end; }
static void test_create_kernel_event(void) { struct ltt_kernel_event *event; struct lttng_event ev; memset(&ev, 0, sizeof(ev)); strncpy(ev.name, get_random_string(), LTTNG_KERNEL_SYM_NAME_LEN); ev.type = LTTNG_EVENT_TRACEPOINT; ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; event = trace_kernel_create_event(&ev); ok(event != NULL, "Create kernel event"); ok(event->fd == -1 && event->enabled == 1 && event->event->instrumentation == LTTNG_KERNEL_TRACEPOINT && strlen(event->event->name), "Validate kernel event"); /* Init list in order to avoid sefaults from cds_list_del */ CDS_INIT_LIST_HEAD(&event->list); trace_kernel_destroy_event(event); }
void init_deq(struct deq *p) { CDS_INIT_LIST_HEAD(&p->chain); }
void init_deq(struct deq *p) { spin_lock_init(&p->lock); CDS_INIT_LIST_HEAD(&p->chain); }
struct lttng_notification_channel *lttng_notification_channel_create( struct lttng_endpoint *endpoint) { int fd, ret; bool is_in_tracing_group = false, is_root = false; char *sock_path = NULL; struct lttng_notification_channel *channel = NULL; if (!endpoint || endpoint != lttng_session_daemon_notification_endpoint) { goto end; } sock_path = zmalloc(LTTNG_PATH_MAX); if (!sock_path) { goto end; } channel = zmalloc(sizeof(struct lttng_notification_channel)); if (!channel) { goto end; } channel->socket = -1; pthread_mutex_init(&channel->lock, NULL); lttng_dynamic_buffer_init(&channel->reception_buffer); CDS_INIT_LIST_HEAD(&channel->pending_notifications.list); is_root = (getuid() == 0); if (!is_root) { is_in_tracing_group = lttng_check_tracing_group(); } if (is_root || is_in_tracing_group) { lttng_ctl_copy_string(sock_path, DEFAULT_GLOBAL_NOTIFICATION_CHANNEL_UNIX_SOCK, LTTNG_PATH_MAX); ret = lttcomm_connect_unix_sock(sock_path); if (ret >= 0) { fd = ret; goto set_fd; } } /* Fallback to local session daemon. */ ret = snprintf(sock_path, LTTNG_PATH_MAX, DEFAULT_HOME_NOTIFICATION_CHANNEL_UNIX_SOCK, utils_get_home_dir()); if (ret < 0 || ret >= LTTNG_PATH_MAX) { goto error; } ret = lttcomm_connect_unix_sock(sock_path); if (ret < 0) { goto error; } fd = ret; set_fd: channel->socket = fd; ret = handshake(channel); if (ret) { goto error; } end: free(sock_path); return channel; error: lttng_notification_channel_destroy(channel); channel = NULL; goto end; }