Skip to content

Commit

Permalink
squashed warnings in memcached
Browse files Browse the repository at this point in the history
Summary: - added -Wall to compile flags and squashed most warnings.
         - updated header files with #ifdef ... #endif

Reviewed By: sgrimm

Test Plan: test/stats.py passes
           
           libmcc/test/test.py -a passes with --enable-threads and without --enable-threads

Revert: OK
  • Loading branch information
ttung committed Oct 31, 2007
1 parent cdaee72 commit 273d051
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Expand Up @@ -2,6 +2,7 @@ bin_PROGRAMS = memcached memcached-debug

memcached_SOURCES = memcached.c slabs.c slabs.h items.c items.h assoc.c assoc.h memcached.h thread.c stats.c stats.h binary_sm.c binary_sm.h binary_protocol.h
memcached_debug_SOURCES = $(memcached_SOURCES)
memcached_CFLAGS = -Wall
memcached_CPPFLAGS = -DNDEBUG
memcached_LDADD = @LIBOBJS@
memcached_debug_LDADD = $(memcached_LDADD)
Expand Down
5 changes: 5 additions & 0 deletions src/assoc.h
@@ -1,7 +1,12 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#if !defined(_assoc_h_)
#define _assoc_h_
/* associative array */
void assoc_init(void);
item *assoc_find(const char *key, const size_t nkey);
int assoc_insert(item *item);
void assoc_delete(const char *key, const size_t nkey);
void do_assoc_move_next_bucket(void);
uint32_t hash( const void *key, size_t length, const uint32_t initval);
int do_assoc_expire_regex(char *pattern);
#endif /* #if !defined(_assoc_h_) */
6 changes: 3 additions & 3 deletions src/binary_protocol.h
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#if !defined(_facebook_memcache_binary_protocol_h_)
#define _facebook_memcache_binary_protocol_h_
#if !defined(_memcache_binary_protocol_h_)
#define _memcache_binary_protocol_h_

#include <stdint.h>

Expand Down Expand Up @@ -183,4 +183,4 @@ typedef struct string_rep_s {
// string goes here.
} string_rep_t;

#endif /* #if !defined(_facebook_memcache_binary_protocol_h_) */
#endif /* #if !defined(_memcache_binary_protocol_h_) */
6 changes: 3 additions & 3 deletions src/binary_sm.h
@@ -1,11 +1,11 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */

#if !defined(_facebook_binary_sm_h_)
#define _facebook_binary_sm_h_
#if !defined(_binary_sm_h_)
#define _binary_sm_h_

#include "memcached.h"

extern void process_binary_protocol(conn* c);
extern bp_hdr_pool_t* bp_allocate_hdr_pool(bp_hdr_pool_t* next);

#endif /* #if !defined(_facebook_binary_sm_h_) */
#endif /* #if !defined(_binary_sm_h_) */
6 changes: 4 additions & 2 deletions src/items.c
@@ -1,6 +1,5 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* $Id$ */
#include "memcached.h"
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/signal.h>
Expand All @@ -14,6 +13,9 @@
#include <time.h>
#include <assert.h>

#include "memcached.h"
#include "slabs.h"

/* Forward Declarations */
static void item_link_q(item *it);
static void item_unlink_q(item *it);
Expand Down Expand Up @@ -282,7 +284,7 @@ void do_item_update(item *it) {
if (it->time < current_time - ITEM_UPDATE_INTERVAL) {
assert((it->it_flags & ITEM_SLABBED) == 0);

if (it->it_flags & ITEM_LINKED != 0) {
if ((it->it_flags & ITEM_LINKED) != 0) {
item_unlink_q(it);
it->time = current_time;
item_link_q(it);
Expand Down
30 changes: 18 additions & 12 deletions src/memcached.c
Expand Up @@ -60,6 +60,12 @@
#endif
#endif

#if __WORDSIZE == 64
#define PRINTF_INT64_MODIFIER "l"
#else
#define PRINTF_INT64_MODIFIER "ll"
#endif

/*
* forward declarations
*/
Expand Down Expand Up @@ -916,26 +922,26 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
pos += sprintf(pos, "STAT uptime %u\r\n", now);
pos += sprintf(pos, "STAT time %ld\r\n", now + stats.started);
pos += sprintf(pos, "STAT version " VERSION "\r\n");
pos += sprintf(pos, "STAT pointer_size %d\r\n", 8 * sizeof(void *));
pos += sprintf(pos, "STAT pointer_size %lu\r\n", 8 * sizeof(void *));
#ifndef WIN32
pos += sprintf(pos, "STAT rusage_user %ld.%06ld\r\n", usage.ru_utime.tv_sec, usage.ru_utime.tv_usec);
pos += sprintf(pos, "STAT rusage_system %ld.%06ld\r\n", usage.ru_stime.tv_sec, usage.ru_stime.tv_usec);
pos += sprintf(pos, "STAT rusage_user %ld.%06d\r\n", usage.ru_utime.tv_sec, (int) usage.ru_utime.tv_usec);
pos += sprintf(pos, "STAT rusage_system %ld.%06d\r\n", usage.ru_stime.tv_sec, (int) usage.ru_stime.tv_usec);
#endif /* !WIN32 */
pos += sprintf(pos, "STAT curr_items %u\r\n", stats.curr_items);
pos += sprintf(pos, "STAT total_items %u\r\n", stats.total_items);
pos += sprintf(pos, "STAT bytes %llu\r\n", stats.curr_bytes);
pos += sprintf(pos, "STAT bytes %" PRINTF_INT64_MODIFIER "u\r\n", stats.curr_bytes);
pos += sprintf(pos, "STAT curr_connections %u\r\n", stats.curr_conns - 1); /* ignore listening conn */
pos += sprintf(pos, "STAT total_connections %u\r\n", stats.total_conns);
pos += sprintf(pos, "STAT connection_structures %u\r\n", stats.conn_structs);
pos += sprintf(pos, "STAT cmd_get %llu\r\n", stats.get_cmds);
pos += sprintf(pos, "STAT cmd_set %llu\r\n", stats.set_cmds);
pos += sprintf(pos, "STAT get_hits %llu\r\n", stats.get_hits);
pos += sprintf(pos, "STAT get_misses %llu\r\n", stats.get_misses);
pos += sprintf(pos, "STAT cmd_get %" PRINTF_INT64_MODIFIER "u\r\n", stats.get_cmds);
pos += sprintf(pos, "STAT cmd_set %" PRINTF_INT64_MODIFIER "u\r\n", stats.set_cmds);
pos += sprintf(pos, "STAT get_hits %" PRINTF_INT64_MODIFIER "u\r\n", stats.get_hits);
pos += sprintf(pos, "STAT get_misses %" PRINTF_INT64_MODIFIER "u\r\n", stats.get_misses);
pos += sprintf(pos, "STAT hit_rate %g%%\r\n", (stats.get_hits + stats.get_misses) == 0 ? 0.0 : (double)stats.get_hits * 100 / (stats.get_hits + stats.get_misses));
pos += sprintf(pos, "STAT evictions %llu\r\n", stats.evictions);
pos += sprintf(pos, "STAT bytes_read %llu\r\n", stats.bytes_read);
pos += sprintf(pos, "STAT bytes_written %llu\r\n", stats.bytes_written);
pos += sprintf(pos, "STAT limit_maxbytes %llu\r\n", (uint64_t) settings.maxbytes);
pos += sprintf(pos, "STAT evictions %" PRINTF_INT64_MODIFIER "u\r\n", stats.evictions);
pos += sprintf(pos, "STAT bytes_read %" PRINTF_INT64_MODIFIER "u\r\n", stats.bytes_read);
pos += sprintf(pos, "STAT bytes_written %" PRINTF_INT64_MODIFIER "u\r\n", stats.bytes_written);
pos += sprintf(pos, "STAT limit_maxbytes %" PRINTF_INT64_MODIFIER "u\r\n", (uint64_t) settings.maxbytes);
pos += sprintf(pos, "STAT threads %u\r\n", settings.num_threads);
pos += sprintf(pos, "STAT slabs_rebalance %d\r\n", slabs_get_rebalance_interval());
pos += sprintf(pos, "END");
Expand Down
5 changes: 4 additions & 1 deletion src/memcached.h
Expand Up @@ -309,11 +309,14 @@ void do_run_deferred_deletes(void);
char *do_add_delta(item *item, int incr, const unsigned int delta, char *buf, uint32_t* res_val);
int do_store_item(item *item, int comm);
conn *conn_new(const int sfd, const int init_state, const int event_flags, const int read_buffer_size, const bool is_udp, const bool is_binary, struct event_base *base);
void conn_cleanup(conn *c);
void conn_close(conn *c);
void accept_new_conns(const bool do_accept, const bool is_binary);
bool update_event(conn *c, const int new_flags);
int add_iov(conn *c, const void *buf, int len, bool is_start);
int add_msghdr(conn *c);
rel_time_t realtime(const time_t exptime);
int build_udp_headers(conn *c);

#include "stats.h"
#include "slabs.h"
Expand Down Expand Up @@ -429,7 +432,7 @@ int mt_store_item(item *item, int comm);
# define slabs_rebalance() do_slabs_rebalance()
# define slabs_stats(x) do_slabs_stats(x)
# define store_item(x,y) do_store_item(x,y)
# define thread_init(x,y) 0
# define thread_init(x,y) ;

# define STATS_LOCK() /**/
# define STATS_UNLOCK() /**/
Expand Down
11 changes: 10 additions & 1 deletion src/slabs.h
@@ -1,3 +1,8 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */

#if !defined(_slabs_h_)
#define _slabs_h_

/* slabs memory allocation */

/** Init the subsystem. 1st argument is the limit on no. of bytes to allocate,
Expand Down Expand Up @@ -28,12 +33,16 @@ char* do_slabs_stats(int *buflen);
-1 = tried. busy. send again shortly. */
int do_slabs_reassign(unsigned char srcid, unsigned char dstid);

void slabs_add_hit(void *it, int unique);
void slabs_add_eviction(unsigned int clsid);

/* Find the worst performed slab class to free one slab from it and
assign it to the best performed slab class. */
void do_slab_rebalance();
void do_slabs_rebalance();

/* 0 to turn off rebalance_interval; otherwise, this number is in seconds.
* These two functions are actually implemented in items.c.
*/
void slabs_set_rebalance_interval(int interval);
int slabs_get_rebalance_interval();
#endif /* #if !defined(_slabs_h_) */
21 changes: 15 additions & 6 deletions src/stats.h
@@ -1,8 +1,17 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */

#if !defined(_stats_h_)
#define _stats_h

/* stats */
void stats_prefix_init(void);
void stats_prefix_clear(void);
void stats_prefix_record_get(const char *key, const bool is_hit);
void stats_prefix_record_delete(const char *key);
void stats_prefix_record_set(const char *key);
extern void stats_prefix_init(void);
extern void stats_prefix_clear(void);
extern void stats_prefix_record_get(const char *key, const bool is_hit);
extern void stats_prefix_record_delete(const char *key);
extern void stats_prefix_record_set(const char *key);
extern void stats_prefix_record_byte_total_change(char *key, long bytes);
extern void stats_prefix_record_removal(char *key, size_t bytes, rel_time_t time, long flags);

/*@null@*/
char *stats_prefix_dump(int *length);
extern char *stats_prefix_dump(int *length);
#endif /* #if !defined(_stats_h_) */
2 changes: 1 addition & 1 deletion src/thread.c
Expand Up @@ -289,7 +289,7 @@ static void *worker_libevent(void *arg) {
pthread_cond_signal(&init_cond);
pthread_mutex_unlock(&init_lock);

return (void*) event_base_loop(me->base, 0);
return (void*) (intptr_t) event_base_loop(me->base, 0);
}


Expand Down

0 comments on commit 273d051

Please sign in to comment.