diff options
-rwxr-xr-x | dist/s_prototypes | 2 | ||||
-rw-r--r-- | dist/s_string.ok | 1 | ||||
-rwxr-xr-x[-rw-r--r--] | dist/s_typedef | 5 | ||||
-rw-r--r-- | src/btree/bt_debug.c | 2 | ||||
-rw-r--r-- | src/include/btmem.h | 8 | ||||
-rw-r--r-- | src/include/extern.h | 18 | ||||
-rw-r--r-- | src/include/gcc.h | 8 | ||||
-rw-r--r-- | src/include/log.h | 4 | ||||
-rw-r--r-- | src/include/lsm.h | 4 | ||||
-rw-r--r-- | src/include/msvc.h | 15 | ||||
-rw-r--r-- | src/include/mutex.h | 8 | ||||
-rw-r--r-- | src/include/session.h | 4 | ||||
-rw-r--r-- | src/include/txn.h | 4 |
13 files changed, 53 insertions, 30 deletions
diff --git a/dist/s_prototypes b/dist/s_prototypes index f29b96a1f55..603c0f5633d 100755 --- a/dist/s_prototypes +++ b/dist/s_prototypes @@ -31,7 +31,7 @@ for i in `sed -e '/^[a-z]/!d' filelist`; do -e 's/\* /\*/g' \ -e 's/ */ /g' \ -e 's/^/extern /' \ - -e 's/WT_GCC_FUNC_/WT_GCC_/' \ + -e 's/WT_GCC_FUNC_/WT_GCC_FUNC_DECL_/' \ -e 's/$/;/p' \ < ../$i done) > $t diff --git a/dist/s_string.ok b/dist/s_string.ok index cea96db2848..1658684313c 100644 --- a/dist/s_string.ok +++ b/dist/s_string.ok @@ -881,6 +881,7 @@ poptable pos posint posix +pragmas pre prealloc preload diff --git a/dist/s_typedef b/dist/s_typedef index 6b230223baa..ed37f940933 100644..100755 --- a/dist/s_typedef +++ b/dist/s_typedef @@ -20,7 +20,10 @@ build() { l=`ls ../src/include/*.[hi] ../src/include/*.in | sed -e '/wiredtiger.*/d' -e '/queue.h/d'` - egrep -h '^[ ]*(struct|union)[ ]*__.*[ ]*{' $l | \ + egrep -h '^[ ]*(((struct|union)[ ]*(WT_COMPILER_TYPE_ALIGN\(.*\)[ ]*)?__.*[ ]*{)|(WT_PACKED_STRUCT_BEGIN.*))' $l | \ + egrep -v '(#define|__attribute)' | + sed -e 's/WT_PACKED_STRUCT_BEGIN(\(.*\))/struct \1 {/' | + sed -e 's/WT_COMPILER_TYPE_ALIGN(.*)[ ]*//' | sed -e 's/^[ ]*//' -e 's/[ ]*{.*//' | sort | \ while read t n; do upper=`echo $n | sed -e 's/^__//' | tr [a-z] [A-Z]` diff --git a/src/btree/bt_debug.c b/src/btree/bt_debug.c index af9f6a669f2..5a3342e62a9 100644 --- a/src/btree/bt_debug.c +++ b/src/btree/bt_debug.c @@ -48,7 +48,7 @@ static void __debug_row_skip(WT_DBG *, WT_INSERT_HEAD *); static int __debug_tree(WT_SESSION_IMPL *, WT_PAGE *, const char *, uint32_t); static void __debug_update(WT_DBG *, WT_UPDATE *, int); static void __dmsg(WT_DBG *, const char *, ...) - WT_GCC_ATTRIBUTE((format (printf, 2, 3))); + WT_GCC_FUNC_DECL_ATTRIBUTE((format (printf, 2, 3))); static void __dmsg_wrapup(WT_DBG *); /* diff --git a/src/include/btmem.h b/src/include/btmem.h index aea9ee98742..176d4733f7d 100644 --- a/src/include/btmem.h +++ b/src/include/btmem.h @@ -759,11 +759,11 @@ struct __wt_col { * with RLE counts greater than 1 when reading the page. We can do a binary * search in this array, then an offset calculation to find the cell. */ -struct __wt_col_rle { +WT_PACKED_STRUCT_BEGIN(__wt_col_rle) uint64_t recno; /* Record number of first repeat. */ uint64_t rle; /* Repeat count. */ uint32_t indx; /* Slot of entry in col_var.d */ -} WT_GCC_ATTRIBUTE((packed)); +WT_PACKED_STRUCT_END /* * WT_COL_PTR, WT_COL_PTR_SET -- @@ -827,7 +827,7 @@ struct __wt_ikey { * is done for an entry, WT_UPDATE structures are formed into a forward-linked * list. */ -struct __wt_update { +WT_PACKED_STRUCT_BEGIN(__wt_update) uint64_t txnid; /* update transaction */ WT_UPDATE *next; /* forward-linked list */ @@ -846,7 +846,7 @@ struct __wt_update { /* The untyped value immediately follows the WT_UPDATE structure. */ #define WT_UPDATE_DATA(upd) \ ((void *)((uint8_t *)(upd) + sizeof(WT_UPDATE))) -} WT_GCC_ATTRIBUTE((packed)); +}; /* * WT_INSERT -- diff --git a/src/include/extern.h b/src/include/extern.h index 71ed9656656..e47f4ba09c0 100644 --- a/src/include/extern.h +++ b/src/include/extern.h @@ -423,7 +423,7 @@ extern int __wt_meta_track_handle_lock(WT_SESSION_IMPL *session, int created); extern int __wt_turtle_init(WT_SESSION_IMPL *session); extern int __wt_turtle_read(WT_SESSION_IMPL *session, const char *key, char **valuep); extern int __wt_turtle_update( WT_SESSION_IMPL *session, const char *key, const char *value); -extern void __wt_abort(WT_SESSION_IMPL *session) WT_GCC_ATTRIBUTE((noreturn)); +extern void __wt_abort(WT_SESSION_IMPL *session) WT_GCC_FUNC_DECL_ATTRIBUTE((noreturn)); extern int __wt_calloc(WT_SESSION_IMPL *session, size_t number, size_t size, void *retp); extern int __wt_realloc(WT_SESSION_IMPL *session, size_t *bytes_allocated_ret, size_t bytes_to_allocate, void *retp); extern int __wt_realloc_aligned(WT_SESSION_IMPL *session, size_t *bytes_allocated_ret, size_t bytes_to_allocate, void *retp); @@ -567,13 +567,13 @@ extern uint32_t __wt_cksum(const void *chunk, size_t len); extern void __wt_cksum_init(void); extern void __wt_event_handler_set(WT_SESSION_IMPL *session, WT_EVENT_HANDLER *handler); extern int __wt_eventv(WT_SESSION_IMPL *session, int msg_event, int error, const char *file_name, int line_number, const char *fmt, va_list ap); -extern void __wt_err(WT_SESSION_IMPL *session, int error, const char *fmt, ...) WT_GCC_ATTRIBUTE((format (printf, 3, 4))); -extern void __wt_errx(WT_SESSION_IMPL *session, const char *fmt, ...) WT_GCC_ATTRIBUTE((format (printf, 2, 3))); -extern int __wt_ext_err_printf( WT_EXTENSION_API *wt_api, WT_SESSION *wt_session, const char *fmt, ...) WT_GCC_ATTRIBUTE((format (printf, 3, 4))); -extern int __wt_msg(WT_SESSION_IMPL *session, const char *fmt, ...) WT_GCC_ATTRIBUTE((format (printf, 2, 3))); -extern int __wt_ext_msg_printf( WT_EXTENSION_API *wt_api, WT_SESSION *wt_session, const char *fmt, ...) WT_GCC_ATTRIBUTE((format (printf, 3, 4))); +extern void __wt_err(WT_SESSION_IMPL *session, int error, const char *fmt, ...) WT_GCC_FUNC_DECL_ATTRIBUTE((format (printf, 3, 4))); +extern void __wt_errx(WT_SESSION_IMPL *session, const char *fmt, ...) WT_GCC_FUNC_DECL_ATTRIBUTE((format (printf, 2, 3))); +extern int __wt_ext_err_printf( WT_EXTENSION_API *wt_api, WT_SESSION *wt_session, const char *fmt, ...) WT_GCC_FUNC_DECL_ATTRIBUTE((format (printf, 3, 4))); +extern int __wt_msg(WT_SESSION_IMPL *session, const char *fmt, ...) WT_GCC_FUNC_DECL_ATTRIBUTE((format (printf, 2, 3))); +extern int __wt_ext_msg_printf( WT_EXTENSION_API *wt_api, WT_SESSION *wt_session, const char *fmt, ...) WT_GCC_FUNC_DECL_ATTRIBUTE((format (printf, 3, 4))); extern int __wt_progress(WT_SESSION_IMPL *session, const char *s, uint64_t v); -extern void __wt_assert(WT_SESSION_IMPL *session, int error, const char *file_name, int line_number, const char *fmt, ...) WT_GCC_ATTRIBUTE((format (printf, 5, 6))); +extern void __wt_assert(WT_SESSION_IMPL *session, int error, const char *file_name, int line_number, const char *fmt, ...) WT_GCC_FUNC_DECL_ATTRIBUTE((format (printf, 5, 6))); extern int __wt_panic(WT_SESSION_IMPL *session); extern int __wt_illegal_value(WT_SESSION_IMPL *session, const char *name); extern int __wt_object_unsupported(WT_SESSION_IMPL *session, const char *uri); @@ -616,8 +616,8 @@ extern uint32_t __wt_rduppo2(uint32_t n, uint32_t po2); extern void __wt_random_init(uint32_t *rnd); extern uint32_t __wt_random(uint32_t *rnd); extern int __wt_buf_grow_worker(WT_SESSION_IMPL *session, WT_ITEM *buf, size_t size); -extern int __wt_buf_fmt(WT_SESSION_IMPL *session, WT_ITEM *buf, const char *fmt, ...) WT_GCC_ATTRIBUTE((format (printf, 3, 4))); -extern int __wt_buf_catfmt(WT_SESSION_IMPL *session, WT_ITEM *buf, const char *fmt, ...) WT_GCC_ATTRIBUTE((format (printf, 3, 4))); +extern int __wt_buf_fmt(WT_SESSION_IMPL *session, WT_ITEM *buf, const char *fmt, ...) WT_GCC_FUNC_DECL_ATTRIBUTE((format (printf, 3, 4))); +extern int __wt_buf_catfmt(WT_SESSION_IMPL *session, WT_ITEM *buf, const char *fmt, ...) WT_GCC_FUNC_DECL_ATTRIBUTE((format (printf, 3, 4))); extern int __wt_scr_alloc_func(WT_SESSION_IMPL *session, size_t size, WT_ITEM **scratchp #ifdef HAVE_DIAGNOSTIC diff --git a/src/include/gcc.h b/src/include/gcc.h index 7b606ca80b1..0acfa7be702 100644 --- a/src/include/gcc.h +++ b/src/include/gcc.h @@ -7,7 +7,12 @@ */ /* Add GCC-specific attributes to types and function declarations. */ -#define WT_GCC_ATTRIBUTE(x) __attribute__(x) +#define WT_COMPILER_TYPE_ALIGN(x) __attribute__((aligned(x))) + +#define WT_PACKED_STRUCT_BEGIN(name) \ + struct __attribute__ ((__packed__)) name { +#define WT_PACKED_STRUCT_END \ + }; /* * Attribute are only permitted on function declarations, not definitions. @@ -15,6 +20,7 @@ * dist/s_prototypes to create extern.h. */ #define WT_GCC_FUNC_ATTRIBUTE(x) +#define WT_GCC_FUNC_DECL_ATTRIBUTE(x) __attribute__(x) /* * Atomic writes: diff --git a/src/include/log.h b/src/include/log.h index f88a5381227..82d90070609 100644 --- a/src/include/log.h +++ b/src/include/log.h @@ -70,7 +70,7 @@ #define WT_LOG_SLOT_FREE 1 #define WT_LOG_SLOT_PENDING 2 #define WT_LOG_SLOT_READY 3 -typedef struct { +typedef WT_COMPILER_TYPE_ALIGN(WT_CACHE_LINE_ALIGNMENT) struct { int64_t slot_state; /* Slot state */ uint64_t slot_group_size; /* Group size */ int32_t slot_error; /* Error value */ @@ -90,7 +90,7 @@ typedef struct { #define SLOT_SYNC 0x08 /* Needs sync on release */ #define SLOT_SYNC_DIR 0x10 /* Directory sync on release */ uint32_t flags; /* Flags */ -} WT_LOGSLOT WT_GCC_ATTRIBUTE((aligned(WT_CACHE_LINE_ALIGNMENT))); +} WT_LOGSLOT; typedef struct { WT_LOGSLOT *slot; diff --git a/src/include/lsm.h b/src/include/lsm.h index 8038e5a34ab..8d50f3ea73b 100644 --- a/src/include/lsm.h +++ b/src/include/lsm.h @@ -73,7 +73,7 @@ struct __wt_cursor_lsm { * WT_LSM_CHUNK -- * A single chunk (file) in an LSM tree. */ -struct __wt_lsm_chunk { +struct WT_COMPILER_TYPE_ALIGN(WT_CACHE_LINE_ALIGNMENT) __wt_lsm_chunk { const char *uri; /* Data source for this chunk */ const char *bloom_uri; /* URI of Bloom filter, if any */ struct timespec create_ts; /* Creation time (for rate limiting) */ @@ -101,7 +101,7 @@ struct __wt_lsm_chunk { #define WT_LSM_CHUNK_ONDISK 0x04 #define WT_LSM_CHUNK_STABLE 0x08 uint32_t flags; -} WT_GCC_ATTRIBUTE((aligned(WT_CACHE_LINE_ALIGNMENT))); +}; /* * Different types of work units. Used by LSM worker threads to choose which diff --git a/src/include/msvc.h b/src/include/msvc.h index f176a40f2bf..159e72e65af 100644 --- a/src/include/msvc.h +++ b/src/include/msvc.h @@ -13,8 +13,21 @@ #define inline __inline -#define WT_GCC_ATTRIBUTE(x) +/* + * Add MSVC-specific attributes and pragmas to types and function declarations. + */ +#define WT_COMPILER_TYPE_ALIGN(x) __declspec(align(x)) + +#define WT_PACKED_STRUCT_BEGIN(name) \ + __pragma(pack(push,1)) \ + struct name { + +#define WT_PACKED_STRUCT_END \ + }; \ + __pragma(pack(pop)) + #define WT_GCC_FUNC_ATTRIBUTE(x) +#define WT_GCC_FUNC_DECL_ATTRIBUTE(x) #define __WT_ATOMIC_ADD(v, val, n, s, t) \ (WT_STATIC_ASSERT(sizeof(v) == (n)), \ diff --git a/src/include/mutex.h b/src/include/mutex.h index c5b7587303d..07aa740c525 100644 --- a/src/include/mutex.h +++ b/src/include/mutex.h @@ -68,15 +68,15 @@ struct __wt_rwlock { #if SPINLOCK_TYPE == SPINLOCK_GCC -typedef volatile int - WT_SPINLOCK WT_GCC_ATTRIBUTE((aligned(WT_CACHE_LINE_ALIGNMENT))); +typedef volatile int WT_COMPILER_TYPE_ALIGN(WT_CACHE_LINE_ALIGNMENT) + WT_SPINLOCK; #elif SPINLOCK_TYPE == SPINLOCK_PTHREAD_MUTEX ||\ SPINLOCK_TYPE == SPINLOCK_PTHREAD_MUTEX_ADAPTIVE ||\ SPINLOCK_TYPE == SPINLOCK_MSVC ||\ SPINLOCK_TYPE == SPINLOCK_PTHREAD_MUTEX_LOGGING -typedef struct { +typedef WT_COMPILER_TYPE_ALIGN(WT_CACHE_LINE_ALIGNMENT) struct { wt_mutex_t lock; uint64_t counter; /* Statistics: counter */ @@ -85,7 +85,7 @@ typedef struct { int8_t id; /* Statistics: current holder ID */ int8_t initialized; /* Lock initialized, for cleanup */ -} WT_SPINLOCK WT_GCC_ATTRIBUTE((aligned(WT_CACHE_LINE_ALIGNMENT))); +} WT_SPINLOCK; #else diff --git a/src/include/session.h b/src/include/session.h index c2ed3473dfb..909f1daf5a4 100644 --- a/src/include/session.h +++ b/src/include/session.h @@ -42,7 +42,7 @@ struct __wt_hazard { * WT_SESSION_IMPL -- * Implementation of WT_SESSION. */ -struct __wt_session_impl { +struct WT_COMPILER_TYPE_ALIGN(WT_CACHE_LINE_ALIGNMENT) __wt_session_impl { WT_SESSION iface; void *lang_private; /* Language specific private storage */ @@ -190,4 +190,4 @@ struct __wt_session_impl { uint32_t hazard_size; /* Allocated slots in hazard array. */ uint32_t nhazard; /* Count of active hazard pointers */ WT_HAZARD *hazard; /* Hazard pointer array */ -} WT_GCC_ATTRIBUTE((aligned(WT_CACHE_LINE_ALIGNMENT))); +}; diff --git a/src/include/txn.h b/src/include/txn.h index 8380e55effb..c1c4703316b 100644 --- a/src/include/txn.h +++ b/src/include/txn.h @@ -25,10 +25,10 @@ #define WT_SESSION_TXN_STATE(s) (&S2C(s)->txn_global.states[(s)->id]) -struct __wt_txn_state { +struct WT_COMPILER_TYPE_ALIGN(WT_CACHE_LINE_ALIGNMENT) __wt_txn_state { volatile uint64_t id; volatile uint64_t snap_min; -} WT_GCC_ATTRIBUTE((aligned(WT_CACHE_LINE_ALIGNMENT))); +}; struct __wt_txn_global { volatile uint64_t current; /* Current transaction ID. */ |