Commit bb1f4142 authored by Marko Mäkelä's avatar Marko Mäkelä

InnoDB: Remove thread_mutex

Use my_atomic for updating os_thread_count.

os_thread_init(): Remove.
parent 86927cc7
...@@ -151,23 +151,15 @@ os_thread_sleep( ...@@ -151,23 +151,15 @@ os_thread_sleep(
/*============*/ /*============*/
ulint tm); /*!< in: time in microseconds */ ulint tm); /*!< in: time in microseconds */
/**
Initializes OS thread management data structures. */
void
os_thread_init();
/*============*/
/** /**
Frees OS thread management data structures. */ Frees OS thread management data structures. */
void void
os_thread_free(); os_thread_free();
/*============*/
/*****************************************************************//** /*****************************************************************//**
Check if there are threads active. Check if there are threads active.
@return true if the thread count > 0. */ @return true if the thread count > 0. */
bool bool
os_thread_active(); os_thread_active();
/*==============*/
#endif #endif
...@@ -354,7 +354,6 @@ enum latch_id_t { ...@@ -354,7 +354,6 @@ enum latch_id_t {
LATCH_ID_EVENT_MANAGER, LATCH_ID_EVENT_MANAGER,
LATCH_ID_EVENT_MUTEX, LATCH_ID_EVENT_MUTEX,
LATCH_ID_SYNC_ARRAY_MUTEX, LATCH_ID_SYNC_ARRAY_MUTEX,
LATCH_ID_THREAD_MUTEX,
LATCH_ID_ZIP_PAD_MUTEX, LATCH_ID_ZIP_PAD_MUTEX,
LATCH_ID_OS_AIO_READ_MUTEX, LATCH_ID_OS_AIO_READ_MUTEX,
LATCH_ID_OS_AIO_WRITE_MUTEX, LATCH_ID_OS_AIO_WRITE_MUTEX,
......
...@@ -31,14 +31,9 @@ Created 9/8/1995 Heikki Tuuri ...@@ -31,14 +31,9 @@ Created 9/8/1995 Heikki Tuuri
#include "os0event.h" #include "os0event.h"
#include <map> #include <map>
/** Mutex that tracks the thread count. Used by innorwlocktest.cc
FIXME: the unit tests should use APIs */
SysMutex thread_mutex;
/** Number of threads active. */ /** Number of threads active. */
ulint os_thread_count; ulint os_thread_count;
/***************************************************************//** /***************************************************************//**
Compares two thread ids for equality. Compares two thread ids for equality.
@return TRUE if equal */ @return TRUE if equal */
...@@ -127,11 +122,7 @@ os_thread_create_func( ...@@ -127,11 +122,7 @@ os_thread_create_func(
CloseHandle(handle); CloseHandle(handle);
mutex_enter(&thread_mutex); my_atomic_addlint(&os_thread_count, 1);
os_thread_count++;
mutex_exit(&thread_mutex);
return((os_thread_t)new_thread_id); return((os_thread_t)new_thread_id);
#else /* _WIN32 else */ #else /* _WIN32 else */
...@@ -140,9 +131,7 @@ os_thread_create_func( ...@@ -140,9 +131,7 @@ os_thread_create_func(
pthread_attr_init(&attr); pthread_attr_init(&attr);
mutex_enter(&thread_mutex); my_atomic_addlint(&os_thread_count, 1);
++os_thread_count;
mutex_exit(&thread_mutex);
int ret = pthread_create(&new_thread_id, &attr, func, arg); int ret = pthread_create(&new_thread_id, &attr, func, arg);
...@@ -197,16 +186,11 @@ os_thread_exit( ...@@ -197,16 +186,11 @@ os_thread_exit(
pfs_delete_thread(); pfs_delete_thread();
#endif #endif
mutex_enter(&thread_mutex); my_atomic_addlint(&os_thread_count, -1);
os_thread_count--;
#ifdef _WIN32 #ifdef _WIN32
mutex_exit(&thread_mutex);
ExitThread(0); ExitThread(0);
#else #else
mutex_exit(&thread_mutex);
if (detach) { if (detach) {
pthread_detach(pthread_self()); pthread_detach(pthread_self());
} }
...@@ -260,10 +244,6 @@ bool ...@@ -260,10 +244,6 @@ bool
os_thread_active() os_thread_active()
/*==============*/ /*==============*/
{ {
mutex_enter(&thread_mutex);
bool active = (os_thread_count > 0);
/* All the threads have exited or are just exiting; /* All the threads have exited or are just exiting;
NOTE that the threads may not have completed their NOTE that the threads may not have completed their
exit yet. Should we use pthread_join() to make sure exit yet. Should we use pthread_join() to make sure
...@@ -272,30 +252,16 @@ os_thread_active() ...@@ -272,30 +252,16 @@ os_thread_active()
os_thread_exit(). Now we just sleep 0.1 os_thread_exit(). Now we just sleep 0.1
seconds and hope that is enough! */ seconds and hope that is enough! */
mutex_exit(&thread_mutex); return(my_atomic_loadlint(&os_thread_count) > 0);
return(active);
}
/**
Initializes OS thread management data structures. */
void
os_thread_init()
/*============*/
{
mutex_create(LATCH_ID_THREAD_MUTEX, &thread_mutex);
} }
/** /**
Frees OS thread management data structures. */ Frees OS thread management data structures. */
void void
os_thread_free() os_thread_free()
/*============*/
{ {
if (os_thread_count != 0) { if (ulint count = my_atomic_loadlint(&os_thread_count)) {
ib::warn() << "Some (" << os_thread_count << ") threads are" ib::warn() << "Some (" << count << ") threads are"
" still active"; " still active";
} }
mutex_destroy(&thread_mutex);
} }
...@@ -1183,7 +1183,6 @@ srv_boot(void) ...@@ -1183,7 +1183,6 @@ srv_boot(void)
srv_normalize_init_values(); srv_normalize_init_values();
sync_check_init(); sync_check_init();
os_thread_init();
/* Reset the system variables in the recovery module. */ /* Reset the system variables in the recovery module. */
recv_sys_var_init(); recv_sys_var_init();
trx_pool_init(); trx_pool_init();
......
...@@ -1498,8 +1498,6 @@ sync_latch_meta_init() ...@@ -1498,8 +1498,6 @@ sync_latch_meta_init()
LATCH_ADD_MUTEX(SYNC_ARRAY_MUTEX, SYNC_NO_ORDER_CHECK, LATCH_ADD_MUTEX(SYNC_ARRAY_MUTEX, SYNC_NO_ORDER_CHECK,
sync_array_mutex_key); sync_array_mutex_key);
LATCH_ADD_MUTEX(THREAD_MUTEX, SYNC_NO_ORDER_CHECK, thread_mutex_key);
LATCH_ADD_MUTEX(ZIP_PAD_MUTEX, SYNC_NO_ORDER_CHECK, zip_pad_mutex_key); LATCH_ADD_MUTEX(ZIP_PAD_MUTEX, SYNC_NO_ORDER_CHECK, zip_pad_mutex_key);
LATCH_ADD_MUTEX(OS_AIO_READ_MUTEX, SYNC_NO_ORDER_CHECK, LATCH_ADD_MUTEX(OS_AIO_READ_MUTEX, SYNC_NO_ORDER_CHECK,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment