Changeset 493

Show
Ignore:
Timestamp:
04/10/07 11:54:23 (2 years ago)
Author:
plindner
Message:

update clean-whitespace, add automated whitespace test, and clean whitespace (merge from trunk)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/multithreaded/server/assoc.c

    r469 r493  
    6565  is commonly produced by subtraction) look like a single 1-bit 
    6666  difference. 
    67 * the base values were pseudorandom, all zero but one bit set, or  
     67* the base values were pseudorandom, all zero but one bit set, or 
    6868  all zero plus a counter that starts at zero. 
    6969 
     
    7575Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing 
    7676for "differ" defined as + with a one-bit base and a two-bit delta.  I 
    77 used http://burtleburtle.net/bob/hash/avalanche.html to choose  
     77used http://burtleburtle.net/bob/hash/avalanche.html to choose 
    7878the operations, constants, and arrangements of the variables. 
    7979 
     
    114114  is commonly produced by subtraction) look like a single 1-bit 
    115115  difference. 
    116 * the base values were pseudorandom, all zero but one bit set, or  
     116* the base values were pseudorandom, all zero but one bit set, or 
    117117  all zero plus a counter that starts at zero. 
    118118 
     
    138138 
    139139#if HASH_LITTLE_ENDIAN == 1 
    140 uint32_t hash(  
     140uint32_t hash( 
    141141  const void *key,       /* the key to hash */ 
    142142  size_t      length,    /* length of the key */ 
     
    146146  union { const void *ptr; size_t i; } u;     /* needed for Mac Powerbook G4 */ 
    147147 
    148   /* Set up the internal state */   
     148  /* Set up the internal state */ 
    149149  a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; 
    150150 
     
    168168 
    169169    /*----------------------------- handle the last (probably partial) block */ 
    170     /*  
     170    /* 
    171171     * "k[2]&0xffffff" actually reads beyond the end of the string, but 
    172172     * then masks off the part it's not allowed to read.  Because the 
     
    317317 * This is the same as hashword() on big-endian machines.  It is different 
    318318 * from hashlittle() on all machines.  hashbig() takes advantage of 
    319  * big-endian byte ordering.  
     319 * big-endian byte ordering. 
    320320 */ 
    321321uint32_t hash( const void *key, size_t length, const uint32_t initval) 
     
    346346 
    347347    /*----------------------------- handle the last (probably partial) block */ 
    348     /*  
     348    /* 
    349349     * "k[2]<<8" actually reads beyond the end of the string, but 
    350350     * then shifts out the part it's not allowed to read.  Because the 
     
    443443} 
    444444#else // HASH_XXX_ENDIAN == 1 
    445 #error Must define HASH_BIG_ENDIAN or HASH_LITTLE_ENDIAN  
     445#error Must define HASH_BIG_ENDIAN or HASH_LITTLE_ENDIAN 
    446446#endif // hash_XXX_ENDIAN == 1 
    447447 
     
    611611        return; 
    612612    } 
    613     /* Note:  we never actually get here.  the callers don't delete things  
     613    /* Note:  we never actually get here.  the callers don't delete things 
    614614       they can't find. */ 
    615615    assert(*before != 0); 
  • branches/multithreaded/server/configure.ac

    r469 r493  
    103103AC_CHECK_HEADER(malloc.h, AC_DEFINE(HAVE_MALLOC_H,,[do we have malloc.h?])) 
    104104AC_CHECK_MEMBER([struct mallinfo.arena], [ 
    105                AC_DEFINE(HAVE_STRUCT_MALLINFO,,[do we have stuct mallinfo?]) 
    106        ], ,[ 
    107 #      include <malloc.h> 
    108        
     105        AC_DEFINE(HAVE_STRUCT_MALLINFO,,[do we have stuct mallinfo?]) 
     106    ], ,[ 
     107#    include <malloc.h> 
     108   
    109109) 
    110110 
  • branches/multithreaded/server/devtools/clean-whitespace.pl

    r332 r493  
    33use FindBin qw($Bin); 
    44chdir "$Bin/.." or die; 
    5 my @files = (glob("*.h"), glob("*.c")); 
     5my @files = (glob("*.h"), glob("*.c"), glob("*.ac")); 
    66foreach my $f (@files) { 
    77    open(my $fh, $f) or die; 
  • branches/multithreaded/server/items.c

    r490 r493  
    5555 * Generates the variable-sized part of the header for an object. 
    5656 * 
    57  * key     - The key  
     57 * key     - The key 
    5858 * nkey    - The length of the key 
    5959 * flags   - key flags 
     
    7070    return sizeof(item) + nkey + *nsuffix + nbytes; 
    7171} 
    72   
     72 
    7373/*@null@*/ 
    7474item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_time_t exptime, const int nbytes) { 
     
    9393        if (settings.evict_to_free == 0) return NULL; 
    9494 
    95         /*  
    96          * try to get one off the right LRU  
     95        /* 
     96         * try to get one off the right LRU 
    9797         * don't necessariuly unlink the tail because it may be locked: refcount>0 
    9898         * search up from tail an item with refcount==0 and unlink it; give up after 50 
  • branches/multithreaded/server/memcached.c

    r490 r493  
    6262 
    6363/* 
    64  * forward declarations  
     64 * forward declarations 
    6565 */ 
    6666static void drive_machine(conn *c); 
     
    485485            c->isize = ITEM_LIST_INITIAL; 
    486486        } 
    487        /* TODO check error condition? */ 
     487    /* TODO check error condition? */ 
    488488    } 
    489489 
     
    494494            c->msgsize = MSG_LIST_INITIAL; 
    495495        } 
    496        /* TODO check error condition? */ 
     496    /* TODO check error condition? */ 
    497497    } 
    498498 
     
    503503            c->iovsize = IOV_LIST_INITIAL; 
    504504        } 
    505        /* TODO check return value */ 
     505    /* TODO check return value */ 
    506506    } 
    507507} 
     
    755755#define KEY_MAX_LENGTH 250 
    756756 
    757 #define MAX_TOKENS 6  
     757#define MAX_TOKENS 6 
    758758 
    759759/* 
     
    762762 * Returns total number of tokens.  The last valid token is the terminal 
    763763 * token (value points to the first unprocessed character of the string and 
    764  * length zero).   
     764 * length zero). 
    765765 * 
    766766 * Usage example: 
     
    780780    size_t ntokens = 0; 
    781781 
    782     assert(command != NULL && tokens != NULL && max_tokens > 1);  
     782    assert(command != NULL && tokens != NULL && max_tokens > 1); 
    783783 
    784784    cp = command; 
    785785    while(*cp != '\0' && ntokens < max_tokens - 1) { 
    786786        if(*cp == ' ') { 
    787             // If we've accumulated a token, this is the end of it.  
     787            // If we've accumulated a token, this is the end of it. 
    788788            if(length > 0) { 
    789789                tokens[ntokens].value = value; 
     
    943943            return; 
    944944        } 
    945              
     945 
    946946        fd = open("/proc/self/maps", O_RDONLY); 
    947947        if (fd == -1) { 
     
    965965        c->write_and_free = wbuf; 
    966966        c->wcurr = wbuf; 
    967         c->wbytes = res + 5; // Don't write the terminal '\0'  
     967        c->wbytes = res + 5; // Don't write the terminal '\0' 
    968968        conn_set_state(c, conn_write); 
    969969        c->write_and_go = conn_read; 
     
    10781078    do { 
    10791079        while(key_token->length != 0) { 
    1080              
     1080 
    10811081            key = key_token->value; 
    10821082            nkey = key_token->length; 
    1083              
     1083 
    10841084            if(nkey > KEY_MAX_LENGTH) { 
    10851085                out_string(c, "CLIENT_ERROR bad command line format"); 
    10861086                return; 
    10871087            } 
    1088                  
     1088 
    10891089            STATS_LOCK(); 
    10901090            stats.get_cmds++; 
     
    11021102                    } else break; 
    11031103                } 
    1104                      
     1104 
    11051105                /* 
    11061106                 * Construct the response. Each hit adds three elements to the 
     
    11321132                STATS_UNLOCK(); 
    11331133            } 
    1134              
     1134 
    11351135            key_token++; 
    11361136        } 
     
    11441144            key_token = tokens; 
    11451145        } 
    1146          
     1146 
    11471147    } while(key_token->value != NULL); 
    11481148 
    11491149    c->icurr = c->ilist; 
    11501150    c->ileft = i; 
    1151              
     1151 
    11521152    if (settings.verbose > 1) 
    11531153        fprintf(stderr, ">%d END\n", c->sfd); 
    11541154    add_iov(c, "END\r\n", 5); 
    1155          
     1155 
    11561156    if (c->udp && build_udp_headers(c) != 0) { 
    11571157        out_string(c, "SERVER_ERROR out of memory"); 
     
    11851185    exptime = strtol(tokens[3].value, NULL, 10); 
    11861186    vlen = strtol(tokens[4].value, NULL, 10); 
    1187      
     1187 
    11881188    if(errno == ERANGE || ((flags == 0 || exptime == 0) && errno == EINVAL)) { 
    11891189        out_string(c, "CLIENT_ERROR bad command line format"); 
     
    12201220        return; 
    12211221    } 
    1222      
     1222 
    12231223    c->item_comm = comm; 
    12241224    c->item = it; 
     
    12341234    char *key; 
    12351235    size_t nkey; 
    1236      
     1236 
    12371237    assert(c != NULL); 
    12381238 
    1239     if(tokens[KEY_TOKEN].length > KEY_MAX_LENGTH) {  
     1239    if(tokens[KEY_TOKEN].length > KEY_MAX_LENGTH) { 
    12401240        out_string(c, "CLIENT_ERROR bad command line format"); 
    12411241        return; 
     
    12441244    key = tokens[KEY_TOKEN].value; 
    12451245    nkey = tokens[KEY_TOKEN].length; 
    1246          
     1246 
    12471247    if (settings.managed) { 
    12481248        int bucket = c->bucket; 
     
    12591259 
    12601260    delta = strtoul(tokens[2].value, NULL, 10); 
    1261          
     1261 
    12621262    if(errno == ERANGE) { 
    12631263        out_string(c, "CLIENT_ERROR bad command line format"); 
     
    12821282 * delta amount to adjust value by 
    12831283 * buf   buffer for response string 
    1284  *  
     1284 * 
    12851285 * returns a response string to send back to the client. 
    12861286 */ 
     
    12921292    ptr = ITEM_data(it); 
    12931293    while ((*ptr != '\0') && (*ptr < '0' && *ptr > '9')) ptr++;    // BUG: can't be true 
    1294          
     1294 
    12951295    value = strtol(ptr, NULL, 10); 
    12961296 
     
    13301330    item *it; 
    13311331    time_t exptime = 0; 
    1332      
     1332 
    13331333    assert(c != NULL); 
    13341334 
     
    13451345        } 
    13461346    } 
    1347      
     1347 
    13481348    key = tokens[KEY_TOKEN].value; 
    13491349    nkey = tokens[KEY_TOKEN].length; 
     
    13561356    if(ntokens == 4) { 
    13571357        exptime = strtol(tokens[2].value, NULL, 10); 
    1358          
     1358 
    13591359        if(errno == ERANGE) { 
    13601360            out_string(c, "CLIENT_ERROR bad command line format"); 
     
    13941394            todelete = new_delete; 
    13951395            deltotal *= 2; 
    1396         } else {  
    1397             /*  
     1396        } else { 
     1397            /* 
    13981398             * can't delete it immediately, user wants a delay, 
    13991399             * but we ran out of memory for the delete queue 
     
    14031403        } 
    14041404    } 
    1405      
     1405 
    14061406    /* use its expiration time as its deletion time now */ 
    14071407    it->exptime = realtime(exptime); 
     
    14131413 
    14141414static void process_command(conn *c, char *command) { 
    1415      
     1415 
    14161416    token_t tokens[MAX_TOKENS]; 
    14171417    size_t ntokens; 
     
    14231423        fprintf(stderr, "<%d %s\n", c->sfd, command); 
    14241424 
    1425     /*  
     1425    /* 
    14261426     * for commands set/add/replace, we build an item and read the data 
    14271427     * directly into it, then continue in nread_complete(). 
    1428      */  
    1429      
     1428     */ 
     1429 
    14301430    c->msgcurr = 0; 
    14311431    c->msgused = 0; 
     
    14411441        ((strcmp(tokens[COMMAND_TOKEN].value, "get") == 0) || 
    14421442         (strcmp(tokens[COMMAND_TOKEN].value, "bget") == 0))) { 
    1443          
     1443 
    14441444        process_get_command(c, tokens, ntokens); 
    14451445 
    1446     } else if (ntokens == 6 &&  
    1447                ((strcmp(tokens[COMMAND_TOKEN].value, "add") == 0 && (comm = NREAD_ADD)) ||  
     1446    } else if (ntokens == 6 && 
     1447               ((strcmp(tokens[COMMAND_TOKEN].value, "add") == 0 && (comm = NREAD_ADD)) || 
    14481448                (strcmp(tokens[COMMAND_TOKEN].value, "set") == 0 && (comm = NREAD_SET)) || 
    14491449                (strcmp(tokens[COMMAND_TOKEN].value, "replace") == 0 && (comm = NREAD_REPLACE)))) { 
    1450          
     1450 
    14511451        process_update_command(c, tokens, ntokens, comm); 
    14521452 
     
    14691469            return; 
    14701470        } 
    1471          
     1471 
    14721472        if (sscanf(tokens[1].value, "%u:%u", &bucket,&gen) == 2) { 
    14731473            if ((bucket < 0) || (bucket >= MAX_BUCKETS)) { 
     
    15251525 
    15261526    } else if (ntokens >= 2 && (strcmp(tokens[COMMAND_TOKEN].value, "stats") == 0)) { 
    1527          
     1527 
    15281528        process_stat(c, tokens, ntokens); 
    15291529 
     
    15491549        out_string(c, "OK"); 
    15501550        return; 
    1551   
     1551 
    15521552    } else if (ntokens == 2 && (strcmp(tokens[COMMAND_TOKEN].value, "version") == 0)) { 
    15531553 
     
    15571557 
    15581558        conn_set_state(c, conn_closing); 
    1559          
     1559 
    15601560    } else if (ntokens == 5 && (strcmp(tokens[COMMAND_TOKEN].value, "slabs") == 0 && 
    15611561                                strcmp(tokens[COMMAND_TOKEN + 1].value, "reassign") == 0)) { 
     
    27072707    } 
    27082708    /* create the initial listening connection */ 
    2709     if (!(listen_conn = conn_new(l_socket, conn_listening,  
     2709    if (!(listen_conn = conn_new(l_socket, conn_listening, 
    27102710                                 EV_READ | EV_PERSIST, 1, false, main_base))) { 
    27112711        fprintf(stderr, "failed to create listening connection"); 
  • branches/multithreaded/server/slabs.c

    r490 r493  
    7474 * a given size. 
    7575 * 
    76  * Given object size, return id to use when allocating/freeing memory for object  
    77  * 0 means error: can't store such a large object  
     76 * Given object size, return id to use when allocating/freeing memory for object 
     77 * 0 means error: can't store such a large object 
    7878 */ 
    7979 
  • branches/multithreaded/server/slabs.h

    r469 r493  
    77 
    88 
    9 /*   
     9/* 
    1010 * Given object size, return id to use when allocating/freeing memory for object 
    1111 * 0 means error: can't store such a large object 
  • branches/multithreaded/server/stats.c

    r462 r493  
    128128void stats_prefix_record_delete(char *key) { 
    129129    PREFIX_STATS *pfs; 
    130      
     130 
    131131    STATS_LOCK(); 
    132132    pfs = stats_prefix_find(key); 
     
    142142void stats_prefix_record_set(char *key) { 
    143143    PREFIX_STATS *pfs; 
    144      
     144 
    145145    STATS_LOCK(); 
    146146    pfs = stats_prefix_find(key); 
     
    182182    for (i = 0; i < PREFIX_HASH_SIZE; i++) { 
    183183        for (pfs = prefix_stats[i]; NULL != pfs; pfs = pfs->next) { 
    184             pos += sprintf(buf + pos, format,  
     184            pos += sprintf(buf + pos, format, 
    185185                           pfs->prefix, pfs->num_gets, pfs->num_hits, 
    186186                           pfs->num_sets, pfs->num_deletes); 
    187187        } 
    188188    } 
    189      
     189 
    190190    STATS_UNLOCK(); 
    191191    strcpy(buf + pos, "END\r\n"); 
  • branches/multithreaded/server/thread.c

    r461 r493  
    302302 
    303303    if (item = cq_peek(&me->new_conn_queue)) { 
    304        conn *c = conn_new(item->sfd, item->init_state, item->event_flags, 
    305                           item->read_buffer_size, item->is_udp, me->base); 
    306        if (!c) { 
    307            if (item->is_udp) { 
    308                fprintf(stderr, "Can't listen for events on UDP socket\n"); 
    309                exit(1); 
     304    conn *c = conn_new(item->sfd, item->init_state, item->event_flags, 
     305                       item->read_buffer_size, item->is_udp, me->base); 
     306    if (!c) { 
     307        if (item->is_udp) { 
     308            fprintf(stderr, "Can't listen for events on UDP socket\n"); 
     309            exit(1); 
    310310            } 
    311            else { 
    312                if (settings.verbose > 0) { 
    313                    fprintf(stderr, "Can't listen for events on fd %d\n", 
    314                            item->sfd); 
    315                
    316                close(item->sfd); 
    317            } 
    318        
     311        else { 
     312        if (settings.verbose > 0) { 
     313                fprintf(stderr, "Can't listen for events on fd %d\n", 
     314                    item->sfd); 
     315       
     316        close(item->sfd); 
     317        } 
     318   
    319319        cqi_free(item); 
    320320    } 
     
    595595        threads[i].notify_send_fd = fds[1]; 
    596596 
    597        setup_thread(&threads[i]); 
     597    setup_thread(&threads[i]); 
    598598    } 
    599599