#include <my_global.h>#include <tap.h>#include <my_sys.h>#include <my_atomic.h>Include dependency graph for my_atomic-t.c:

Go to the source code of this file.
Functions | |
| pthread_handler_t | test_atomic_add_handler (void *arg) |
| pthread_handler_t | test_atomic_swap_handler (void *arg) |
| pthread_handler_t | test_atomic_cas_handler (void *arg) |
| void | test_atomic (const char *test, pthread_handler handler, int n, int m) |
| int | main () |
Variables | |
| int32 | a32 |
| int32 | b32 |
| int32 | c32 |
| my_atomic_rwlock_t | rwl |
| pthread_attr_t | thr_attr |
| pthread_mutex_t | mutex |
| pthread_cond_t | cond |
| int | N |
| int main | ( | void | ) |
Definition at line 153 of file my_atomic-t.c.
References cond, diag(), err, exit_status(), mutex, my_atomic_initialize(), my_atomic_rwlock_destroy, my_atomic_rwlock_init, my_getncpus(), ok(), plan(), pthread_mutex_destroy, pthread_mutex_init, rwl, test_atomic(), test_atomic_add_handler(), test_atomic_cas_handler(), test_atomic_swap_handler(), and thr_attr.
00154 { 00155 int err; 00156 00157 diag("N CPUs: %d", my_getncpus()); 00158 err= my_atomic_initialize(); 00159 00160 plan(4); 00161 ok(err == 0, "my_atomic_initialize() returned %d", err); 00162 00163 pthread_attr_init(&thr_attr); 00164 pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); 00165 pthread_mutex_init(&mutex, 0); 00166 pthread_cond_init(&cond, 0); 00167 my_atomic_rwlock_init(&rwl); 00168 00169 test_atomic("my_atomic_add32", test_atomic_add_handler, 100,10000); 00170 test_atomic("my_atomic_swap32", test_atomic_swap_handler, 100,10000); 00171 test_atomic("my_atomic_cas32", test_atomic_cas_handler, 100,10000); 00172 00173 pthread_mutex_destroy(&mutex); 00174 pthread_cond_destroy(&cond); 00175 pthread_attr_destroy(&thr_attr); 00176 my_atomic_rwlock_destroy(&rwl); 00177 return exit_status(); 00178 }
Here is the call graph for this function:

| void test_atomic | ( | const char * | test, | |
| pthread_handler | handler, | |||
| int | n, | |||
| int | m | |||
| ) |
Definition at line 132 of file my_atomic-t.c.
References a32, b32, c32, cond, diag(), mutex, my_getsystime(), N, ok(), pthread_mutex_lock, pthread_mutex_unlock, and thr_attr.
Referenced by main().
00133 { 00134 pthread_t t; 00135 ulonglong now=my_getsystime(); 00136 00137 a32= 0; 00138 b32= 0; 00139 c32= 0; 00140 00141 diag("Testing %s with %d threads, %d iterations... ", test, n, m); 00142 for (N=n ; n ; n--) 00143 pthread_create(&t, &thr_attr, handler, &m); 00144 00145 pthread_mutex_lock(&mutex); 00146 while (N) 00147 pthread_cond_wait(&cond, &mutex); 00148 pthread_mutex_unlock(&mutex); 00149 now=my_getsystime()-now; 00150 ok(a32 == 0, "tested %s in %g secs", test, ((double)now)/1e7); 00151 }
Here is the call graph for this function:

Here is the caller graph for this function:

| pthread_handler_t test_atomic_add_handler | ( | void * | arg | ) |
Definition at line 31 of file my_atomic-t.c.
References a32, cond, mutex, my_atomic_rwlock_wrlock, my_atomic_rwlock_wrunlock, N, pthread_mutex_lock, pthread_mutex_unlock, rwl, and x.
Referenced by main().
00032 { 00033 int m=*(int *)arg; 00034 int32 x; 00035 for (x=((int)(&m)); m ; m--) 00036 { 00037 x=x*m+0x87654321; 00038 my_atomic_rwlock_wrlock(&rwl); 00039 my_atomic_add32(&a32, x); 00040 my_atomic_rwlock_wrunlock(&rwl); 00041 00042 my_atomic_rwlock_wrlock(&rwl); 00043 my_atomic_add32(&a32, -x); 00044 my_atomic_rwlock_wrunlock(&rwl); 00045 } 00046 pthread_mutex_lock(&mutex); 00047 N--; 00048 if (!N) pthread_cond_signal(&cond); 00049 pthread_mutex_unlock(&mutex); 00050 return 0; 00051 }
Here is the caller graph for this function:

| pthread_handler_t test_atomic_cas_handler | ( | void * | arg | ) |
Definition at line 103 of file my_atomic-t.c.
References a32, cond, mutex, my_atomic_rwlock_wrlock, my_atomic_rwlock_wrunlock, N, ok(), pthread_mutex_lock, pthread_mutex_unlock, rwl, and x.
Referenced by main().
00104 { 00105 int m=*(int *)arg, ok; 00106 int32 x,y; 00107 for (x=((int)(&m)); m ; m--) 00108 { 00109 my_atomic_rwlock_wrlock(&rwl); 00110 y=my_atomic_load32(&a32); 00111 my_atomic_rwlock_wrunlock(&rwl); 00112 00113 x=x*m+0x87654321; 00114 do { 00115 my_atomic_rwlock_wrlock(&rwl); 00116 ok=my_atomic_cas32(&a32, &y, y+x); 00117 my_atomic_rwlock_wrunlock(&rwl); 00118 } while (!ok); 00119 do { 00120 my_atomic_rwlock_wrlock(&rwl); 00121 ok=my_atomic_cas32(&a32, &y, y-x); 00122 my_atomic_rwlock_wrunlock(&rwl); 00123 } while (!ok); 00124 } 00125 pthread_mutex_lock(&mutex); 00126 N--; 00127 if (!N) pthread_cond_signal(&cond); 00128 pthread_mutex_unlock(&mutex); 00129 return 0; 00130 }
Here is the call graph for this function:

Here is the caller graph for this function:

| pthread_handler_t test_atomic_swap_handler | ( | void * | arg | ) |
Definition at line 61 of file my_atomic-t.c.
References a32, b32, c32, cond, mutex, my_atomic_rwlock_wrlock, my_atomic_rwlock_wrunlock, N, pthread_mutex_lock, pthread_mutex_unlock, rwl, and x.
Referenced by main().
00062 { 00063 int m=*(int *)arg; 00064 int32 x; 00065 00066 my_atomic_rwlock_wrlock(&rwl); 00067 x=my_atomic_add32(&b32, 1); 00068 my_atomic_rwlock_wrunlock(&rwl); 00069 00070 my_atomic_rwlock_wrlock(&rwl); 00071 my_atomic_add32(&a32, x); 00072 my_atomic_rwlock_wrunlock(&rwl); 00073 00074 for (; m ; m--) 00075 { 00076 my_atomic_rwlock_wrlock(&rwl); 00077 x=my_atomic_swap32(&c32, x); 00078 my_atomic_rwlock_wrunlock(&rwl); 00079 } 00080 00081 if (!x) 00082 { 00083 my_atomic_rwlock_wrlock(&rwl); 00084 x=my_atomic_swap32(&c32, x); 00085 my_atomic_rwlock_wrunlock(&rwl); 00086 } 00087 00088 my_atomic_rwlock_wrlock(&rwl); 00089 my_atomic_add32(&a32, -x); 00090 my_atomic_rwlock_wrunlock(&rwl); 00091 00092 pthread_mutex_lock(&mutex); 00093 N--; 00094 if (!N) pthread_cond_signal(&cond); 00095 pthread_mutex_unlock(&mutex); 00096 return 0; 00097 }
Here is the caller graph for this function:

| int32 a32 |
Definition at line 22 of file my_atomic-t.c.
Referenced by test_atomic(), test_atomic_add_handler(), test_atomic_cas_handler(), and test_atomic_swap_handler().
| int32 b32 |
Definition at line 22 of file my_atomic-t.c.
Referenced by test_atomic(), and test_atomic_swap_handler().
| int32 c32 |
Definition at line 22 of file my_atomic-t.c.
Referenced by test_atomic(), and test_atomic_swap_handler().
| pthread_cond_t cond |
Definition at line 27 of file my_atomic-t.c.
Referenced by sp_instr_hpush_jump::add_condition(), add_found_match_trig_cond(), add_ft_keys(), add_key_equal_fields(), add_key_field(), add_key_fields(), add_ref_to_table_cond(), and_items(), build_equal_items(), build_equal_items_for_cond(), change_cond_ref_to_const(), check_group_min_max_predicates(), handler::cond_push(), const_expression_in_where(), eliminate_item_equal(), eval_const_cond(), fill_schema_files(), sp_rcontext::find_handler(), sp_pcontext::find_handler(), find_key_for_maxmin(), get_all_tables(), get_mm_tree(), APZJobBuffer::insert(), Dbtup::interpreterNextLab(), main(), make_cond_for_info_schema(), make_cond_for_table(), make_join_select(), matching_cond(), maxmin_in_range(), mysql_ha_read(), opt_classify_comparison(), opt_find_test_conds(), opt_normalize_cmp_conds(), prepare_select_for_name(), prepare_simple_select(), print_where(), propagate_cond_constants(), sp_rcontext::push_handler(), sp_pcontext::push_handler(), reckey_in_range(), remove_const(), remove_eq_conds(), APZJobBuffer::retrieve(), row_sel_open_pcur(), row_sel_test_end_conds(), row_sel_test_other_conds(), substitute_for_best_equal_field(), test_atomic(), test_atomic_add_handler(), test_atomic_cas_handler(), test_atomic_swap_handler(), update_const_equal_items(), update_ref_and_keys(), and Item_func_sleep::val_int().
| pthread_mutex_t mutex |
Definition at line 26 of file my_atomic-t.c.
Referenced by Dbdict::alterTable_backup_mutex_locked(), Dbdih::createMutex_done(), Dbdih::createMutexes(), Dbdict::createTab_reply(), Backup::defineBackupMutex_locked(), Dbdict::dropTable_backup_mutex_locked(), Dbdict::execALTER_TABLE_REQ(), Dbdih::execCOPY_ACTIVECONF(), Dbdih::execCREATE_FRAGCONF(), Dbdict::execDROP_TABLE_REQ(), Dbdih::execSTART_LCP_CONF(), Dbdih::execSTOP_PERM_REQ(), Backup::execUTIL_SEQUENCE_CONF(), main(), mutex_create_func(), mutex_enter_noninline(), mutex_enter_nowait(), mutex_exit_noninline(), mutex_free(), mutex_set_waiters(), mutex_signal_object(), mutex_spin_wait(), mutex_validate(), my_close(), my_lock(), my_pread(), my_pwrite(), my_register_filename(), os_mutex_create(), os_mutex_enter(), os_mutex_exit(), os_mutex_free(), os_sync_free(), Dbdih::startLcpMutex_unlocked(), Dbdih::startLcpRoundLab(), Dbdih::switchPrimaryMutex_locked(), Dbdih::switchReplica(), sync_arr_cell_can_wake_up(), sync_array_cell_print(), sync_close(), sync_thread_levels_g(), test_atomic(), test_atomic_add_handler(), test_atomic_cas_handler(), and test_atomic_swap_handler().
| int N |
Definition at line 28 of file my_atomic-t.c.
Definition at line 23 of file my_atomic-t.c.
Referenced by main(), test_atomic_add_handler(), test_atomic_cas_handler(), and test_atomic_swap_handler().
| pthread_attr_t thr_attr |
Definition at line 25 of file my_atomic-t.c.
Referenced by main(), mi_repair_parallel(), start_signal_handler(), and test_atomic().
1.4.7
