#include "os0thread.h"#include "srv0srv.h"#include "os0sync.h"Include dependency graph for os0thread.c:

Go to the source code of this file.
Functions | |
| ibool | os_thread_eq (os_thread_id_t a, os_thread_id_t b) |
| ulint | os_thread_pf (os_thread_id_t a) |
| os_thread_id_t | os_thread_get_curr_id (void) |
| os_thread_t | os_thread_create (os_posix_f_t start_f, void *arg, os_thread_id_t *thread_id) |
| void | os_thread_exit (void *exit_value) |
| os_thread_t | os_thread_get_curr (void) |
| void | os_thread_yield (void) |
| void | os_thread_sleep (ulint tm) |
| void | os_thread_set_priority (os_thread_t handle, ulint pri) |
| ulint | os_thread_get_priority (os_thread_t handle __attribute__((unused))) |
| ulint | os_thread_get_last_error (void) |
| os_thread_t os_thread_create | ( | os_posix_f_t | start_f, | |
| void * | arg, | |||
| os_thread_id_t * | thread_id | |||
| ) |
Definition at line 87 of file os0thread.c.
References exit, my_pthread_setprio(), NULL, NW_THD_STACKSIZE, os_mutex_enter(), os_mutex_exit(), os_sync_mutex, os_thread_count, pthread_attr_setstacksize, PTHREAD_STACK_MIN, srv_query_thread_priority, srv_set_thread_priorities, and ut_a.
Referenced by innobase_start_or_create_for_mysql(), and recv_recovery_from_checkpoint_finish().
00089 : handle to the thread */ 00090 #ifndef __WIN__ 00091 os_posix_f_t start_f, 00092 #else 00093 ulint (*start_f)(void*), /* in: pointer to function 00094 from which to start */ 00095 #endif 00096 void* arg, /* in: argument to start 00097 function */ 00098 os_thread_id_t* thread_id) /* out: id of the created 00099 thread, or NULL */ 00100 { 00101 #ifdef __WIN__ 00102 os_thread_t thread; 00103 DWORD win_thread_id; 00104 00105 os_mutex_enter(os_sync_mutex); 00106 os_thread_count++; 00107 os_mutex_exit(os_sync_mutex); 00108 00109 thread = CreateThread(NULL, /* no security attributes */ 00110 0, /* default size stack */ 00111 (LPTHREAD_START_ROUTINE)start_f, 00112 arg, 00113 0, /* thread runs immediately */ 00114 &win_thread_id); 00115 00116 if (srv_set_thread_priorities) { 00117 00118 /* Set created thread priority the same as a normal query 00119 in MYSQL: we try to prevent starvation of threads by 00120 assigning same priority QUERY_PRIOR to all */ 00121 00122 ut_a(SetThreadPriority(thread, srv_query_thread_priority)); 00123 } 00124 00125 if (thread_id) { 00126 *thread_id = win_thread_id; 00127 } 00128 00129 return(thread); 00130 #else 00131 int ret; 00132 os_thread_t pthread; 00133 pthread_attr_t attr; 00134 00135 #if !(defined(UNIV_HOTBACKUP) && defined(UNIV_HPUX10)) 00136 pthread_attr_init(&attr); 00137 #endif 00138 00139 #ifdef UNIV_AIX 00140 /* We must make sure a thread stack is at least 32 kB, otherwise 00141 InnoDB might crash; we do not know if the default stack size on 00142 AIX is always big enough. An empirical test on AIX-4.3 suggested 00143 the size was 96 kB, though. */ 00144 00145 ret = pthread_attr_setstacksize(&attr, 00146 (size_t)(PTHREAD_STACK_MIN + 32 * 1024)); 00147 if (ret) { 00148 fprintf(stderr, 00149 "InnoDB: Error: pthread_attr_setstacksize returned %d\n", ret); 00150 exit(1); 00151 } 00152 #endif 00153 #ifdef __NETWARE__ 00154 ret = pthread_attr_setstacksize(&attr, 00155 (size_t) NW_THD_STACKSIZE); 00156 if (ret) { 00157 fprintf(stderr, 00158 "InnoDB: Error: pthread_attr_setstacksize returned %d\n", ret); 00159 exit(1); 00160 } 00161 #endif 00162 os_mutex_enter(os_sync_mutex); 00163 os_thread_count++; 00164 os_mutex_exit(os_sync_mutex); 00165 00166 #if defined(UNIV_HOTBACKUP) && defined(UNIV_HPUX10) 00167 ret = pthread_create(&pthread, pthread_attr_default, start_f, arg); 00168 #else 00169 ret = pthread_create(&pthread, &attr, start_f, arg); 00170 #endif 00171 if (ret) { 00172 fprintf(stderr, 00173 "InnoDB: Error: pthread_create returned %d\n", ret); 00174 exit(1); 00175 } 00176 00177 #if !(defined(UNIV_HOTBACKUP) && defined(UNIV_HPUX10)) 00178 pthread_attr_destroy(&attr); 00179 #endif 00180 if (srv_set_thread_priorities) { 00181 00182 my_pthread_setprio(pthread, srv_query_thread_priority); 00183 } 00184 00185 if (thread_id) { 00186 *thread_id = pthread; 00187 } 00188 00189 return(pthread); 00190 #endif 00191 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_thread_eq | ( | os_thread_id_t | a, | |
| os_thread_id_t | b | |||
| ) |
Definition at line 25 of file os0thread.c.
Referenced by rw_lock_x_lock_low(), sync_arr_cell_can_wake_up(), sync_thread_level_arrays_find_slot(), thr_local_free(), and thr_local_get().
00027 : TRUE if equal */ 00028 os_thread_id_t a, /* in: OS thread or thread id */ 00029 os_thread_id_t b) /* in: OS thread or thread id */ 00030 { 00031 #ifdef __WIN__ 00032 if (a == b) { 00033 return(TRUE); 00034 } 00035 00036 return(FALSE); 00037 #else 00038 if (pthread_equal(a, b)) { 00039 return(TRUE); 00040 } 00041 00042 return(FALSE); 00043 #endif 00044 }
Here is the caller graph for this function:

| void os_thread_exit | ( | void * | exit_value | ) |
Definition at line 197 of file os0thread.c.
References os_mutex_enter(), os_mutex_exit(), os_sync_mutex, os_thread_count, os_thread_get_curr_id(), and os_thread_pf().
Referenced by io_handler_thread(), os_event_wait(), srv_error_monitor_thread(), srv_master_thread(), and trx_rollback_or_clean_all_without_sess().
00199 : exit value; in Windows this void* 00200 is cast as a DWORD */ 00201 { 00202 #ifdef UNIV_DEBUG_THREAD_CREATION 00203 fprintf(stderr, "Thread exits, id %lu\n", 00204 os_thread_pf(os_thread_get_curr_id())); 00205 #endif 00206 os_mutex_enter(os_sync_mutex); 00207 os_thread_count--; 00208 os_mutex_exit(os_sync_mutex); 00209 00210 #ifdef __WIN__ 00211 ExitThread((DWORD)exit_value); 00212 #else 00213 pthread_exit(exit_value); 00214 #endif 00215 }
Here is the call graph for this function:

Here is the caller graph for this function:

| os_thread_t os_thread_get_curr | ( | void | ) |
Definition at line 230 of file os0thread.c.
Referenced by srv_table_reserve_slot(), srv_table_reserve_slot_for_mysql(), and thr_local_create().
00232 { 00233 #ifdef __WIN__ 00234 return(GetCurrentThread()); 00235 #else 00236 return(pthread_self()); 00237 #endif 00238 }
Here is the caller graph for this function:

| os_thread_id_t os_thread_get_curr_id | ( | void | ) |
Definition at line 71 of file os0thread.c.
Referenced by io_handler_thread(), mutex_spin_wait(), os_thread_exit(), row_create_index_for_mysql(), row_create_table_for_mysql(), row_discard_tablespace_for_mysql(), row_drop_database_for_mysql(), row_import_tablespace_for_mysql(), row_insert_for_mysql(), row_lock_table_autoinc_for_mysql(), row_lock_table_for_mysql(), row_rename_table_for_mysql(), row_search_for_mysql(), row_truncate_table_for_mysql(), row_unlock_for_mysql(), row_update_for_mysql(), rw_lock_s_lock_spin(), rw_lock_x_lock_func(), rw_lock_x_lock_low(), rw_lock_x_lock_move_ownership(), srv_error_monitor_thread(), srv_get_thread_type(), srv_lock_timeout_and_monitor_thread(), srv_master_thread(), srv_suspend_thread(), srv_table_reserve_slot(), srv_table_reserve_slot_for_mysql(), sync_array_reserve_cell(), sync_array_wait_event(), sync_thread_add_level(), sync_thread_level_arrays_find_slot(), thr_local_create(), thr_local_get_in_ibuf_field(), trx_allocate_for_mysql(), trx_rollback_or_clean_all_without_sess(), ut_dbg_assertion_failed(), and ut_dbg_stop_thread().
00073 { 00074 #ifdef __WIN__ 00075 return(GetCurrentThreadId()); 00076 #else 00077 return(pthread_self()); 00078 #endif 00079 }
Here is the caller graph for this function:

| ulint os_thread_get_last_error | ( | void | ) |
Definition at line 347 of file os0thread.c.
00349 { 00350 #ifdef __WIN__ 00351 return(GetLastError()); 00352 #else 00353 return(0); 00354 #endif 00355 }
| ulint os_thread_get_priority | ( | os_thread_t handle | __attribute__((unused)) | ) |
Definition at line 315 of file os0thread.c.
References handle, OS_THREAD_PRIORITY_ABOVE_NORMAL, OS_THREAD_PRIORITY_BACKGROUND, OS_THREAD_PRIORITY_NORMAL, and ut_error.
00317 : priority */ 00318 os_thread_t handle __attribute__((unused))) 00319 /* in: OS handle to the thread */ 00320 { 00321 #ifdef __WIN__ 00322 int os_pri; 00323 ulint pri; 00324 00325 os_pri = GetThreadPriority(handle); 00326 00327 if (os_pri == THREAD_PRIORITY_BELOW_NORMAL) { 00328 pri = OS_THREAD_PRIORITY_BACKGROUND; 00329 } else if (os_pri == THREAD_PRIORITY_NORMAL) { 00330 pri = OS_THREAD_PRIORITY_NORMAL; 00331 } else if (os_pri == THREAD_PRIORITY_HIGHEST) { 00332 pri = OS_THREAD_PRIORITY_ABOVE_NORMAL; 00333 } else { 00334 ut_error; 00335 } 00336 00337 return(pri); 00338 #else 00339 return(0); 00340 #endif 00341 }
| ulint os_thread_pf | ( | os_thread_id_t | a | ) |
Definition at line 51 of file os0thread.c.
Referenced by io_handler_thread(), mutex_spin_wait(), os_thread_exit(), rw_lock_s_lock_spin(), rw_lock_x_lock_func(), srv_error_monitor_thread(), srv_lock_timeout_and_monitor_thread(), srv_master_thread(), srv_table_reserve_slot_for_mysql(), sync_array_cell_print(), sync_thread_levels_g(), thr_local_create(), thr_local_free(), thr_local_get(), trx_print(), ut_dbg_assertion_failed(), and ut_dbg_stop_thread().
00054 { 00055 #ifdef UNIV_HPUX10 00056 /* In HP-UX-10.20 a pthread_t is a struct of 3 fields: field1, field2, 00057 field3. We do not know if field1 determines the thread uniquely. */ 00058 00059 return((ulint)(a.field1)); 00060 #else 00061 return((ulint)a); 00062 #endif 00063 }
Here is the caller graph for this function:

| void os_thread_set_priority | ( | os_thread_t | handle, | |
| ulint | pri | |||
| ) |
Definition at line 286 of file os0thread.c.
References OS_THREAD_PRIORITY_ABOVE_NORMAL, OS_THREAD_PRIORITY_BACKGROUND, OS_THREAD_PRIORITY_NORMAL, ut_a, ut_error, and UT_NOT_USED.
00288 : OS handle to the thread */ 00289 ulint pri) /* in: priority */ 00290 { 00291 #ifdef __WIN__ 00292 int os_pri; 00293 00294 if (pri == OS_THREAD_PRIORITY_BACKGROUND) { 00295 os_pri = THREAD_PRIORITY_BELOW_NORMAL; 00296 } else if (pri == OS_THREAD_PRIORITY_NORMAL) { 00297 os_pri = THREAD_PRIORITY_NORMAL; 00298 } else if (pri == OS_THREAD_PRIORITY_ABOVE_NORMAL) { 00299 os_pri = THREAD_PRIORITY_HIGHEST; 00300 } else { 00301 ut_error; 00302 } 00303 00304 ut_a(SetThreadPriority(handle, os_pri)); 00305 #else 00306 UT_NOT_USED(handle); 00307 UT_NOT_USED(pri); 00308 #endif 00309 }
| void os_thread_sleep | ( | ulint | tm | ) |
Definition at line 264 of file os0thread.c.
References NULL.
Referenced by buf_LRU_get_free_block(), buf_LRU_invalidate_tablespace(), buf_page_get_gen(), buf_read_ibuf_merge_pages(), buf_read_recv_pages(), fil_delete_tablespace(), fil_flush(), fil_mutex_enter_and_prepare_for_io(), fil_rename_tablespace(), innobase_shutdown_for_mysql(), innobase_start_or_create_for_mysql(), logs_empty_and_mark_files_at_shutdown(), os_file_create(), os_file_delete(), os_file_delete_if_exists(), os_file_write(), os_thread_yield(), recv_apply_hashed_log_recs(), row_drop_database_for_mysql(), row_mysql_delay_if_needed(), row_purge_remove_clust_if_poss(), row_purge_remove_sec_if_poss(), row_undo_ins_remove_clust_rec(), row_undo_ins_remove_sec(), srv_conc_enter_innodb(), srv_error_monitor_thread(), srv_lock_timeout_and_monitor_thread(), srv_master_thread(), trx_general_rollback_for_mysql(), trx_rollback_or_clean_all_without_sess(), ut_dbg_stop_thread(), and ut_malloc_low().
00266 : time in microseconds */ 00267 { 00268 #ifdef __WIN__ 00269 Sleep((DWORD) tm / 1000); 00270 #elif defined(__NETWARE__) 00271 delay(tm / 1000); 00272 #else 00273 struct timeval t; 00274 00275 t.tv_sec = tm / 1000000; 00276 t.tv_usec = tm % 1000000; 00277 00278 select(0, NULL, NULL, NULL, &t); 00279 #endif 00280 }
Here is the caller graph for this function:

| void os_thread_yield | ( | void | ) |
Definition at line 244 of file os0thread.c.
References os_thread_sleep().
Referenced by btr_search_validate(), mutex_spin_wait(), rw_lock_s_lock_spin(), and rw_lock_x_lock_func().
00246 { 00247 #if defined(__WIN__) 00248 Sleep(0); 00249 #elif (defined(HAVE_SCHED_YIELD) && defined(HAVE_SCHED_H)) 00250 sched_yield(); 00251 #elif defined(HAVE_PTHREAD_YIELD_ZERO_ARG) 00252 pthread_yield(); 00253 #elif defined(HAVE_PTHREAD_YIELD_ONE_ARG) 00254 pthread_yield(0); 00255 #else 00256 os_thread_sleep(0); 00257 #endif 00258 }
Here is the call graph for this function:

Here is the caller graph for this function:

1.4.7

