From 27dadbd89577e8ff80c926cfb3fbd36cf0fb48a4 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 1 Sep 2008 21:43:11 +0200 Subject: [PATCH] wt: don't support a key as a union { ulonglong, void* }. Although convenient, it forces the user to bzero a key before setting it as a pointer, otherwise it'll have random content on architectures where sizeof(void*) < sizeof(ulonglong). Declaring a key as ulonglong only (not a union) makes this user mistake impossible. include/waiting_threads.h: WT_RESOURCE_ID::value is an ulonglong, not a union mysys/waiting_threads.c: WT_RESOURCE_ID::value is an ulonglong, not a union storage/maria/ma_write.c: WT_RESOURCE_ID::value is an ulonglong, not a union storage/maria/trnman.c: WT_RESOURCE_ID::value is an ulonglong, not a union unittest/mysys/waiting_threads-t.c: WT_RESOURCE_ID::value is an ulonglong, not a union --- include/waiting_threads.h | 5 +---- mysys/waiting_threads.c | 17 ++++++++--------- storage/maria/ma_write.c | 2 +- storage/maria/trnman.c | 2 +- unittest/mysys/waiting_threads-t.c | 6 ++---- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/include/waiting_threads.h b/include/waiting_threads.h index c2aecdc760d..0df17a47c61 100644 --- a/include/waiting_threads.h +++ b/include/waiting_threads.h @@ -32,10 +32,7 @@ typedef struct st_wt_resource_type { struct st_wt_resource_id { WT_RESOURCE_TYPE *type; - union { - void *ptr; - ulonglong num; - } value; + ulonglong value; }; #define WT_WAIT_STATS 24 diff --git a/mysys/waiting_threads.c b/mysys/waiting_threads.c index 49b41111311..255317ea4cc 100644 --- a/mysys/waiting_threads.c +++ b/mysys/waiting_threads.c @@ -30,8 +30,7 @@ A resource is represented by a WT_RESOURCE structure. a resource identifier - a pair of {resource type, value}. A value is - either a ulonglong number or a pointer (it's a union). - WT_RESOURCE_ID structure. + an ulonglong number. Represented by a WT_RESOURCE_ID structure. a resource type - a pointer to a statically defined instance of WT_RESOURCE_TYPE structure. This structure contains a pointer to @@ -169,20 +168,20 @@ static my_atomic_rwlock_t cycle_stats_lock, wait_stats_lock, success_stats_lock; #define rc_rdlock(X) \ do { \ WT_RESOURCE *R=(X); \ - DBUG_PRINT("wt", ("LOCK resid=%lld for READ", R->id.value.num)); \ - rw_rdlock(&R->lock); \ + DBUG_PRINT("wt", ("LOCK resid=%lld for READ", R->id.value)); \ + rw_rdlock(&R->lock); \ } while (0) #define rc_wrlock(X) \ do { \ WT_RESOURCE *R=(X); \ - DBUG_PRINT("wt", ("LOCK resid=%lld for WRITE", R->id.value.num)); \ - rw_wrlock(&R->lock); \ + DBUG_PRINT("wt", ("LOCK resid=%lld for WRITE", R->id.value)); \ + rw_wrlock(&R->lock); \ } while (0) #define rc_unlock(X) \ do { \ WT_RESOURCE *R=(X); \ - DBUG_PRINT("wt", ("UNLOCK resid=%lld", R->id.value.num)); \ - rw_unlock(&R->lock); \ + DBUG_PRINT("wt", ("UNLOCK resid=%lld", R->id.value)); \ + rw_unlock(&R->lock); \ } while (0) /* @@ -688,7 +687,7 @@ int wt_thd_will_wait_for(WT_THD *thd, WT_THD *blocker, WT_RESOURCE_ID *resid) LF_REQUIRE_PINS(3); DBUG_PRINT("wt", ("enter: thd=%s, blocker=%s, resid=%llu", - thd->name, blocker->name, resid->value.num)); + thd->name, blocker->name, resid->value)); if (fix_thd_pins(thd)) DBUG_RETURN(WT_DEADLOCK); diff --git a/storage/maria/ma_write.c b/storage/maria/ma_write.c index fb380b6d3e2..4d4fccb8f39 100644 --- a/storage/maria/ma_write.c +++ b/storage/maria/ma_write.c @@ -217,7 +217,7 @@ int maria_write(MARIA_HA *info, uchar *record) int res; rc.type= &ma_rc_dup_unique; - rc.value.ptr= blocker; /* TODO savepoint id when we'll have them */ + rc.value= (intptr)blocker; /* TODO savepoint id when we'll have them */ res= wt_thd_will_wait_for(info->trn->wt, blocker->wt, & rc); if (res != WT_OK) { diff --git a/storage/maria/trnman.c b/storage/maria/trnman.c index 4a9004596ae..981b81e2252 100644 --- a/storage/maria/trnman.c +++ b/storage/maria/trnman.c @@ -87,7 +87,7 @@ static void wt_thd_release_self(TRN *trn) { WT_RESOURCE_ID rc; rc.type= &ma_rc_dup_unique; - rc.value.ptr= trn; + rc.value= (intptr)trn; wt_thd_release(trn->wt, & rc); trn->wt= 0; } diff --git a/unittest/mysys/waiting_threads-t.c b/unittest/mysys/waiting_threads-t.c index 3c60e31a66f..39a8e800db0 100644 --- a/unittest/mysys/waiting_threads-t.c +++ b/unittest/mysys/waiting_threads-t.c @@ -62,9 +62,8 @@ pthread_handler_t test_wt(void *arg) { WT_RESOURCE_ID resid; int blockers[THREADS/10], j, k; - bzero(&resid, sizeof(resid)); - resid.value.num= id; + resid.value= id; resid.type= &restype; res= 0; @@ -187,8 +186,7 @@ void do_tests() WT_RESOURCE_ID resid[3]; for (i=0; i < 3; i++) { - bzero(&resid[i], sizeof(resid[i])); - resid[i].value.num= i+1; + resid[i].value= i+1; resid[i].type= &restype; }