static inline void put_entry_d_sorted(int row, int col, double value, size_t pos, queue_d *queue, cstuff_DirectionMap *obj, entry_d **waiting) { entry_d *entry, *entry2, *entry3; entry = waiting[pos]; if (entry) { TAILQ_REMOVE(queue, entry, hook); } else { entry = get_entry_d(row, col, value); waiting[pos] = entry; } entry->row = row; entry->col = col; entry->value = value; obj->map->values[pos] = value; if (TAILQ_EMPTY(queue) || TAILQ_LAST(queue, _queue_d)->value <= value) { TAILQ_INSERT_TAIL(queue, entry, hook); } else if (TAILQ_FIRST(queue)->value > value) { TAILQ_INSERT_HEAD(queue, entry, hook); } else { entry2 = TAILQ_LAST(queue, _queue_d); TAILQ_FOREACH_REVERSE(entry3, queue, _queue_d, hook) { if (entry3->value > value) { entry2 = entry3; } else { break; } } TAILQ_INSERT_BEFORE(entry2, entry, hook); } }
static struct cache_policy_item_ * cache_lfu_policy_get_prev_item(struct cache_policy_ *policy, struct cache_policy_item_ *item) { struct cache_lfu_policy_ *lfu_policy; struct cache_lfu_policy_item_ *lfu_item; int i; TRACE_IN(cache_lfu_policy_get_prev_item); lfu_policy = (struct cache_lfu_policy_ *)policy; lfu_item = TAILQ_PREV((struct cache_lfu_policy_item_ *)item, cache_lfu_policy_group_, entries); if (lfu_item == NULL) { for (i = ((struct cache_lfu_policy_item_ *)item)->frequency - 1; i >= 0; --i) if (!TAILQ_EMPTY(&(lfu_policy->groups[i]))) { lfu_item = TAILQ_LAST(&(lfu_policy->groups[i]), cache_lfu_policy_group_); break; } } TRACE_OUT(cache_lfu_policy_get_prev_item); return ((struct cache_policy_item_ *)lfu_item); }
/** * load_one - Load one plugin * @path: Path to finit plugins, usually %PLUGIN_PATH * @name: Name of plugin, optionally ending in ".so" * * Loads a plugin from @path/@name[.so]. Note, if ".so" is missing from * the plugin @name it is added before attempting to load. * * It is up to the plugin itself ot register itself as a "ctor" with the * %PLUGIN_INIT macro so that plugin_register() is called automatically. * * Returns: * POSIX OK(0) on success, non-zero otherwise. */ static int load_one(char *path, char *name) { int noext; char sofile[CMD_SIZE]; void *handle; plugin_t *plugin; if (!path || !fisdir(path) || !name) { errno = EINVAL; return 1; } /* Compose full path, with optional .so extension, to plugin */ noext = strcmp(name + strlen(name) - 3, ".so"); snprintf(sofile, sizeof(sofile), "%s/%s%s", path, name, noext ? ".so" : ""); _d("Loading plugin %s ...", basename(sofile)); handle = dlopen(sofile, RTLD_LAZY | RTLD_LOCAL); if (!handle) { _e("Failed loading plugin %s: %s", sofile, dlerror()); return 1; } plugin = TAILQ_LAST(&plugins, plugin_head); if (!plugin) { _e("Plugin %s failed to register, unloading from memory", sofile); dlclose(handle); return 1; } /* Remember handle from dlopen() for plugin_unregister() */ plugin->handle = handle; return 0; }
/* * db_exist -- * Return if a line exists. * * PUBLIC: int db_exist(SCR *, recno_t); */ int db_exist( SCR *sp, recno_t lno) { EXF *ep; /* Check for no underlying file. */ if ((ep = sp->ep) == NULL) { ex_emsg(sp, NULL, EXM_NOFILEYET); return (1); } if (lno == OOBLNO) return (0); /* * Check the last-line number cache. Adjust the cached line * number for the lines used by the text input buffers. */ if (ep->c_nlines != OOBLNO) return (lno <= (F_ISSET(sp, SC_TINPUT) ? ep->c_nlines + (((TEXT *)TAILQ_LAST(sp->tiq, _texth))->lno - ((TEXT *)TAILQ_FIRST(sp->tiq))->lno) : ep->c_nlines)); /* Go get the line. */ return (!db_get(sp, lno, 0, NULL, NULL)); }
int del_panel(PANEL *p) { if (__predict_false(p == NULL)) return ERR; (void) hide_panel(p); free(p); /* * If the last panel is removed, remove the phantom stdscr * panel as well. * * A program that wants to switch to a different screen with * set_term(3), or ends and recreates curses session with * endwin(3)/initscr(3), must delete all panels first, since * their windows will become invalid. When it will create its * first new panel afterwards, it will pick up new stdscr. */ if (TAILQ_LAST(&_deck, deck) == &_stdscr_panel) { (void) hide_panel(&_stdscr_panel); assert(TAILQ_EMPTY(&_deck)); } return OK; }
int trace_enter(int fd, char *line, int closed) { struct trace *tmp; int res; assert(fd >= 0); if (trace_refs == NULL || fd >= trace_refsize) { res = trace_init(fd); if (res == -1) goto error; } if ((tmp = TAILQ_LAST(trace_refs[fd], traceq)) != NULL) { if (tmp->closed) trace_free(fd); } if ((tmp = malloc(sizeof(struct trace))) == NULL) goto error; tmp->line = line; tmp->closed = closed; TAILQ_INSERT_TAIL(trace_refs[fd], tmp, next); return (0); error: free(line); return (-1); }
/* * Find an address entry's position in the address list * according to bridge interface name. */ static struct tp_entry * bridge_addrs_find_pos(struct tp_entries *headp, uint32_t b_idx) { uint32_t t_idx; struct tp_entry *t1; if ((t1 = TAILQ_FIRST(headp)) == NULL || bridge_compare_sysidx(b_idx, t1->sysindex) < 0) return (NULL); t_idx = t1->sysindex; for (t1 = TAILQ_NEXT(t1, tp_e); t1 != NULL; t1 = TAILQ_NEXT(t1, tp_e)) { if (t1->sysindex != t_idx) { if (bridge_compare_sysidx(b_idx, t1->sysindex) < 0) return (TAILQ_PREV(t1, tp_entries, tp_e)); else t_idx = t1->sysindex; } } if (t1 == NULL) t1 = TAILQ_LAST(headp, tp_entries); return (t1); }
struct tag* tag_new(struct screen *s, char *name) { struct tag *t, *l; t = xcalloc(1, sizeof(struct tag)); t->screen = s; t->flags = 0; t->id = 0; t->sel = NULL; t->prev = NULL; if((l = TAILQ_LAST(&s->tags, tsub))) t->id = l->id + 1; if(!name || !strlen(name)) xasprintf(&t->name, "%d", t->id + 1); else t->name = xstrdup(name); SLIST_INIT(&t->clients); TAILQ_INIT(&t->sets); TAILQ_INSERT_TAIL(&s->tags, t, next); return t; }
int imageboot_setup() { dev_t dev; int error = 0; char *root_path = NULL; DBG_TRACE("%s: entry\n", __FUNCTION__); MALLOC_ZONE(root_path, caddr_t, MAXPATHLEN, M_NAMEI, M_WAITOK); if (root_path == NULL) return (ENOMEM); if(PE_parse_boot_argn("rp", root_path, MAXPATHLEN) == FALSE) { error = ENOENT; goto done; } printf("%s: root image url is %s\n", __FUNCTION__, root_path); error = di_root_image(root_path, rootdevice, &dev); if(error) { printf("%s: di_root_image failed: %d\n", __FUNCTION__, error); goto done; } rootdev = dev; mountroot = NULL; printf("%s: root device 0x%x\n", __FUNCTION__, rootdev); error = vfs_mountroot(); if (error == 0 && rootvnode != NULL) { struct vnode *tvp; struct vnode *newdp; /* * Get the vnode for '/'. * Set fdp->fd_fd.fd_cdir to reference it. */ if (VFS_ROOT(TAILQ_LAST(&mountlist,mntlist), &newdp, vfs_context_kernel())) panic("%s: cannot find root vnode", __FUNCTION__); vnode_ref(newdp); vnode_put(newdp); tvp = rootvnode; vnode_rele(tvp); filedesc0.fd_cdir = newdp; rootvnode = newdp; mount_list_lock(); TAILQ_REMOVE(&mountlist, TAILQ_FIRST(&mountlist), mnt_list); mount_list_unlock(); mountlist.tqh_first->mnt_flag |= MNT_ROOTFS; DBG_TRACE("%s: root switched\n", __FUNCTION__); } done: FREE_ZONE(root_path, MAXPATHLEN, M_NAMEI); DBG_TRACE("%s: exit\n", __FUNCTION__); return (error); }
int main() { int i; struct type tmp[20]; struct type *echo; //step 1: init TAILQ_INIT(&header); //step 2: insert item for (i = 0; i < strlen(name); i++) { tmp[i].c = *(name + i); tmp[i].list.tqe_next = NULL; tmp[i].list.tqe_prev = NULL; TAILQ_INSERT_TAIL(&header, &tmp[i], list); } //step 3 : get element. #if defined(_FIFO_) while ((echo = TAILQ_FIRST(&header)) != NULL) { #elif defined(_FILO_) while ((echo = TAILQ_LAST(&header, head_)) != NULL){ #endif printf("%2c", echo->c); TAILQ_REMOVE(&header, echo, list); } printf("\n"); return 0; }
/* * Get the newest file */ timeshift_file_t *timeshift_filemgr_newest ( timeshift_t *ts ) { timeshift_file_t *tsf = TAILQ_LAST(&ts->files, timeshift_file_list); if (tsf) tsf->refcount++; return tsf; }
static void nav_close_all(navigator_t *nav, int with_prop) { nav_page_t *np; while((np = TAILQ_LAST(&nav->nav_pages, nav_page_queue)) != NULL) nav_close(np, with_prop); }
/*---------------------------------------------------------------------------*/ hg_queue_value_t hg_queue_peek_tail(hg_queue_t *queue) { if (!queue || hg_queue_is_empty(queue)) return HG_QUEUE_NULL; else return TAILQ_LAST(queue, hg_queue)->data; }
static ava_macro_subst_result ava_intr_loopctl_subst( const struct ava_symbol_s* self, ava_macsub_context* context, const ava_parse_statement* statement, const ava_parse_unit* provoker, ava_bool* consumed_other_statements, ava_bool is_break ) { ava_intr_loopctl* this; const ava_parse_unit* unit; this = AVA_NEW(ava_intr_loopctl); this->header.v = &ava_intr_loopctl_vtable; this->header.location = provoker->location; this->header.context = context; this->is_break = is_break; this->suppress_write_back = ava_false; this->expression = NULL; for (unit = TAILQ_NEXT(provoker, next); unit; unit = TAILQ_NEXT(unit, next)) { if (ava_put_bareword != unit->type || ava_string_is_empty(unit->v.string) || '-' != ava_string_index(unit->v.string, 0)) /* Not a flag */ break; switch (ava_string_to_ascii9(unit->v.string)) { case AVA_ASCII9('-'): if (this->suppress_write_back) return ava_macsub_error_result( context, ava_error_loopctl_flag_more_than_once( &unit->location, self->full_name, unit->v.string)); this->suppress_write_back = ava_true; break; default: return ava_macsub_error_result( context, ava_error_bad_loopctl_flag( &unit->location, self->full_name, unit->v.string)); } } if (unit) { if (this->suppress_write_back) return ava_macsub_error_result( context, ava_error_loopctl_expression_but_suppressed( &unit->location)); this->expression = ava_macsub_run_units( context, unit, TAILQ_LAST(&statement->units, ava_parse_unit_list_s)); } return (ava_macro_subst_result) { .status = ava_mss_done, .v = { .node = (ava_ast_node*)this }, }; }
void net_send_queue(struct connection *c, void *data, u_int32_t len, struct spdy_stream *s, int before) { u_int8_t *d; struct netbuf *nb; u_int32_t avail; kore_debug("net_send_queue(%p, %p, %d, %p, %d)", c, data, len, s, before); d = data; if (before == NETBUF_LAST_CHAIN) { nb = TAILQ_LAST(&(c->send_queue), netbuf_head); if (nb != NULL && !(nb->flags & NETBUF_IS_STREAM) && nb->stream == s && nb->b_len < nb->m_len) { avail = nb->m_len - nb->b_len; if (len < avail) { memcpy(nb->buf + nb->b_len, d, len); nb->b_len += len; return; } else if (len > avail) { memcpy(nb->buf + nb->b_len, d, avail); nb->b_len += avail; len -= avail; d += avail; if (len == 0) return; } } } nb = kore_pool_get(&nb_pool); nb->flags = 0; nb->cb = NULL; nb->owner = c; nb->s_off = 0; nb->stream = s; nb->b_len = len; nb->type = NETBUF_SEND; if (nb->b_len < NETBUF_SEND_PAYLOAD_MAX) nb->m_len = NETBUF_SEND_PAYLOAD_MAX; else nb->m_len = nb->b_len; nb->buf = kore_malloc(nb->m_len); if (len > 0) memcpy(nb->buf, d, nb->b_len); if (before == NETBUF_BEFORE_CHAIN) { TAILQ_INSERT_BEFORE(c->snb, nb, list); } else { TAILQ_INSERT_TAIL(&(c->send_queue), nb, list); } }
static int test_frag(char *overlap, int drop) { struct timeval tv, save_tv = read_tv; struct pkt *pkt; struct icmp_msg_echo *echo; char *frag_argv[4]; if (overlap != NULL) printf("frag-%s: ", overlap); else if (drop) printf("frag-timeout (please wait): "); else printf("frag: "); fflush(stdout); ping->pkt_ip->ip_id = rand_uint16(ctx.rnd); ping->pkt_icmp_msg->echo.icmp_id = rand_uint16(ctx.rnd); pkt = pkt_dup(ping); ip_checksum(pkt->pkt_ip, pkt->pkt_end - pkt->pkt_eth_data); TAILQ_INSERT_TAIL(&ctx.pktq, pkt, pkt_next); frag_argv[0] = "ip_frag"; frag_argv[1] = "8"; frag_argv[2] = overlap; frag_argv[3] = NULL; mod_ip_frag.open(overlap ? 3 : 2, frag_argv, NULL); mod_ip_frag.apply(NULL, &ctx.pktq, NULL); if (drop) { pkt = TAILQ_LAST(&ctx.pktq, pktq); TAILQ_REMOVE(&ctx.pktq, pkt, pkt_next); pkt_free(pkt); save_tv.tv_sec = FRAG_TIMEOUT; } pcap_filter(ctx.pcap, "icmp[0] = %d and src %s and dst %s", drop ? 11 : 0, addr_ntoa(&ctx.dst), addr_ntoa(&ctx.src)); send_pktq(&ctx.pktq); for (tv = save_tv; (pkt = recv_pkt(&tv)) != NULL; tv = save_tv) { if (drop) { echo = (struct icmp_msg_echo *) (pkt->pkt_icmp_msg->timexceed.icmp_ip + IP_HDR_LEN + ICMP_HDR_LEN); } else { echo = &pkt->pkt_icmp_msg->echo; } if (echo->icmp_id == ping->pkt_icmp_msg->echo.icmp_id) break; } printf("%s\n", pkt ? timeval_ntoa(&tv) : "no reply"); return (0); }
void viomb_deflate(struct viomb_softc *sc) { struct virtio_softc *vsc = (struct virtio_softc *)sc->sc_virtio; struct balloon_req *b; struct vm_page *p; struct virtqueue *vq = &sc->sc_vq[VQ_DEFLATE]; u_int64_t nvpages; int i, slot; nvpages = sc->sc_actual - sc->sc_npages; if (nvpages > PGS_PER_REQ) nvpages = PGS_PER_REQ; b = &sc->sc_req; b->bl_nentries = nvpages; TAILQ_INIT(&b->bl_pglist); for (i = 0; i < nvpages; i++) { p = TAILQ_FIRST(&sc->sc_balloon_pages); if (p == NULL){ b->bl_nentries = i - 1; break; } TAILQ_REMOVE(&sc->sc_balloon_pages, p, pageq); TAILQ_INSERT_TAIL(&b->bl_pglist, p, pageq); b->bl_pages[i] = p->phys_addr / VIRTIO_PAGE_SIZE; } if (virtio_enqueue_prep(vq, &slot)) { printf("%s:virtio_get_slot(def) vq_num %d\n", DEVNAME(sc), vq->vq_num); goto err; } if (virtio_enqueue_reserve(vq, slot, 1)) { printf("%s:virtio_enqueue_reserve() vq_num %d\n", DEVNAME(sc), vq->vq_num); goto err; } bus_dmamap_sync(vsc->sc_dmat, b->bl_dmamap, 0, sizeof(u_int32_t) * nvpages, BUS_DMASYNC_PREWRITE); virtio_enqueue_p(vq, slot, b->bl_dmamap, 0, sizeof(u_int32_t) * nvpages, VRING_READ); if (!(vsc->sc_features & VIRTIO_BALLOON_F_MUST_TELL_HOST)) uvm_pglistfree(&b->bl_pglist); virtio_enqueue_commit(vsc, vq, slot, VRING_NOTIFY); return; err: while ((p = TAILQ_LAST(&b->bl_pglist, pglist))) { TAILQ_REMOVE(&b->bl_pglist, p, pageq); TAILQ_INSERT_HEAD(&sc->sc_balloon_pages, p, pageq); } return; }
void uicb_tag_prev(Uicb cmd) { (void)cmd; struct tag *t; if((t = TAILQ_PREV(W->screen->seltag, tsub, next))) tag_screen(W->screen, t); else if( /* CIRCULAR OPTION */ 1) tag_screen(W->screen, TAILQ_LAST(&W->screen->tags, tsub)); }
static struct cache_policy_item_ * cache_queue_policy_get_last_item(struct cache_policy_ *policy) { struct cache_queue_policy_ *queue_policy; TRACE_IN(cache_queue_policy_get_last_item); queue_policy = (struct cache_queue_policy_ *)policy; TRACE_OUT(cache_queue_policy_get_last_item); return ((struct cache_policy_item_ *)TAILQ_LAST(&queue_policy->head, cache_queue_policy_head_)); }
void uicb_tag_prev(Uicb cmd) { (void)cmd; struct tag *t; if((t = TAILQ_PREV(W->screen->seltag, tsub, next))) tag_screen(W->screen, t); else if(W->flags & WMFS_TAGCIRC) tag_screen(W->screen, TAILQ_LAST(&W->screen->tags, tsub)); }
void *rd_lru_pop (rd_lru_t *rlru) { rd_lru_elm_t *rlrue; void *ptr; if ((rlrue = TAILQ_LAST(&rlru->rlru_elms, rd_lru_elm_head))) { ptr = rlrue->rlrue_ptr; rd_lru_elm_destroy(rlru, rlrue); } else ptr = NULL; return ptr; }
static streaming_message_t *_timeshift_find_sstart ( timeshift_file_t *tsf, int64_t time ) { timeshift_index_data_t *ti; /* Find the SMT_START message that relates (comes before) the given time */ ti = TAILQ_LAST(&tsf->sstart, timeshift_index_data_list); while (ti && ti->data->sm_time > time) ti = TAILQ_PREV(ti, timeshift_index_data_list, link); return ti ? ti->data : NULL; }
struct mbuf *mbuf_queue_get(struct context *ctx, struct mhdr *q) { struct mbuf *buf = NULL; if (!TAILQ_EMPTY(q)) buf = TAILQ_LAST(q, mhdr); if (buf == NULL || mbuf_full(buf)) { buf = mbuf_get(ctx); buf->queue = q; TAILQ_INSERT_TAIL(q, buf, next); } return buf; }
void uicb_tag_move_client_prev(Uicb cmd) { (void)cmd; struct tag *t; if(!W->client) return; if((t = TAILQ_PREV(W->screen->seltag, tsub, next))) tag_client(t, W->client); else if( /* CIRCULAR OPTION */ 1) tag_client(TAILQ_LAST(&W->screen->tags, tsub), W->client); }
static void queue_envelope_cache_add(struct envelope *e) { struct envelope *cached; while (tree_count(&evpcache_tree) >= env->sc_queue_evpcache_size) queue_envelope_cache_del(TAILQ_LAST(&evpcache_list, evplst)->id); cached = xcalloc(1, sizeof *cached, "queue_envelope_cache_add"); *cached = *e; TAILQ_INSERT_HEAD(&evpcache_list, cached, entry); tree_xset(&evpcache_tree, e->id, cached); stat_increment("queue.evpcache.size", 1); }
int qw_pop(void *handle, void **data) { struct qw_node *node = NULL; QW *qw_p = (QW *)handle; *data = NULL; if(!TAILQ_EMPTY(&qw_p->h)) { node = TAILQ_LAST(&qw_p->h, qw_h); *data = node->d; TAILQ_REMOVE(&qw_p->h, node, entries); free(node); } return ((*data != NULL) ? 0 : -1); }
void AutoreleasePoolAddObject(const void *object) { COAssertNoNullOrBailOut(object,EINVAL); if (ThreadAutoreleasePools.tqh_last == NULL && ThreadAutoreleasePools.tqh_first == NULL) TAILQ_INIT(&ThreadAutoreleasePools); struct threadAutoreleasePoolsHeadItem *item = TAILQ_LAST(&ThreadAutoreleasePools, ThreadAutoreleasePoolsHead); if (item == NULL) { fprintf(stderr, "Object of class %s autoreleased with no pool, just leaking\n", getClassName(object)); return; } else { struct AutoreleasePool *pool = item->autoreleasePool; addAutoreleaseObject(pool, object); } }
static timeshift_index_iframe_t *_timeshift_last_frame ( timeshift_t *ts ) { int end; timeshift_index_iframe_t *tsi = NULL; timeshift_file_t *tsf = timeshift_filemgr_get(ts, 0); while (tsf && !tsi) { if (!(tsi = TAILQ_LAST(&tsf->iframes, timeshift_index_iframe_list))) { tsf = timeshift_filemgr_prev(tsf, &end, 0); } } if (tsf) tsf->refcount--; return tsi; }
/* * add a packet to a stream */ int stream_add(struct stream_object *so, struct log_header_packet *pck, char *buf) { struct so_list *pl, *tmp; /* skip ack packet or zero lenght packet */ if (pck->len == 0) return 0; /* the packet is good, add it */ SAFE_CALLOC(pl, 1, sizeof(struct so_list)); /* create the packet object */ memcpy(&pl->po.L3.src, &pck->L3_src, sizeof(struct ip_addr)); memcpy(&pl->po.L3.dst, &pck->L3_dst, sizeof(struct ip_addr)); pl->po.L4.src = pck->L4_src; pl->po.L4.dst = pck->L4_dst; pl->po.L4.proto = pck->L4_proto; SAFE_CALLOC(pl->po.DATA.data, pck->len, sizeof(char)); memcpy(pl->po.DATA.data, buf, pck->len); pl->po.DATA.len = pck->len; /* set the stream direction */ /* this is the first packet in the stream */ if (TAILQ_FIRST(&so->so_head) == TAILQ_END(&so->so_head)) { pl->side = STREAM_SIDE1; /* init the pointer to the first packet */ so->side1.so_curr = pl; so->side2.so_curr = pl; /* check the previous one and set it accordingly */ } else { tmp = TAILQ_LAST(&so->so_head, so_list_head); if (!ip_addr_cmp(&tmp->po.L3.src, &pl->po.L3.src)) /* same direction */ pl->side = tmp->side; else /* change detected */ pl->side = (tmp->side == STREAM_SIDE1) ? STREAM_SIDE2 : STREAM_SIDE1; } /* add to the queue */ TAILQ_INSERT_TAIL(&so->so_head, pl, next); return pck->len; }
// 'unprocessed buf': buf is full and has data unprocessed. // // 1. If last buf is nut full, it is returned. // 2. If `unprocessed` is true and the last buf is the unprocessed buf, // the last buf is returned. // 3. Otherwise a new buf is returned. struct mbuf *conn_get_buf(struct connection *conn, bool unprocessed) { struct mbuf *buf = NULL; struct conn_info *info = conn->info; if (!TAILQ_EMPTY(&info->data)) { buf = TAILQ_LAST(&info->data, mhdr); } if (buf == NULL || (unprocessed ? buf->pos : buf->last) >= buf->end) { buf = mbuf_get(conn->ctx); buf->queue = &info->data; TAILQ_INSERT_TAIL(&info->data, buf, next); } return buf; }