コード例 #1
0
ファイル: test33.c プロジェクト: acorbe/uthash
int main(int argc, char *argv[]) {
    el *name, *tmp;
    el *head = NULL;

    char linebuf[BUFLEN];
    FILE *file;

    file = fopen( "test11.dat", "r" );
    if (file == NULL) {
        perror("can't open: ");
        exit(-1);
    }

    while (fgets(linebuf,BUFLEN,file) != NULL) {
        name = (el*)malloc(sizeof(el));
        if (name == NULL) exit(-1);
        strncpy(name->bname,linebuf,sizeof(name->bname));
        LL_PREPEND(head, name);
    }
    LL_SORT(head, namecmp);
    LL_FOREACH(head,tmp) printf("%s", tmp->bname);

    fclose(file);

    return 0;
}
コード例 #2
0
ファイル: pocl_mem_management.c プロジェクト: MoKarma/pocl
void pocl_mem_manager_free_event (cl_event event)
{
  assert (event->status == CL_COMPLETE);
  POCL_LOCK (mm->event_lock);
  LL_PREPEND (mm->event_list, event);
  POCL_UNLOCK(mm->event_lock);
}
コード例 #3
0
ファイル: gnrc_sixlowpan_frag.c プロジェクト: kbumsik/RIOT
static gnrc_pktsnip_t *_build_frag_pkt(gnrc_pktsnip_t *pkt, size_t payload_len,
                                       size_t size)
{
    gnrc_netif_hdr_t *hdr = pkt->data, *new_hdr;
    gnrc_pktsnip_t *netif, *frag;

    netif = gnrc_netif_hdr_build(gnrc_netif_hdr_get_src_addr(hdr), hdr->src_l2addr_len,
                                 gnrc_netif_hdr_get_dst_addr(hdr), hdr->dst_l2addr_len);

    if (netif == NULL) {
        DEBUG("6lo frag: error allocating new link-layer header\n");
        return NULL;
    }

    new_hdr = netif->data;
    new_hdr->if_pid = hdr->if_pid;
    new_hdr->flags = hdr->flags;
    new_hdr->rssi = hdr->rssi;
    new_hdr->lqi = hdr->lqi;

    frag = gnrc_pktbuf_add(NULL, NULL, _min(size, payload_len),
                           GNRC_NETTYPE_SIXLOWPAN);

    if (frag == NULL) {
        DEBUG("6lo frag: error allocating first fragment\n");
        gnrc_pktbuf_release(netif);
        return NULL;
    }

    LL_PREPEND(frag, netif);

    return frag;
}
コード例 #4
0
void
ucl_object_emit_streamline_start_container (struct ucl_emitter_context *ctx,
		const ucl_object_t *obj)
{
	struct ucl_emitter_context_streamline *sctx = TO_STREAMLINE(ctx);
	struct ucl_emitter_streamline_stack *st, *top;
	bool print_key = false;

	/* Check top object presence */
	if (sctx->top == NULL) {
		sctx->top = obj;
	}

	top = sctx->containers;
	st = malloc (sizeof (*st));
	if (st != NULL) {
		if (top != NULL && !top->is_array) {
			print_key = true;
		}
		st->empty = true;
		st->obj = obj;
		if (obj != NULL && obj->type == UCL_ARRAY) {
			st->is_array = true;
			sctx->ops->ucl_emitter_start_array (ctx, obj, print_key);
		}
		else {
			st->is_array = false;
			sctx->ops->ucl_emitter_start_object (ctx, obj, print_key);
		}
		LL_PREPEND (sctx->containers, st);
	}
}
コード例 #5
0
ファイル: event_queue.cpp プロジェクト: rus084/rusefi
/**
 * Invoke all pending actions prior to specified timestamp
 */
void EventQueue::executeAll(uint64_t now) {
    scheduling_s * current, *tmp;

    scheduling_s * executionList = NULL;

    int counter = 0;

    // we need safe iteration because we are removing elements inside the loop
    LL_FOREACH_SAFE(head, current, tmp)
    {
        if (++counter > QUEUE_LENGTH_LIMIT) {
            firmwareError("Is this list looped?");
            return;
        }
        if (current->momentUs <= now) {
            LL_DELETE(head, current);
            LL_PREPEND(executionList, current);
        }
    }

    /*
     * we need safe iteration here because 'callback' might change change 'current->next'
     * while re-inserting it into the queue from within the callback
     */
    LL_FOREACH_SAFE(executionList, current, tmp)
    current->callback(current->param);
}
コード例 #6
0
static void _add_prefix(kernel_pid_t iface, gnrc_sixlowpan_nd_router_abr_t *abr,
                        ndp_opt_pi_t *pi_opt)
{
    gnrc_sixlowpan_nd_router_prf_t *prf_ent;
    gnrc_ipv6_netif_t *ipv6_iface = gnrc_ipv6_netif_get(iface);
    ipv6_addr_t *prefix;

    if ((pi_opt->len != NDP_OPT_PI_LEN) || ipv6_addr_is_link_local(&pi_opt->prefix) ||
        (pi_opt->flags & NDP_OPT_PI_FLAGS_A) ||
        (pi_opt->flags & NDP_OPT_PI_FLAGS_L) ||
        (pi_opt->valid_ltime.u32 == 0)) {
        return;
    }

    prefix = gnrc_ipv6_netif_match_prefix(iface, &pi_opt->prefix);

    prf_ent = _get_free_prefix(&pi_opt->prefix, pi_opt->prefix_len);

    if (prf_ent != NULL) {
        prf_ent->iface = ipv6_iface;
        prf_ent->prefix = container_of(prefix, gnrc_ipv6_netif_addr_t, addr);
    }

    LL_PREPEND(abr->prfs, prf_ent);
}
コード例 #7
0
ファイル: bc.c プロジェクト: SinoJerk/robovm
static Field* loadFields(Env* env, Class* clazz) {
    ClassInfoHeader* header = lookupClassInfo(env, clazz->name, 
        !clazz->classLoader || !clazz->classLoader->parent ? _bcBootClassesHash : _bcClassesHash);
    if (!header) return NULL;

    ClassInfo ci;
    jint i;
    void* p = header;
    readClassInfo(&p, &ci);

    skipInterfaceNames(&p, &ci);

    Field* first = NULL;
    for (i = 0; i < ci.fieldCount; i++) {
        FieldInfo fi;
        readFieldInfo(&p, &fi);
        Field* f = rvmAllocateField(env, clazz, fi.name, fi.desc, fi.access, fi.offset, fi.attributes);
        if (!f) goto error;
        LL_PREPEND(first, f);
    }
    return first;
error:
    while (first) {
        Field* next = first->next;
        rvmFreeMemoryUncollectable(env, first);
        first = next;
    }
    return NULL;
}
コード例 #8
0
ファイル: ucl_schema.c プロジェクト: AAZemlyanukhin/freebsd
static bool
ucl_schema_array_is_unique (const ucl_object_t *obj, struct ucl_schema_error *err)
{
	ucl_compare_tree_t tree = TREE_INITIALIZER (ucl_schema_elt_compare);
	ucl_object_iter_t iter = NULL;
	const ucl_object_t *elt;
	struct ucl_compare_node *node, test, *nodes = NULL, *tmp;
	bool ret = true;

	while ((elt = ucl_iterate_object (obj, &iter, true)) != NULL) {
		test.obj = elt;
		node = TREE_FIND (&tree, ucl_compare_node, link, &test);
		if (node != NULL) {
			ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, elt,
					"duplicate values detected while uniqueItems is true");
			ret = false;
			break;
		}
		node = calloc (1, sizeof (*node));
		if (node == NULL) {
			ucl_schema_create_error (err, UCL_SCHEMA_UNKNOWN, elt,
					"cannot allocate tree node");
			ret = false;
			break;
		}
		node->obj = elt;
		TREE_INSERT (&tree, ucl_compare_node, link, node);
		LL_PREPEND (nodes, node);
	}

	LL_FOREACH_SAFE (nodes, node, tmp) {
		free (node);
	}
コード例 #9
0
ファイル: gnrc_ipv6.c プロジェクト: AdamRLukaitis/RIOT
/* functions for sending */
static void _send_unicast(kernel_pid_t iface, uint8_t *dst_l2addr,
                          uint16_t dst_l2addr_len, gnrc_pktsnip_t *pkt)
{
    gnrc_pktsnip_t *netif;

    if (pkt->type == GNRC_NETTYPE_NETIF) {
        /* great: someone already added a netif_hdr_t we assume it's wrong
         * to keep it simple
         * XXX: alternative would be to check if gnrc_netif_hdr_t::dst_l2addr_len
         * is long enough and only then to throw away the header. This causes
         * to much overhead IMHO */
        DEBUG("ipv6: removed old interface header\n");
        pkt = gnrc_pktbuf_remove_snip(pkt, pkt);
    }

    DEBUG("ipv6: add interface header to packet\n");
    netif = gnrc_netif_hdr_build(NULL, 0, dst_l2addr, dst_l2addr_len);

    if (netif == NULL) {
        DEBUG("ipv6: error on interface header allocation, dropping packet\n");
        gnrc_pktbuf_release(pkt);
        return;
    }

    /* add netif to front of the pkt list */
    LL_PREPEND(pkt, netif);

    DEBUG("ipv6: send unicast over interface %" PRIkernel_pid "\n", iface);
    /* and send to interface */
#ifdef MODULE_NETSTATS_IPV6
    gnrc_ipv6_netif_get_stats(iface)->tx_unicast_count++;
#endif
    _send_to_iface(iface, pkt);
}
コード例 #10
0
OCStackResult PDMGetOwnedDevices(OCUuidList_t **uuidList, size_t *numOfDevices)
{
    CHECK_PDM_INIT(TAG);
    if (NULL != *uuidList)
    {
        OC_LOG(ERROR, TAG, "Not null list will cause memory leak");
        return OC_STACK_INVALID_PARAM;
    }
    sqlite3_stmt *stmt = 0;
    int res = 0;
    res = sqlite3_prepare_v2(g_db, PDM_SQLITE_LIST_ALL_UUID,
                              strlen(PDM_SQLITE_LIST_ALL_UUID) + 1, &stmt, NULL);
    PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR);

    int counter  = 0;
    while (SQLITE_ROW == sqlite3_step(stmt))
    {

        const void *ptr = sqlite3_column_blob(stmt, PDM_FIRST_INDEX);
        OicUuid_t *uid = (OicUuid_t *)ptr;
        OCUuidList_t *temp = (OCUuidList_t *) OICCalloc(1,sizeof(OCUuidList_t));
        if (NULL == temp)
        {
            OC_LOG_V(ERROR, TAG, "Memory allocation problem");
            sqlite3_finalize(stmt);
            return OC_STACK_NO_MEMORY;
        }
        memcpy(&temp->dev.id, uid->id, UUID_LENGTH);
        LL_PREPEND(*uuidList,temp);
        ++counter;
    }
    *numOfDevices = counter;
    sqlite3_finalize(stmt);
    return OC_STACK_OK;
}
コード例 #11
0
ファイル: memory.c プロジェクト: TimurTarasenko/robovm
void rvmRegisterReference(Env* env, Object* reference, Object* referent) {
    if (referent) {
        // Add 'reference' to the references list for 'referent' in the referents hashtable
        rvmLockMutex(&referentsLock);

        ReferenceList* l = rvmAllocateMemory(env, sizeof(ReferenceList));
        if (!l) goto done; // OOM thrown
        l->reference = reference;

        void* key = (void*) GC_HIDE_POINTER(referent); // Hide the pointer from the GC so that it doesn't prevent the referent from being GCed.
        ReferentEntry* referentEntry;
        HASH_FIND_PTR(referents, &key, referentEntry);
        if (!referentEntry) {
            // referent is not in the hashtable. Add it.
            referentEntry = rvmAllocateMemory(env, sizeof(ReferentEntry));
            if (!referentEntry) goto done; // OOM thrown
            referentEntry->key = key;
            HASH_ADD_PTR(referents, key, referentEntry);
        }

        // Add the reference to the referent's list of references
        LL_PREPEND(referentEntry->references, l);

        // Register the referent for finalization
        GC_REGISTER_FINALIZER_NO_ORDER(referent, _finalizeObject, NULL, NULL, NULL);

done:
        rvmUnlockMutex(&referentsLock);
    }
}
コード例 #12
0
ファイル: sc_netif.c プロジェクト: ryankurte/RIOT
/* shell commands */
int _netif_send(int argc, char **argv)
{
    kernel_pid_t dev;
    uint8_t addr[MAX_ADDR_LEN];
    size_t addr_len;
    gnrc_pktsnip_t *pkt, *hdr;
    gnrc_netif_hdr_t *nethdr;
    uint8_t flags = 0x00;

    if (argc < 4) {
        printf("usage: %s <if> [<L2 addr>|bcast] <data>\n", argv[0]);
        return 1;
    }

    /* parse interface */
    dev = atoi(argv[1]);

    if (!_is_iface(dev)) {
        puts("error: invalid interface given");
        return 1;
    }

    /* parse address */
    addr_len = gnrc_netif_addr_from_str(addr, sizeof(addr), argv[2]);

    if (addr_len == 0) {
        if (strcmp(argv[2], "bcast") == 0) {
            flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST;
        }
        else {
            puts("error: invalid address given");
            return 1;
        }
    }

    /* put packet together */
    pkt = gnrc_pktbuf_add(NULL, argv[3], strlen(argv[3]), GNRC_NETTYPE_UNDEF);
    if (pkt == NULL) {
        puts("error: packet buffer full");
        return 1;
    }
    hdr = gnrc_netif_hdr_build(NULL, 0, addr, addr_len);
    if (hdr == NULL) {
        puts("error: packet buffer full");
        gnrc_pktbuf_release(pkt);
        return 1;
    }
    LL_PREPEND(pkt, hdr);
    nethdr = (gnrc_netif_hdr_t *)hdr->data;
    nethdr->flags = flags;
    /* and send it */
    if (gnrc_netapi_send(dev, pkt) < 1) {
        puts("error: unable to send");
        gnrc_pktbuf_release(pkt);
        return 1;
    }

    return 0;
}
コード例 #13
0
ファイル: ng_netreg.c プロジェクト: 4dahalibut/RIOT
int ng_netreg_register(ng_nettype_t type, ng_netreg_entry_t *entry)
{
    if (_INVALID_TYPE(type)) {
        return -EINVAL;
    }

    LL_PREPEND(netreg[type], entry);

    return 0;
}
コード例 #14
0
ファイル: indexer.c プロジェクト: mc4/Systems_Programming
/*
 * Adds a file node to the head of the file list in the word given as an argument
 * also sets the count to 1 for that file
 */
void addFileNode( TokenPtr word, char *filename ) {
	FileNodePtr fileNode;
	if ( (fileNode = (FileNodePtr) malloc(sizeof(struct FileNode))) == NULL ) exit(-1);
	char *newFilename = (char *) malloc(sizeof(char) * strlen(filename));
	strcpy(newFilename, filename);
	fileNode->filename = newFilename;
	fileNode->tokenCount = 1;
	fileNode->next = NULL;

	// add node to head of list
	LL_PREPEND(word->fileHead, fileNode);
}
コード例 #15
0
ファイル: xmpp_parser.c プロジェクト: BellerophonMobile/xmp3
/** Expat callback for namespace declarations. */
static void ns_start(void *data, const char *prefix, const char *uri) {
    struct xmpp_parser *parser = (struct xmpp_parser*)data;

    struct xmpp_parser_namespace *ns = calloc(1, sizeof(*ns));
    check_mem(ns);

    if (prefix) {
        STRDUP_CHECK(ns->prefix, prefix);
    }
    STRDUP_CHECK(ns->uri, uri);
    LL_PREPEND(parser->namespaces, ns);
}
コード例 #16
0
void gnrc_icmpv6_echo_req_handle(gnrc_netif_t *netif, ipv6_hdr_t *ipv6_hdr,
                                 icmpv6_echo_t *echo, uint16_t len)
{
    uint8_t *payload = ((uint8_t *)echo) + sizeof(icmpv6_echo_t);
    gnrc_pktsnip_t *hdr, *pkt;

    if ((echo == NULL) || (len < sizeof(icmpv6_echo_t))) {
        DEBUG("icmpv6_echo: echo was NULL or len (%" PRIu16
              ") was < sizeof(icmpv6_echo_t)\n", len);
        return;
    }

    pkt = gnrc_icmpv6_echo_build(ICMPV6_ECHO_REP, byteorder_ntohs(echo->id),
                                 byteorder_ntohs(echo->seq), payload,
                                 len - sizeof(icmpv6_echo_t));

    if (pkt == NULL) {
        DEBUG("icmpv6_echo: no space left in packet buffer\n");
        return;
    }

    if (ipv6_addr_is_multicast(&ipv6_hdr->dst)) {
        hdr = gnrc_ipv6_hdr_build(pkt, NULL, &ipv6_hdr->src);
    }
    else {
        hdr = gnrc_ipv6_hdr_build(pkt, &ipv6_hdr->dst, &ipv6_hdr->src);
    }

    if (hdr == NULL) {
        DEBUG("icmpv6_echo: no space left in packet buffer\n");
        gnrc_pktbuf_release(pkt);
        return;
    }

    pkt = hdr;
    hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0);

    if (netif != NULL) {
        ((gnrc_netif_hdr_t *)hdr->data)->if_pid = netif->pid;
    }
    else {
        /* ipv6_hdr->dst is loopback address */
        ((gnrc_netif_hdr_t *)hdr->data)->if_pid = KERNEL_PID_UNDEF;
    }

    LL_PREPEND(pkt, hdr);

    if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_IPV6, GNRC_NETREG_DEMUX_CTX_ALL,
                                   pkt)) {
        DEBUG("icmpv6_echo: no receivers for IPv6 packets\n");
        gnrc_pktbuf_release(pkt);
    }
}
コード例 #17
0
ファイル: async.c プロジェクト: WojciechLuczkow/iotivity
coap_async_state_t *
coap_register_async(coap_context_t *context, coap_address_t *peer, coap_pdu_t *request,
        unsigned char flags, void *data)
{
    coap_async_state_t *s;
    coap_tid_t id;

    coap_transaction_id(peer, request, &id);
    LL_SEARCH_SCALAR(context->async_state, s, id, id);

    if (s != NULL)
    {
        /* We must return NULL here as the caller must know that he is
         * responsible for releasing @p data. */
        debug("asynchronous state for transaction %d already registered\n", id);
        return NULL;
    }

    /* store information for handling the asynchronous task */
    s = (coap_async_state_t *) coap_malloc(sizeof(coap_async_state_t) +
            request->hdr->token_length);
    if (!s)
    {
        coap_log(LOG_CRIT, "coap_register_async: insufficient memory\n");
        return NULL;
    }

    memset(s, 0, sizeof(coap_async_state_t) + request->hdr->token_length);

    /* set COAP_ASYNC_CONFIRM according to request's type */
    s->flags = flags & ~COAP_ASYNC_CONFIRM;
    if (request->hdr->type == COAP_MESSAGE_CON)
        s->flags |= COAP_ASYNC_CONFIRM;

    s->appdata = data;

    memcpy(&s->peer, peer, sizeof(coap_address_t));

    if (request->hdr->token_length)
    {
        s->tokenlen = request->hdr->token_length;
        memcpy(s->token, request->hdr->token, request->hdr->token_length);
    }

    memcpy(&s->id, &id, sizeof(coap_tid_t));

    coap_touch_async(s);

    LL_PREPEND(context->async_state, s);

    return s;
}
コード例 #18
0
ファイル: gnrc_netreg.c プロジェクト: JMR-b/RIOT
int gnrc_netreg_register(gnrc_nettype_t type, gnrc_netreg_entry_t *entry)
{
    /* only threads with a message queue are allowed to register at gnrc */
    assert(sched_threads[entry->pid]->msg_array);

    if (_INVALID_TYPE(type)) {
        return -EINVAL;
    }

    LL_PREPEND(netreg[type], entry);

    return 0;
}
コード例 #19
0
ファイル: event_queue.cpp プロジェクト: rus084/rusefi
void EventQueue::insertTask(scheduling_s *scheduling, uint64_t nowUs, int delayUs, schfunc_t callback, void *param) {
    if (callback == NULL)
        firmwareError("NULL callback");
    uint64_t time = nowUs + delayUs;

    int alreadyPending = checkIfPending(scheduling);
    if (alreadyPending || hasFirmwareError())
        return;

    scheduling->momentUs = time;
    scheduling->callback = callback;
    scheduling->param = param;

    LL_PREPEND(head, scheduling);
}
コード例 #20
0
ファイル: memory.c プロジェクト: tobium/robovm
void registerCleanupHandler(Env* env, Object* object, CleanupHandler handler) {
    rvmLockMutex(&referentsLock);
    CleanupHandlerList* l = rvmAllocateMemory(env, sizeof(CleanupHandlerList));
    if (!l) goto done; // OOM thrown
    l->handler = handler;
    ReferentEntry* referentEntry = getReferentEntryForObject(env, object);
    if (!referentEntry) goto done;
    // Add the handler to the object's list of cleanup handlers
    LL_PREPEND(referentEntry->cleanupHandlers, l);
    // Register the referent for finalization
    GC_REGISTER_FINALIZER_NO_ORDER(object, _finalizeObject, NULL, NULL, NULL);

done:
    rvmUnlockMutex(&referentsLock);
}
コード例 #21
0
void gnrc_rpl_send(gnrc_pktsnip_t *pkt, kernel_pid_t iface, ipv6_addr_t *src, ipv6_addr_t *dst,
                   ipv6_addr_t *dodag_id)
{
    (void)dodag_id;
    gnrc_pktsnip_t *hdr;
    if (iface == KERNEL_PID_UNDEF) {
        if ((iface = gnrc_ipv6_netif_find_by_addr(NULL, &ipv6_addr_all_rpl_nodes))
            == KERNEL_PID_UNDEF) {
            DEBUG("RPL: no suitable interface found for this destination address\n");
            gnrc_pktbuf_release(pkt);
            return;
        }
    }

    if (src == NULL) {
        src = gnrc_ipv6_netif_match_prefix(iface, &ipv6_addr_link_local_prefix);

        if (src == NULL) {
            DEBUG("RPL: no suitable src address found\n");
            gnrc_pktbuf_release(pkt);
            return;
        }
    }

    if (dst == NULL) {
        dst = (ipv6_addr_t *) &ipv6_addr_all_rpl_nodes;
    }

    hdr = gnrc_ipv6_hdr_build(pkt, src, dst);

    if (hdr == NULL) {
        DEBUG("RPL: Send - no space left in packet buffer\n");
        gnrc_pktbuf_release(pkt);
        return;
    }

    pkt = hdr;

    hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0);
    ((gnrc_netif_hdr_t *)hdr->data)->if_pid = iface;
    LL_PREPEND(pkt, hdr);

    if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_IPV6, GNRC_NETREG_DEMUX_CTX_ALL, pkt)) {
        DEBUG("RPL: cannot send packet: no subscribers found.\n");
        gnrc_pktbuf_release(pkt);
    }
}
コード例 #22
0
ファイル: network_graph.c プロジェクト: atrinik/atrinik
/**
 * Updates all network graph widgets with new data.
 * @param type
 * The network graph type.
 * @param traffic
 * The traffic type (tx/rx).
 * @param bytes
 * Bytes.
 * @note This function is thread-safe.
 */
void network_graph_update(int type, int traffic, size_t bytes)
{
    HARD_ASSERT(type >= 0 && type < NETWORK_GRAPH_TYPE_MAX);
    HARD_ASSERT(traffic >= 0 && traffic < NETWORK_GRAPH_TRAFFIC_MAX);

    if (network_graph_mutex == NULL) {
        return;
    }

    network_graph_work_t *work = ecalloc(1, sizeof(*work));
    work->type = type;
    work->traffic = traffic;
    work->bytes = bytes;

    SDL_LockMutex(network_graph_mutex);
    LL_PREPEND(work_queue, work);
    SDL_UnlockMutex(network_graph_mutex);
}
コード例 #23
0
OCStackResult PDMGetToBeUnlinkedDevices(OCPairList_t **staleDevList, size_t *numOfDevices)
{
    CHECK_PDM_INIT(TAG);
    if (NULL != *staleDevList)
    {
        OC_LOG(ERROR, TAG, "Not null list will cause memory leak");
        return OC_STACK_INVALID_PARAM;
    }

    sqlite3_stmt *stmt = 0;
    int res = 0;
    res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_STALE_INFO,
                              strlen(PDM_SQLITE_GET_STALE_INFO) + 1, &stmt, NULL);
    PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR);

    res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, PDM_STALE_STATE);
    PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR);

    int counter  = 0;
    while (SQLITE_ROW == sqlite3_step(stmt))
    {
        int i1 = sqlite3_column_int(stmt, PDM_FIRST_INDEX);
        int i2 = sqlite3_column_int(stmt, PDM_SECOND_INDEX);
        OicUuid_t temp1 = {{0,}};
        OicUuid_t temp2 = {{0,}};;
        getUUIDforId(i1, &temp1);
        getUUIDforId(i2, &temp2);

        OCPairList_t *tempNode = (OCPairList_t *) OICCalloc(1, sizeof(OCPairList_t));
        if (NULL == tempNode)
        {
            OC_LOG(ERROR, TAG, "No Memory");
            sqlite3_finalize(stmt);
            return OC_STACK_NO_MEMORY;
        }
        memcpy(&tempNode->dev.id, &temp1.id, UUID_LENGTH);
        memcpy(&tempNode->dev2.id, &temp2.id, UUID_LENGTH);
        LL_PREPEND(*staleDevList, tempNode);
        ++counter;
    }
    *numOfDevices = counter;
    sqlite3_finalize(stmt);
    return OC_STACK_OK;
}
コード例 #24
0
ファイル: event_queue.cpp プロジェクト: jharvey/rusefi
/**
 * @return true if inserted into the head of the list
 */
bool EventQueue::insertTask(scheduling_s *scheduling, efitime_t timeX, schfunc_t callback, void *param) {
#if EFI_UNIT_TEST || defined(__DOXYGEN__)
	assertListIsSorted();
#endif /* EFI_UNIT_TEST */
	efiAssert(CUSTOM_ERR_ASSERT, callback != NULL, "NULL callback", false);

// please note that simulator does not use this code at all - simulator uses signal_executor_sleep

	if (scheduling->isScheduled) {
#if EFI_UNIT_TEST || defined(__DOXYGEN__)
		printf("Already scheduled was %d\r\n", (int)scheduling->momentX);
		printf("Already scheduled now %d\r\n", (int)timeX);
#endif /* EFI_UNIT_TEST */
		return false;
	}

	scheduling->momentX = timeX;
	scheduling->callback = callback;
	scheduling->param = param;
	scheduling->isScheduled = true;

	if (head == NULL || timeX < head->momentX) {
		// here we insert into head of the linked list
		LL_PREPEND(head, scheduling);
#if EFI_UNIT_TEST || defined(__DOXYGEN__)
		assertListIsSorted();
#endif /* EFI_UNIT_TEST */
		return true;
	} else {
		// here we know we are not in the head of the list, let's find the position - linear search
		scheduling_s *insertPosition = head;
		while (insertPosition->next != NULL && insertPosition->next->momentX < timeX) {
			insertPosition = insertPosition->next;
		}

		scheduling->next = insertPosition->next;
		insertPosition->next = scheduling;
#if EFI_UNIT_TEST || defined(__DOXYGEN__)
		assertListIsSorted();
#endif /* EFI_UNIT_TEST */
		return false;
	}
}
コード例 #25
0
ファイル: memory.c プロジェクト: tobium/robovm
void rvmRegisterReference(Env* env, Object* reference, Object* referent) {
    if (referent) {
        // Add 'reference' to the references list for 'referent' in the referents hashtable
        rvmLockMutex(&referentsLock);

        ReferenceList* l = rvmAllocateMemory(env, sizeof(ReferenceList));
        if (!l) goto done; // OOM thrown
        l->reference = reference;
        ReferentEntry* referentEntry = getReferentEntryForObject(env, referent);
        if (!referentEntry) goto done;
        // Add the reference to the referent's list of references
        LL_PREPEND(referentEntry->references, l);
        // Register the referent for finalization
        GC_REGISTER_FINALIZER_NO_ORDER(referent, _finalizeObject, NULL, NULL, NULL);

done:
        rvmUnlockMutex(&referentsLock);
    }
}
コード例 #26
0
ファイル: main.c プロジェクト: AdamRLukaitis/RIOT
/* tests sending */
static int test_send(void)
{
    ethernet_hdr_t *exp_mac = (ethernet_hdr_t *)_tmp;
    uint8_t *exp_payload = _tmp + sizeof(ethernet_hdr_t);
    gnrc_pktsnip_t *pkt, *hdr;
    msg_t msg;

    /* prepare packet for sending */
    pkt = gnrc_pktbuf_add(NULL, _TEST_PAYLOAD1, sizeof(_TEST_PAYLOAD1) - 1,
                          GNRC_NETTYPE_UNDEF);
    if (pkt == NULL) {
        puts("Could not allocate send payload");
        return 0;
    }
    hdr = gnrc_netif_hdr_build(NULL, 0, (uint8_t *)_test_dst, sizeof(_test_dst));
    if (hdr == NULL) {
        gnrc_pktbuf_release(pkt);
        puts("Could not allocate send header");
        return 0;
    }
    LL_PREPEND(pkt, hdr);
    /* prepare expected data */
    memcpy(exp_mac->dst, _test_dst, sizeof(_test_dst));
    memcpy(exp_mac->src, _dev_addr, sizeof(_dev_addr));
    exp_mac->type = byteorder_htons(ETHERTYPE_UNKNOWN);
    memcpy(exp_payload, _TEST_PAYLOAD1, sizeof(_TEST_PAYLOAD1) - 1);
    _tmp_len = sizeof(_TEST_PAYLOAD1) + sizeof(ethernet_hdr_t) - 1;
    /* register for returned packet status */
    if (gnrc_neterr_reg(pkt) != 0) {
        puts("Can not register for error reporting");
        return 0;
    }
    /* send packet to MAC layer */
    gnrc_netapi_send(_mac_pid, pkt);
    /* wait for packet status and check */
    msg_receive(&msg);
    if ((msg.type != GNRC_NETERR_MSG_TYPE) ||
        (msg.content.value != GNRC_NETERR_SUCCESS)) {
        puts("Error sending packet");
        return 0;
    }
    return 1;
}
コード例 #27
0
ファイル: gnrc_netreg.c プロジェクト: deepfryed/RIOT
int gnrc_netreg_register(gnrc_nettype_t type, gnrc_netreg_entry_t *entry)
{
#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS)
#ifdef DEVELHELP
    /* only threads with a message queue are allowed to register at gnrc */
    assert((entry->type != GNRC_NETREG_TYPE_DEFAULT) ||
           sched_threads[entry->target.pid]->msg_array);
#endif
#else
    /* only threads with a message queue are allowed to register at gnrc */
    assert(sched_threads[entry->target.pid]->msg_array);
#endif

    if (_INVALID_TYPE(type)) {
        return -EINVAL;
    }

    LL_PREPEND(netreg[type], entry);

    return 0;
}
コード例 #28
0
ファイル: gnrc_ndp_internal.c プロジェクト: khhhh/RIOT
static gnrc_pktsnip_t *_build_headers(kernel_pid_t iface, gnrc_pktsnip_t *payload,
                                      ipv6_addr_t *dst, ipv6_addr_t *src)
{
    gnrc_pktsnip_t *l2hdr;
    gnrc_pktsnip_t *iphdr = gnrc_ipv6_hdr_build(payload, (uint8_t *)src, sizeof(ipv6_addr_t),
                                                (uint8_t *)dst, sizeof(ipv6_addr_t));
    if (iphdr == NULL) {
        DEBUG("ndp internal: error allocating IPv6 header.\n");
        return NULL;
    }
    ((ipv6_hdr_t *)iphdr->data)->hl = 255;
    /* add netif header for send interface specification */
    l2hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0);
    if (l2hdr == NULL) {
        DEBUG("ndp internal: error allocating netif header.\n");
        gnrc_pktbuf_remove_snip(iphdr, iphdr);
        return NULL;
    }
    ((gnrc_netif_hdr_t *)l2hdr->data)->if_pid = iface;
    LL_PREPEND(iphdr, l2hdr);
    return l2hdr;
}
コード例 #29
0
ファイル: bc.c プロジェクト: Zubnix/aura
static Method* loadMethods(Env* env, Class* clazz) {
    ClassInfoHeader* header = lookupClassInfo(env, clazz->name, 
        !clazz->classLoader || !rvmGetParentClassLoader(env, clazz->classLoader) ? _bcBootClassesHash : _bcClassesHash);
    if (!header) return NULL;

    ClassInfo ci;
    jint i;
    void* p = header;
    readClassInfo(&p, &ci);
    
    skipInterfaceNames(&p, &ci);
    skipFieldInfos(&p, &ci);

    Method* first = NULL;
    for (i = 0; i < ci.methodCount; i++) {
        MethodInfo mi;
        readMethodInfo(&p, &mi);
        if (!isStrippedMethod(&mi)) {
            Method* m = NULL;
            if (mi.targetFnPtr) {
                m = (Method*) rvmAllocateBridgeMethod(env, clazz, mi.name, mi.desc, mi.vtableIndex, mi.access, mi.size, mi.impl, mi.synchronizedImpl, mi.targetFnPtr, mi.attributes);
            } else if (mi.callbackImpl) {
                m = (Method*) rvmAllocateCallbackMethod(env, clazz, mi.name, mi.desc, mi.vtableIndex, mi.access, mi.size, mi.impl, mi.synchronizedImpl, mi.linetable, mi.callbackImpl, mi.attributes);
            } else {
                m = rvmAllocateMethod(env, clazz, mi.name, mi.desc, mi.vtableIndex, mi.access, mi.size, mi.impl, mi.synchronizedImpl, mi.linetable, mi.attributes);
            }
            if (!m) goto error;
            LL_PREPEND(first, m);
        }
    }
    return first;
error:
    while (first) {
        Method* next = first->next;
        rvmFreeMemoryUncollectable(env, first);
        first = next;
    }
    return NULL;
}
コード例 #30
-1
/* send a beacon */
void beaconing_send(void)
{
    gnrc_pktsnip_t *pkt, *hdr;
    gnrc_netif_hdr_t *nethdr;

    /* put packet together */
    beacon_t b = { .magic_key = BEACONING_MK, .id = dow_my_id };
    pkt = gnrc_pktbuf_add(NULL, &b, sizeof(b), GNRC_NETTYPE_UNDEF);
    if (pkt == NULL) {
        puts("error: packet buffer full");
        return;
    }
    hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0);
    if (hdr == NULL) {
        puts("error: packet buffer full");
        gnrc_pktbuf_release(pkt);
        return;
    }
    LL_PREPEND(pkt, hdr);
    nethdr = (gnrc_netif_hdr_t *)hdr->data;
    nethdr->flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST;
    /* and send it */
    LOG_DEBUG("beaconing: send beacon\n");
    if (gnrc_netapi_send(CCNLRIOT_NETIF, pkt) < 1) {
        puts("error: unable to send");
        gnrc_pktbuf_release(pkt);
        return;
    }
}