示例#1
0
static dwarf_reg_state_t *
rs_lookup (struct dwarf_rs_cache *cache, struct dwarf_cursor *c)
{
    dwarf_reg_state_t *rs = cache->buckets + c->hint;
    unsigned short index;
    unw_word_t ip;

    ip = c->ip;

    if (cache_match (rs, ip))
        return rs;

    index = cache->hash[hash (ip)];
    if (index >= DWARF_UNW_CACHE_SIZE)
        return NULL;

    rs = cache->buckets + index;
    while (1)
    {
        if (cache_match (rs, ip))
        {
            /* update hint; no locking needed: single-word writes are atomic */
            c->hint = cache->buckets[c->prev_rs].hint =
                          (rs - cache->buckets);
            return rs;
        }
        if (rs->coll_chain >= DWARF_UNW_HASH_SIZE)
            return NULL;
        rs = cache->buckets + rs->coll_chain;
    }
}
示例#2
0
static struct ia64_script *
script_lookup (struct ia64_script_cache *cache, struct cursor *c)
{
    struct ia64_script *script = cache->buckets + c->hint;
    unsigned short index;
    unw_word_t ip, pr;

    ip = c->ip;
    pr = c->pr;

    if (cache_match (script, ip, pr))
        return script;

    index = cache->hash[hash (ip)];
    if (index >= IA64_UNW_CACHE_SIZE)
        return 0;

    script = cache->buckets + index;
    while (1)
    {
        if (cache_match (script, ip, pr))
        {
            /* update hint; no locking needed: single-word writes are atomic */
            c->hint = cache->buckets[c->prev_script].hint =
                          (script - cache->buckets);
            return script;
        }
        if (script->coll_chain >= IA64_UNW_HASH_SIZE)
            return 0;
        script = cache->buckets + script->coll_chain;
    }
}
示例#3
0
文件: gf.c 项目: cshen/julia
static jl_function_t *jl_method_table_assoc_exact(jl_methtable_t *mt,
                                                  jl_value_t **args, size_t n)
{
    jl_methlist_t *ml = NULL;
    if (n > 0) {
        jl_value_t *a0 = args[0];
        jl_value_t *ty = (jl_value_t*)jl_typeof(a0);
        uptrint_t uid;
        if ((ty == (jl_value_t*)jl_struct_kind && (uid = ((jl_struct_type_t*)a0)->uid)) ||
            (ty == (jl_value_t*)jl_bits_kind   && (uid = ((jl_bits_type_t*)a0)->uid))) {
            if (mt->cache_targ &&
                uid < jl_array_len(mt->cache_targ)) {
                ml = (jl_methlist_t*)jl_cellref(mt->cache_targ, uid);
                if (ml)
                    goto mt_assoc_lkup;
            }
        }
        if ((jl_is_struct_type(ty) && (uid = ((jl_struct_type_t*)ty)->uid)) ||
            (jl_is_bits_type(ty)   && (uid = ((jl_bits_type_t*)ty)->uid))) {
            if (mt->cache_arg1 &&
                uid < jl_array_len(mt->cache_arg1)) {
                ml = (jl_methlist_t*)jl_cellref(mt->cache_arg1, uid);
                if (ml) {
                    if (ml->next==NULL && n==1 && ml->sig->length==1)
                        return ml->func;
                    if (n==2) {
                        // some manually-unrolled common special cases
                        jl_value_t *a1 = args[1];
                        jl_methlist_t *mn = ml;
                        if (mn->sig->length==2 &&
                            jl_tupleref(mn->sig,1)==(jl_value_t*)jl_typeof(a1))
                            return mn->func;
                        mn = mn->next;
                        if (mn && mn->sig->length==2 &&
                            jl_tupleref(mn->sig,1)==(jl_value_t*)jl_typeof(a1))
                            return mn->func;
                    }
                }
            }
        }
    }
    if (ml == NULL)
        ml = mt->cache;
 mt_assoc_lkup:
    while (ml != NULL) {
        if (((jl_tuple_t*)ml->sig)->length == n || ml->va==jl_true) {
            if (cache_match(args, n, (jl_tuple_t*)ml->sig, ml->va==jl_true)) {
                return ml->func;
            }
        }
        ml = ml->next;
    }
    return NULL;
}
示例#4
0
/*
 * handle HTTP request/response transaction of a thread
 * clinet-----(request)----->server
 *       <------(data)-------
 */
void *doit(void *connfd) {
    int fd = *(int *)connfd;
    int fd_server;
    /* detach thread */
    Pthread_detach(pthread_self());

    rio_t rio;
    char buf[MAXLINE], object_buf[MAX_OBJECT_SIZE];
    char method[MAXLINE], uri[MAXLINE], version[MAXLINE];

    /* uri info */
    char host[MAXLINE];
    int port;
    char filename[MAXLINE];

    /* Read request line and headers */
    Rio_readinitb(&rio, fd);
    Rio_readlineb(&rio, buf, MAXLINE);
    sscanf(buf, "%s %s %s", method, uri, version);

    /* request method is not GET */
    if (strcmp(method, "GET")) {
        printerror(fd, method, "501", "Not Implemented",
            "tianqiw's proxy does not implement this method");
        Close(fd);
        return NULL;
    }

    /* request method is GET
     * look for the object in cache */
    cache_block *block = cache_match(cache_ptr, uri);

    if (block != NULL) {
        /* cache hit */
        Rio_writen(fd, block->object, block->object_size);
    }
    else {
        /* cache miss */
        parse_uri(uri, host, &port, filename);

        /* construct the request header */
        char request_buf[MAXLINE];
        requestHdr(&rio, request_buf, host, filename);

        /* send request to server */
        if ((fd_server = open_clientfd_r(host, port)) < 0) {
            /* server connection error */
            char longmsg[MAXBUF];
            sprintf(longmsg, "Cannot open connection to server at <%s, %d>", host, port);
            printerror(fd, "Connection Failed", "404", "Not Found", longmsg);
            Close(fd);
            return NULL;
        }

        /* reset rio for server use */
        memset(&rio, 0, sizeof(rio_t));
        Rio_readinitb(&rio, fd_server);
        Rio_writen(fd_server, request_buf, strlen(request_buf));

        /* get data from server and send to client */
        size_t object_size = 0;
        size_t buflen;
        int is_exceed = 0;

        while ((buflen = Rio_readlineb(&rio, buf, MAXLINE))) {
            Rio_writen(fd, buf, buflen);

            /* size of the buffer exceeds the max object size
             * discard the buffer */
            if ((object_size + buflen) > MAX_OBJECT_SIZE) {
                is_exceed = 1;
            }
            else {
                memcpy(object_buf + object_size, buf, buflen);
                object_size += buflen;
            }
        }

        /* if not exceed the max object size, insert to cache */
        if (!is_exceed) {
            cache_insert(cache_ptr, uri, object_buf, object_size);
        }

        /* clear the buffer */
        Close(fd_server);
    }

    Close(fd);
    return NULL;
}