--- mysql50/include/my_global.h 2009-02-21 18:10:20.000000000 -0800 +++ mysql50/include/my_global.h 2009-02-26 08:30:51.000000000 -0800 @@ -1330,6 +1330,12 @@ #define thread_safe_sub(V,C,L) (V)-=(C) #define statistic_increment(V,L) (V)++ #define statistic_add(V,C,L) (V)+=(C) + +// Defined in my_pthread.h for server code +#define THREAD_SAFE_BIGWORD int +#define thread_safe_add_big(V,C,L) (V)+=(C) +#define thread_safe_sub_big(V,C,L) (V)-=(C) + #endif #ifdef HAVE_CHARSET_utf8 ==== //depot/google_vendor_src_branch/mysql50/include/my_pthread.h#7 - None ==== # action=edit type=text --- mysql50/include/my_pthread.h 2009-02-21 18:10:21.000000000 -0800 +++ mysql50/include/my_pthread.h 2009-02-26 08:30:51.000000000 -0800 @@ -917,6 +917,17 @@ /* statistics_xxx functions are for not essential statistic */ +/* Atomic operations for the largest machine integer type. */ +#ifdef __x86_64__ +#define THREAD_SAFE_BIGWORD atomic64_t +#define thread_safe_add_big(V,C,L) thread_safe_add64(V,C,L) +#define thread_safe_sub_big(V,C,L) thread_safe_sub64(V,C,L) +#else +#define THREAD_SAFE_BIGWORD atomic_t +#define thread_safe_add_big(V,C,L) thread_safe_add(V,C,L) +#define thread_safe_sub_big(V,C,L) thread_safe_sub(V,C,L) +#endif + #ifndef thread_safe_increment #if defined(__x86_64__) && defined(HAVE_ATOMIC_ADD) --- mysql50/mysys/my_alloc.c 2009-02-21 18:10:21.000000000 -0800 +++ mysql50/mysys/my_alloc.c 2009-02-26 08:30:51.000000000 -0800 @@ -47,6 +47,16 @@ #define TRASH_MEM(X) TRASH(((char*)(X) + ((X)->size-(X)->left)), (X)->left) #endif /* USE_VALGRIND */ + +/* Count number of bytes currently allocated for all MEM_ROOT instances */ +extern pthread_mutex_t LOCK_stats; +THREAD_SAFE_BIGWORD atomic_bytes_allocated; + +#define add_malloc_count(v) \ + thread_safe_add_big(atomic_bytes_allocated, (v), &LOCK_stats) + +#define sub_malloc_count(v) \ + thread_safe_sub_big(atomic_bytes_allocated, (v), &LOCK_stats) /* Initialize memory root @@ -92,6 +102,7 @@ mem_root->free->size= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM)); mem_root->free->left= pre_alloc_size; mem_root->free->next= 0; + add_malloc_count(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM))); } } #endif @@ -146,6 +157,7 @@ { /* remove block from the list and free it */ *prev= mem->next; + sub_malloc_count(mem->size); my_free((gptr) mem, MYF(0)); } else @@ -158,6 +170,7 @@ mem->left= pre_alloc_size; mem->next= *prev; *prev= mem_root->pre_alloc= mem; + add_malloc_count(size); } } } @@ -183,6 +196,7 @@ (*mem_root->error_handler)(); DBUG_RETURN((gptr) 0); /* purecov: inspected */ } + add_malloc_count(Size); /* TODO(larryz): next->left was not properly initiated here, * by looking at the other part of if macro, it's believed it should be here. @@ -232,6 +246,7 @@ (*mem_root->error_handler)(); return((gptr) 0); /* purecov: inspected */ } + add_malloc_count(get_size); mem_root->block_num++; next->next= *prev; next->size= get_size; @@ -383,13 +398,19 @@ { old=next; next= next->next ; if (old != root->pre_alloc) + { + sub_malloc_count(old->size); my_free((gptr) old,MYF(0)); + } } for (next=root->free ; next ;) { old=next; next= next->next; if (old != root->pre_alloc) + { + sub_malloc_count(old->size); my_free((gptr) old,MYF(0)); + } } root->used=root->free=0; if (root->pre_alloc)