summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'mysys')
-rw-r--r--mysys/mf_keycache.c32
-rw-r--r--mysys/my_context.c14
-rw-r--r--mysys/safemalloc.c5
-rw-r--r--mysys/thr_lock.c26
-rw-r--r--mysys/thr_mutex.c90
5 files changed, 44 insertions, 123 deletions
diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c
index 3263459bd72..3077415b243 100644
--- a/mysys/mf_keycache.c
+++ b/mysys/mf_keycache.c
@@ -1068,7 +1068,7 @@ static void link_into_queue(KEYCACHE_WQUEUE *wqueue,
static void unlink_from_queue(KEYCACHE_WQUEUE *wqueue,
struct st_my_thread_var *thread)
{
- KEYCACHE_DBUG_PRINT("unlink_from_queue", ("thread %ld", thread->id));
+ KEYCACHE_DBUG_PRINT("unlink_from_queue", ("thread %ld", (ulong) thread->id));
DBUG_ASSERT(thread->next && thread->prev);
if (thread->next == thread)
@@ -1145,7 +1145,7 @@ static void wait_on_queue(KEYCACHE_WQUEUE *wqueue,
*/
do
{
- KEYCACHE_DBUG_PRINT("wait", ("suspend thread %ld", thread->id));
+ KEYCACHE_DBUG_PRINT("wait", ("suspend thread %ld", (ulong) thread->id));
keycache_pthread_cond_wait(&thread->suspend, mutex);
}
while (thread->next);
@@ -1184,7 +1184,7 @@ static void release_whole_queue(KEYCACHE_WQUEUE *wqueue)
thread=next;
DBUG_ASSERT(thread && thread->init == 1);
KEYCACHE_DBUG_PRINT("release_whole_queue: signal",
- ("thread %ld", thread->id));
+ ("thread %ld", (ulong) thread->id));
/* Take thread from queue. */
next= thread->next;
thread->next= NULL;
@@ -1388,7 +1388,8 @@ static void link_block(SIMPLE_KEY_CACHE_CB *keycache, BLOCK_LINK *block,
*/
if ((HASH_LINK *) thread->keycache_link == hash_link)
{
- KEYCACHE_DBUG_PRINT("link_block: signal", ("thread %ld", thread->id));
+ KEYCACHE_DBUG_PRINT("link_block: signal",
+ ("thread %ld", (ulong) thread->id));
keycache_pthread_cond_signal(&thread->suspend);
unlink_from_queue(&keycache->waiting_for_block, thread);
block->requests++;
@@ -1677,7 +1678,7 @@ static void wait_for_readers(SIMPLE_KEY_CACHE_CB *keycache,
{
KEYCACHE_DBUG_PRINT("wait_for_readers: wait",
("suspend thread %ld block %u",
- thread->id, BLOCK_NUMBER(block)));
+ (ulong) thread->id, BLOCK_NUMBER(block)));
/* There must be no other waiter. We have no queue here. */
DBUG_ASSERT(!block->condvar);
block->condvar= &thread->suspend;
@@ -1737,7 +1738,8 @@ static void unlink_hash(SIMPLE_KEY_CACHE_CB *keycache, HASH_LINK *hash_link)
*/
if (page->file == hash_link->file && page->filepos == hash_link->diskpos)
{
- KEYCACHE_DBUG_PRINT("unlink_hash: signal", ("thread %ld", thread->id));
+ KEYCACHE_DBUG_PRINT("unlink_hash: signal",
+ ("thread %ld", (ulong) thread->id));
keycache_pthread_cond_signal(&thread->suspend);
unlink_from_queue(&keycache->waiting_for_hash_link, thread);
}
@@ -1821,7 +1823,7 @@ restart:
thread->keycache_link= (void *) &page;
link_into_queue(&keycache->waiting_for_hash_link, thread);
KEYCACHE_DBUG_PRINT("get_hash_link: wait",
- ("suspend thread %ld", thread->id));
+ ("suspend thread %ld", (ulong) thread->id));
keycache_pthread_cond_wait(&thread->suspend,
&keycache->cache_lock);
thread->keycache_link= NULL;
@@ -1987,7 +1989,7 @@ restart:
do
{
KEYCACHE_DBUG_PRINT("find_key_block: wait",
- ("suspend thread %ld", thread->id));
+ ("suspend thread %ld", (ulong) thread->id));
keycache_pthread_cond_wait(&thread->suspend,
&keycache->cache_lock);
} while (thread->next);
@@ -2334,7 +2336,7 @@ restart:
do
{
KEYCACHE_DBUG_PRINT("find_key_block: wait",
- ("suspend thread %ld", thread->id));
+ ("suspend thread %ld", (ulong) thread->id));
keycache_pthread_cond_wait(&thread->suspend,
&keycache->cache_lock);
}
@@ -4585,7 +4587,7 @@ static void keycache_dump(SIMPLE_KEY_CACHE_CB *keycache)
KEYCACHE_PAGE *page;
uint i;
- fprintf(keycache_dump_file, "thread:%u\n", thread->id);
+ fprintf(keycache_dump_file, "thread:%lu\n", (ulong) thread->id);
i=0;
thread=last=waiting_for_hash_link.last_thread;
@@ -4596,8 +4598,8 @@ static void keycache_dump(SIMPLE_KEY_CACHE_CB *keycache)
thread=thread->next;
page= (KEYCACHE_PAGE *) thread->keycache_link;
fprintf(keycache_dump_file,
- "thread:%u, (file,filepos)=(%u,%lu)\n",
- thread->id,(uint) page->file,(ulong) page->filepos);
+ "thread:%lu, (file,filepos)=(%u,%lu)\n",
+ (ulong) thread->id,(uint) page->file,(ulong) page->filepos);
if (++i == MAX_QUEUE_LEN)
break;
}
@@ -4612,8 +4614,8 @@ static void keycache_dump(SIMPLE_KEY_CACHE_CB *keycache)
thread=thread->next;
hash_link= (HASH_LINK *) thread->keycache_link;
fprintf(keycache_dump_file,
- "thread:%u hash_link:%u (file,filepos)=(%u,%lu)\n",
- thread->id, (uint) HASH_LINK_NUMBER(hash_link),
+ "thread:%lu hash_link:%u (file,filepos)=(%u,%lu)\n",
+ (ulong) thread->id, (uint) HASH_LINK_NUMBER(hash_link),
(uint) hash_link->file,(ulong) hash_link->diskpos);
if (++i == MAX_QUEUE_LEN)
break;
@@ -4640,7 +4642,7 @@ static void keycache_dump(SIMPLE_KEY_CACHE_CB *keycache)
{
thread=thread->next;
fprintf(keycache_dump_file,
- "thread:%u\n", thread->id);
+ "thread:%lu\n", (ulong) thread->id);
if (++i == MAX_QUEUE_LEN)
break;
}
diff --git a/mysys/my_context.c b/mysys/my_context.c
index 60c0014b3b9..5faa041361a 100644
--- a/mysys/my_context.c
+++ b/mysys/my_context.c
@@ -24,7 +24,7 @@
#include "m_string.h"
#include "my_context.h"
-#ifdef HAVE_VALGRIND
+#ifdef HAVE_VALGRIND_MEMCHECK_H
#include <valgrind/valgrind.h>
#endif
@@ -134,7 +134,7 @@ my_context_init(struct my_context *c, size_t stack_size)
if (!(c->stack= malloc(stack_size)))
return -1; /* Out of memory */
c->stack_size= stack_size;
-#ifdef HAVE_VALGRIND
+#ifdef HAVE_VALGRIND_MEMCHECK_H
c->valgrind_stack_id=
VALGRIND_STACK_REGISTER(c->stack, ((unsigned char *)(c->stack))+stack_size);
#endif
@@ -146,7 +146,7 @@ my_context_destroy(struct my_context *c)
{
if (c->stack)
{
-#ifdef HAVE_VALGRIND
+#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id);
#endif
free(c->stack);
@@ -384,7 +384,7 @@ my_context_init(struct my_context *c, size_t stack_size)
(( ((intptr)c->stack_bot + stack_size) & ~(intptr)0xf) - 16);
bzero(c->stack_top, 16);
-#ifdef HAVE_VALGRIND
+#ifdef HAVE_VALGRIND_MEMCHECK_H
c->valgrind_stack_id=
VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top);
#endif
@@ -397,7 +397,7 @@ my_context_destroy(struct my_context *c)
if (c->stack_bot)
{
free(c->stack_bot);
-#ifdef HAVE_VALGRIND
+#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id);
#endif
}
@@ -620,7 +620,7 @@ my_context_init(struct my_context *c, size_t stack_size)
(( ((intptr)c->stack_bot + stack_size) & ~(intptr)0xf) - 16);
bzero(c->stack_top, 16);
-#ifdef HAVE_VALGRIND
+#ifdef HAVE_VALGRIND_MEMCHECK_H
c->valgrind_stack_id=
VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top);
#endif
@@ -633,7 +633,7 @@ my_context_destroy(struct my_context *c)
if (c->stack_bot)
{
free(c->stack_bot);
-#ifdef HAVE_VALGRIND
+#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id);
#endif
}
diff --git a/mysys/safemalloc.c b/mysys/safemalloc.c
index 5d19647c989..9916650308a 100644
--- a/mysys/safemalloc.c
+++ b/mysys/safemalloc.c
@@ -55,6 +55,9 @@ struct st_irem
struct st_irem *next; /* Linked list of structures */
struct st_irem *prev; /* Other link */
size_t datasize; /* Size requested */
+#if SIZEOF_SIZE_T == 4
+ size_t pad; /* Compensate 32bit datasize */
+#endif
#ifdef HAVE_BACKTRACE
void *frame[SF_REMEMBER_FRAMES]; /* call stack */
#endif
@@ -375,7 +378,7 @@ void sf_report_leaked_memory(my_thread_id id)
{
my_thread_id tid = irem->thread_id && irem->flags & MY_THREAD_SPECIFIC ?
irem->thread_id : 0;
- fprintf(stderr, "Warning: %4lu bytes lost at %p, allocated by T@%lu at ",
+ fprintf(stderr, "Warning: %4lu bytes lost at %p, allocated by T@%llu at ",
(ulong) irem->datasize, (char*) (irem + 1), tid);
print_stack(irem->frame);
total+= irem->datasize;
diff --git a/mysys/thr_lock.c b/mysys/thr_lock.c
index 8990cbd5a14..da653b12314 100644
--- a/mysys/thr_lock.c
+++ b/mysys/thr_lock.c
@@ -772,7 +772,7 @@ thr_lock(THR_LOCK_DATA *data, THR_LOCK_INFO *owner, ulong lock_wait_timeout)
mysql_mutex_lock(&lock->mutex);
DBUG_PRINT("lock",("data: 0x%lx thread: 0x%lx lock: 0x%lx type: %d",
- (long) data, data->owner->thread_id,
+ (long) data, (ulong) data->owner->thread_id,
(long) lock, (int) lock_type));
check_locks(lock,(uint) lock_type <= (uint) TL_READ_NO_INSERT ?
"enter read_lock" : "enter write_lock", lock_type, 0);
@@ -809,7 +809,7 @@ thr_lock(THR_LOCK_DATA *data, THR_LOCK_INFO *owner, ulong lock_wait_timeout)
*/
DBUG_PRINT("lock",("write locked 1 by thread: 0x%lx",
- lock->write.data->owner->thread_id));
+ (ulong) lock->write.data->owner->thread_id));
if (thr_lock_owner_equal(data->owner, lock->write.data->owner) ||
(lock->write.data->type <= TL_WRITE_DELAYED &&
(((int) lock_type <= (int) TL_READ_HIGH_PRIORITY) ||
@@ -968,7 +968,7 @@ thr_lock(THR_LOCK_DATA *data, THR_LOCK_INFO *owner, ulong lock_wait_timeout)
goto end;
}
DBUG_PRINT("lock",("write locked 2 by thread: 0x%lx",
- lock->write.data->owner->thread_id));
+ (ulong) lock->write.data->owner->thread_id));
}
else
{
@@ -1004,7 +1004,8 @@ thr_lock(THR_LOCK_DATA *data, THR_LOCK_INFO *owner, ulong lock_wait_timeout)
}
}
DBUG_PRINT("lock",("write locked 3 by thread: 0x%lx type: %d",
- lock->read.data->owner->thread_id, data->type));
+ (ulong) lock->read.data->owner->thread_id,
+ data->type));
}
#ifdef WITH_WSREP
if (wsrep_break_lock(data, &lock->write, &lock->write_wait))
@@ -1069,7 +1070,7 @@ static inline void free_all_read_locks(THR_LOCK *lock,
}
/* purecov: begin inspected */
DBUG_PRINT("lock",("giving read lock to thread: 0x%lx",
- data->owner->thread_id));
+ (ulong) data->owner->thread_id));
/* purecov: end */
data->cond=0; /* Mark thread free */
mysql_cond_signal(cond);
@@ -1087,8 +1088,9 @@ void thr_unlock(THR_LOCK_DATA *data, uint unlock_flags)
THR_LOCK *lock=data->lock;
enum thr_lock_type lock_type=data->type;
DBUG_ENTER("thr_unlock");
- DBUG_PRINT("lock",("data: 0x%lx thread: 0x%lx lock: 0x%lx",
- (long) data, data->owner->thread_id, (long) lock));
+ DBUG_PRINT("lock",("data: %p thread: 0x%lx lock: %p",
+ data, (ulong) data->owner->thread_id,
+ lock));
mysql_mutex_lock(&lock->mutex);
check_locks(lock,"start of release lock", lock_type, 0);
@@ -1181,7 +1183,7 @@ static void wake_up_waiters(THR_LOCK *lock)
data->type=TL_WRITE; /* Upgrade lock */
/* purecov: begin inspected */
DBUG_PRINT("lock",("giving write lock of type %d to thread: 0x%lx",
- data->type, data->owner->thread_id));
+ data->type, (ulong) data->owner->thread_id));
/* purecov: end */
{
mysql_cond_t *cond= data->cond;
@@ -1423,9 +1425,9 @@ void thr_multi_unlock(THR_LOCK_DATA **data,uint count, uint unlock_flags)
thr_unlock(*pos, unlock_flags);
else
{
- DBUG_PRINT("lock",("Free lock: data: 0x%lx thread: 0x%lx lock: 0x%lx",
- (long) *pos, (*pos)->owner->thread_id,
- (long) (*pos)->lock));
+ DBUG_PRINT("lock",("Free lock: data: %p thread: 0x%lx lock: %p",
+ *pos, (ulong) (*pos)->owner->thread_id,
+ (*pos)->lock));
}
}
DBUG_VOID_RETURN;
@@ -1673,7 +1675,7 @@ static void thr_print_lock(const char* name,struct st_lock_list *list)
prev= &list->data;
for (data=list->data; data && count++ < MAX_LOCKS ; data=data->next)
{
- printf("0x%lx (%lu:%d); ", (ulong) data, data->owner->thread_id,
+ printf("%p (%lu:%d); ", data, (ulong) data->owner->thread_id,
(int) data->type);
if (data->prev != prev)
printf("\nWarning: prev didn't point at previous lock\n");
diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c
index 18af5f47b10..f1e83db2bb6 100644
--- a/mysys/thr_mutex.c
+++ b/mysys/thr_mutex.c
@@ -105,8 +105,6 @@ void my_mutex_init()
#if defined(SAFE_MUTEX_DEFINED)
safe_mutex_global_init();
-#elif defined(MY_PTHREAD_FASTMUTEX)
- fastmutex_global_init();
#endif
}
@@ -512,7 +510,7 @@ int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp, const char *file,
fprintf(stderr,
"safe_mutex: Count was %d in thread 0x%lx when locking mutex %s "
"at %s, line %d\n",
- mp->count-1, my_thread_dbug_id(), mp->name, file, line);
+ mp->count-1, (ulong) my_thread_dbug_id(), mp->name, file, line);
fflush(stderr);
abort();
}
@@ -566,7 +564,7 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
fprintf(stderr,
"safe_mutex: Count was %d in thread 0x%lx when locking mutex "
"%s at %s, line %d (error: %d (%d))\n",
- mp->count-1, my_thread_dbug_id(), mp->name, file, line,
+ mp->count-1, (ulong) my_thread_dbug_id(), mp->name, file, line,
error, error);
fflush(stderr);
abort();
@@ -838,88 +836,4 @@ static void print_deadlock_warning(safe_mutex_t *new_mutex,
DBUG_VOID_RETURN;
}
-#elif defined(MY_PTHREAD_FASTMUTEX) /* !SAFE_MUTEX_DEFINED */
-
-static ulong mutex_delay(ulong delayloops)
-{
- ulong i;
- volatile ulong j;
-
- j = 0;
-
- for (i = 0; i < delayloops * 50; i++)
- j += i;
-
- return(j);
-}
-
-#define MY_PTHREAD_FASTMUTEX_SPINS 8
-#define MY_PTHREAD_FASTMUTEX_DELAY 4
-
-static int cpu_count= 0;
-
-int my_pthread_fastmutex_init(my_pthread_fastmutex_t *mp,
- const pthread_mutexattr_t *attr)
-{
- if ((cpu_count > 1) && (attr == MY_MUTEX_INIT_FAST))
- mp->spins= MY_PTHREAD_FASTMUTEX_SPINS;
- else
- mp->spins= 0;
- mp->rng_state= 1;
- return pthread_mutex_init(&mp->mutex, attr);
-}
-
-/**
- Park-Miller random number generator. A simple linear congruential
- generator that operates in multiplicative group of integers modulo n.
-
- x_{k+1} = (x_k g) mod n
-
- Popular pair of parameters: n = 2^32 − 5 = 4294967291 and g = 279470273.
- The period of the generator is about 2^31.
- Largest value that can be returned: 2147483646 (RAND_MAX)
-
- Reference:
-
- S. K. Park and K. W. Miller
- "Random number generators: good ones are hard to find"
- Commun. ACM, October 1988, Volume 31, No 10, pages 1192-1201.
-*/
-
-static double park_rng(my_pthread_fastmutex_t *mp)
-{
- mp->rng_state= ((my_ulonglong)mp->rng_state * 279470273U) % 4294967291U;
- return (mp->rng_state / 2147483647.0);
-}
-
-int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp)
-{
- int res;
- uint i;
- uint maxdelay= MY_PTHREAD_FASTMUTEX_DELAY;
-
- for (i= 0; i < mp->spins; i++)
- {
- res= pthread_mutex_trylock(&mp->mutex);
-
- if (res == 0)
- return 0;
-
- if (res != EBUSY)
- return res;
-
- mutex_delay(maxdelay);
- maxdelay += park_rng(mp) * MY_PTHREAD_FASTMUTEX_DELAY + 1;
- }
- return pthread_mutex_lock(&mp->mutex);
-}
-
-
-void fastmutex_global_init(void)
-{
-#ifdef _SC_NPROCESSORS_CONF
- cpu_count= sysconf(_SC_NPROCESSORS_CONF);
#endif
-}
-
-#endif /* defined(MY_PTHREAD_FASTMUTEX) && defined(SAFE_MUTEX_DEFINED) */