diff options
author | unknown <heikki@hundin.mysql.fi> | 2003-05-31 03:12:03 +0300 |
---|---|---|
committer | unknown <heikki@hundin.mysql.fi> | 2003-05-31 03:12:03 +0300 |
commit | 3cba21f9f5abdaea110f40155467cab2899b5461 (patch) | |
tree | 028daf6927cddff18af2ae4c5bbc03a329c59dec /innobase/os | |
parent | 5d1171c024089093d6274dd9d18b480c93516109 (diff) | |
download | mariadb-git-3cba21f9f5abdaea110f40155467cab2899b5461.tar.gz |
Many files:
Free all OS sync primitives and allocated memory in InnoDB shutdown
innobase/os/os0sync.c:
Free all OS sync primitives and allocated memory in InnoDB shutdown
innobase/os/os0thread.c:
Free all OS sync primitives and allocated memory in InnoDB shutdown
innobase/include/os0sync.h:
Free all OS sync primitives and allocated memory in InnoDB shutdown
innobase/include/srv0srv.h:
Free all OS sync primitives and allocated memory in InnoDB shutdown
innobase/include/srv0start.h:
Free all OS sync primitives and allocated memory in InnoDB shutdown
innobase/ibuf/ibuf0ibuf.c:
Free all OS sync primitives and allocated memory in InnoDB shutdown
innobase/srv/srv0srv.c:
Free all OS sync primitives and allocated memory in InnoDB shutdown
innobase/srv/srv0start.c:
Free all OS sync primitives and allocated memory in InnoDB shutdown
innobase/sync/sync0sync.c:
Free all OS sync primitives and allocated memory in InnoDB shutdown
innobase/ut/ut0mem.c:
Free all OS sync primitives and allocated memory in InnoDB shutdown
Diffstat (limited to 'innobase/os')
-rw-r--r-- | innobase/os/os0sync.c | 128 | ||||
-rw-r--r-- | innobase/os/os0thread.c | 12 |
2 files changed, 126 insertions, 14 deletions
diff --git a/innobase/os/os0sync.c b/innobase/os/os0sync.c index abcfa254710..ce9f21ec9a1 100644 --- a/innobase/os/os0sync.c +++ b/innobase/os/os0sync.c @@ -28,14 +28,74 @@ struct os_mutex_struct{ do not assume that the OS mutex supports recursive locking, though NT seems to do that */ + UT_LIST_NODE_T(os_mutex_str_t) os_mutex_list; + /* list of all 'slow' OS mutexes created */ }; -/* Mutex protecting the thread count */ -os_mutex_t os_thread_count_mutex; +/* Mutex protecting the thread count and the lists of OS mutexes +and events */ +os_mutex_t os_sync_mutex; +ibool os_sync_mutex_inited = FALSE; /* This is incremented by 1 in os_thread_create and decremented by 1 in os_thread_exit */ -ulint os_thread_count = 0; +ulint os_thread_count = 0; + +/* The list of all events created (not in Windows) */ +UT_LIST_BASE_NODE_T(os_event_struct_t) os_event_list; + +/* The list of all OS 'slow' mutexes */ +UT_LIST_BASE_NODE_T(os_mutex_str_t) os_mutex_list; + +/* The following are approximate counters for debugging in Unix */ +ulint os_event_count = 0; +ulint os_mutex_count = 0; + + +/************************************************************* +Initializes global event and OS 'slow' mutex lists. */ + +void +os_sync_init(void) +/*==============*/ +{ + UT_LIST_INIT(os_event_list); + UT_LIST_INIT(os_mutex_list); + + os_sync_mutex = os_mutex_create(NULL); + + os_sync_mutex_inited = TRUE; +} + +/************************************************************* +Frees created events (not in Windows) and OS 'slow' mutexes. OS 'fast' +mutexes must be freed with sync_free() before this. */ + +void +os_sync_free(void) +/*==============*/ +{ + os_event_t event; + os_mutex_t mutex; + + event = UT_LIST_GET_FIRST(os_event_list); + + while (event) { + + os_event_free(event); + + event = UT_LIST_GET_FIRST(os_event_list); + } + + mutex = UT_LIST_GET_FIRST(os_mutex_list); + + while (mutex) { + + os_mutex_free(mutex); + + mutex = UT_LIST_GET_FIRST(os_mutex_list); + } +} /************************************************************* Creates an event semaphore, i.e., a semaphore which may @@ -51,8 +111,8 @@ os_event_create( the event is created without a name */ { #ifdef __WIN__ - HANDLE event; - + os_event_t event; + event = CreateEvent(NULL, /* No security attributes */ TRUE, /* Manual reset */ FALSE, /* Initial state nonsignaled */ @@ -83,6 +143,14 @@ os_event_create( #endif event->is_set = FALSE; + os_mutex_enter(os_sync_mutex); + + UT_LIST_ADD_FIRST(os_event_list, os_event_list, event); + + os_event_count++; + + os_mutex_exit(os_sync_mutex); + return(event); #endif } @@ -100,7 +168,7 @@ os_event_create_auto( the event is created without a name */ { #ifdef __WIN__ - HANDLE event; + os_event_t event; event = CreateEvent(NULL, /* No security attributes */ FALSE, /* Auto-reset */ @@ -114,6 +182,8 @@ os_event_create_auto( UT_NOT_USED(name); + ut_a(0); + return(NULL); #endif } @@ -193,6 +263,14 @@ os_event_free( os_fast_mutex_free(&(event->os_mutex)); ut_a(0 == pthread_cond_destroy(&(event->cond_var))); + os_mutex_enter(os_sync_mutex); + + UT_LIST_REMOVE(os_event_list, os_event_list, event); + + os_event_count--; + + os_mutex_exit(os_sync_mutex); + ut_free(event); #endif } @@ -310,8 +388,7 @@ os_event_wait_multiple( ut_a(event_array); ut_a(n > 0); - index = WaitForMultipleObjects(n, - event_array, + index = WaitForMultipleObjects(n, event_array, FALSE, /* Wait for any 1 event */ INFINITE); /* Infinite wait time limit */ @@ -360,6 +437,16 @@ os_mutex_create( mutex_str->handle = mutex; mutex_str->count = 0; + if (os_sync_mutex_inited) { + os_mutex_enter(os_sync_mutex); + } + + UT_LIST_ADD_FIRST(os_mutex_list, os_mutex_list, mutex_str); + + if (os_sync_mutex_inited) { + os_mutex_exit(os_sync_mutex); + } + return(mutex_str); #else os_fast_mutex_t* os_mutex; @@ -376,6 +463,16 @@ os_mutex_create( mutex_str->handle = os_mutex; mutex_str->count = 0; + if (os_sync_mutex_inited) { + os_mutex_enter(os_sync_mutex); + } + + UT_LIST_ADD_FIRST(os_mutex_list, os_mutex_list, mutex_str); + + if (os_sync_mutex_inited) { + os_mutex_exit(os_sync_mutex); + } + return(mutex_str); #endif } @@ -447,9 +544,22 @@ os_mutex_free( #ifdef __WIN__ ut_a(mutex); + os_mutex_enter(os_sync_mutex); + + UT_LIST_REMOVE(os_mutex_list, os_mutex_list, mutex); + + os_mutex_exit(os_sync_mutex); + ut_a(CloseHandle(mutex->handle)); + ut_free(mutex); #else + os_mutex_enter(os_sync_mutex); + + UT_LIST_REMOVE(os_mutex_list, os_mutex_list, mutex); + + os_mutex_exit(os_sync_mutex); + os_fast_mutex_free(mutex->handle); ut_free(mutex->handle); ut_free(mutex); @@ -474,6 +584,7 @@ os_fast_mutex_init( #else ut_a(0 == pthread_mutex_init(fast_mutex, MY_MUTEX_INIT_FAST)); #endif + os_mutex_count++; #endif } @@ -521,5 +632,6 @@ os_fast_mutex_free( DeleteCriticalSection((LPCRITICAL_SECTION) fast_mutex); #else ut_a(0 == pthread_mutex_destroy(fast_mutex)); + os_mutex_count--; #endif } diff --git a/innobase/os/os0thread.c b/innobase/os/os0thread.c index a68f6a3b8bc..1722051a841 100644 --- a/innobase/os/os0thread.c +++ b/innobase/os/os0thread.c @@ -101,9 +101,9 @@ os_thread_create( os_thread_t thread; ulint win_thread_id; - os_mutex_enter(os_thread_count_mutex); + os_mutex_enter(os_sync_mutex); os_thread_count++; - os_mutex_exit(os_thread_count_mutex); + os_mutex_exit(os_sync_mutex); thread = CreateThread(NULL, /* no security attributes */ 0, /* default size stack */ @@ -147,9 +147,9 @@ os_thread_create( exit(1); } #endif - os_mutex_enter(os_thread_count_mutex); + os_mutex_enter(os_sync_mutex); os_thread_count++; - os_mutex_exit(os_thread_count_mutex); + os_mutex_exit(os_sync_mutex); #if defined(UNIV_HOTBACKUP) && defined(UNIV_HPUX10) ret = pthread_create(&pthread, pthread_attr_default, start_f, arg); @@ -185,9 +185,9 @@ os_thread_exit( void* exit_value) /* in: exit value; in Windows this void* is cast as a DWORD */ { - os_mutex_enter(os_thread_count_mutex); + os_mutex_enter(os_sync_mutex); os_thread_count--; - os_mutex_exit(os_thread_count_mutex); + os_mutex_exit(os_sync_mutex); #ifdef __WIN__ ExitThread((DWORD)exit_value); |