/* pin allocator - alloc and release an element in a loop */ pthread_handler_t test_lf_pinbox(void *arg) { int m= *(int *)arg; int32 x= 0; LF_PINS *pins; if (with_my_thread_init) my_thread_init(); pins= lf_pinbox_get_pins(&lf_allocator.pinbox); for (x= ((int)(intptr)(&m)); m ; m--) { lf_pinbox_put_pins(pins); pins= lf_pinbox_get_pins(&lf_allocator.pinbox); } lf_pinbox_put_pins(pins); pthread_mutex_lock(&mutex); if (!--running_threads) pthread_cond_signal(&cond); pthread_mutex_unlock(&mutex); if (with_my_thread_init) my_thread_end(); return 0; }
pthread_handler_t test_lf_hash(void *arg) { int m= (*(int *)arg)/(2*N_TLH); int32 x,y,z,sum= 0, ins= 0, scans= 0; LF_PINS *pins; if (with_my_thread_init) my_thread_init(); pins= lf_hash_get_pins(&lf_hash); for (x= ((int)(intptr)(&m)); m ; m--) { int i; y= x; for (i= 0; i < N_TLH; i++) { x= (x*(m+i)+0x87654321) & INT_MAX32; z= (x<0) ? -x : x; if (lf_hash_insert(&lf_hash, pins, &z)) { sum+= z; ins++; } else { int unused= 0; lf_hash_iterate(&lf_hash, pins, do_sum, &unused); scans++; } } for (i= 0; i < N_TLH; i++) { y= (y*(m+i)+0x87654321) & INT_MAX32; z= (y<0) ? -y : y; if (lf_hash_delete(&lf_hash, pins, (uchar *)&z, sizeof(z))) sum-= z; } } lf_hash_put_pins(pins); pthread_mutex_lock(&mutex); bad+= sum; inserts+= ins; if (--N == 0) { diag("%d mallocs, %d pins in stack, %d hash size, %d inserts, %d scans", lf_hash.alloc.mallocs, lf_hash.alloc.pinbox.pins_in_array, lf_hash.size, inserts, scans); bad|= lf_hash.count; } if (!--running_threads) pthread_cond_signal(&cond); pthread_mutex_unlock(&mutex); if (with_my_thread_init) my_thread_end(); return 0; }
static TDHS_INLINE void destory_thd(THD *thd) { tb_assert(thd!=NULL); my_pthread_setspecific_ptr(THR_THD, 0); tdhs_mysql_mutex_lock(&LOCK_thread_count); delete thd; --thread_count; tdhs_mysql_mutex_unlock(&LOCK_thread_count); my_thread_end(); (void) tdhs_mysql_cond_broadcast(&COND_thread_count); }
static void *audit_log_flush_worker(void *arg) { audit_log_buffer_t *log= (audit_log_buffer_t*) arg; my_thread_init(); while (!(log->stop && log->flush_pos == log->write_pos)) { audit_log_flush(log); } my_thread_end(); return NULL; }
void * thread_routine_2(void * arg) { int tmp; my_thread_start(); my_mutex_lock(&B); printf("thread 2 : lock (B)\n"); my_obj_read(&data); tmp = data; my_mutex_unlock(&B); printf("thread 2 : unlock (B)\n"); my_thread_end(); return 0; }
pthread_handler_t test_lf_alloc(void *arg) { int m= (*(int *)arg)/2; int32 x,y= 0; LF_PINS *pins; if (with_my_thread_init) my_thread_init(); pins= lf_alloc_get_pins(&lf_allocator); for (x= ((int)(intptr)(&m)); m ; m--) { TLA *node1, *node2; x= (x*m+0x87654321) & INT_MAX32; node1= (TLA *)lf_alloc_new(pins); node1->data= x; y+= node1->data; node1->data= 0; node2= (TLA *)lf_alloc_new(pins); node2->data= x; y-= node2->data; node2->data= 0; lf_alloc_free(pins, node1); lf_alloc_free(pins, node2); } lf_alloc_put_pins(pins); pthread_mutex_lock(&mutex); bad+= y; if (--N == 0) { diag("%d mallocs, %d pins in stack", lf_allocator.mallocs, lf_allocator.pinbox.pins_in_array); #ifdef MY_LF_EXTRA_DEBUG bad|= lf_allocator.mallocs - lf_alloc_pool_count(&lf_allocator); #endif } if (!--running_threads) pthread_cond_signal(&cond); pthread_mutex_unlock(&mutex); if (with_my_thread_init) my_thread_end(); return 0; }
void * thread_routine_3(void * arg) { int tmp; my_thread_start(); my_mutex_lock(&C); printf("thread 1 : lock (A)\n"); my_obj_write(&data); data = tmp+1; my_mutex_unlock(&C); printf("thread 1 : unlock (A)\n"); my_thread_end(); return 0; }
pthread_handler_t ThreadOpen(void *p) { PTBMT cmp = (PTBMT)p; if (!my_thread_init()) { set_current_thd(cmp->Thd); // Try to open the connection if (!cmp->Tap->GetTo_Tdb()->OpenDB(cmp->G)) { cmp->Ready = true; } else cmp->Rc = RC_FX; my_thread_end(); } else cmp->Rc = RC_FX; return NULL; } // end of ThreadOpen
static void *test_thread_writer(void *arg) { int param=*((int*) arg); my_thread_init(); { DBUG_ENTER_NO_RETURN("test_writer"); writer(param); DBUG_PRINT("info", ("Thread %s ended", my_thread_name())); pthread_mutex_lock(&LOCK_thread_count); ok(1, "writer%d: done", param); thread_count--; pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */ pthread_mutex_unlock(&LOCK_thread_count); free((uchar*) arg); my_thread_end(); } return 0; }
void * thread_routine_1(void * arg) { int tmp; my_thread_start(); my_mutex_lock(&A); printf("thread 1 : lock (A)\n"); my_obj_read(&data1); tmp = data1; my_obj_write(&data2); data2 = tmp+1; my_mutex_unlock(&A); printf("thread 1 : unlock (A)\n"); my_thread_end(); return 0; }
static void * timer_notify_thread_func(void *arg) { sigset_t set; siginfo_t info; my_timer_t *timer; pthread_barrier_t *barrier= arg; my_thread_init(); sigemptyset(&set); sigaddset(&set, MY_TIMER_EVENT_SIGNO); sigaddset(&set, MY_TIMER_KILL_SIGNO); /* Get the thread ID of the current thread. */ timer_notify_thread_id= (pid_t) syscall(SYS_gettid); /* Wake up parent thread, timer_notify_thread_id is available. */ pthread_barrier_wait(barrier); while (1) { if (sigwaitinfo(&set, &info) < 0) continue; if (info.si_signo == MY_TIMER_EVENT_SIGNO) { timer= (my_timer_t*)info.si_value.sival_ptr; timer->notify_function(timer); } else if (info.si_signo == MY_TIMER_KILL_SIGNO) break; } my_thread_end(); return NULL; }
void * thread_routine_2(void * arg) { int tmp; my_thread_start(); my_mutex_lock(&B); printf("thread 2 : lock (B)\n"); my_obj_read(&data2); tmp = data2; my_mutex_lock(&A); printf("thread 2 : lock (A)\n"); my_obj_write(&data1); data1 = tmp-1; my_mutex_unlock(&A); printf("thread 2 : unlock (A)\n"); my_mutex_unlock(&B); printf("thread 2 : unlock (B)\n"); my_thread_end(); return 0; }
BOOL APIENTRY LibMain(HANDLE hInst,DWORD ul_reason_being_called, LPVOID lpReserved) { switch (ul_reason_being_called) { case DLL_PROCESS_ATTACH: /* case of libentry call in win 3.x */ if (!inited++) { s_hModule=hInst; libmysql_init(); main_thread=GetCurrentThreadId(); } break; case DLL_THREAD_ATTACH: threads++; my_thread_init(); break; case DLL_PROCESS_DETACH: /* case of wep call in win 3.x */ if (!--inited) /* Safety */ { /* my_thread_init() */ /* This may give extra safety */ my_end(0); } break; case DLL_THREAD_DETACH: /* Main thread will free by my_end() */ threads--; if (main_thread != GetCurrentThreadId()) my_thread_end(); break; default: break; } /* switch */ return TRUE; UNREFERENCED_PARAMETER(lpReserved); } /* LibMain */
pthread_handler_t test_trnman(void *arg) { uint x, y, i, n; TRN *trn[MAX_ITER]; int m= (*(int *)arg); if (my_thread_init()) BAIL_OUT("my_thread_init failed!"); for (x= ((int)(intptr)(&m)); m > 0; ) { y= x= (x*3628273133LL + 1500450271LL) % 9576890767LL; /* three prime numbers */ m-= n= x % MAX_ITER; for (i= 0; i < n; i++) { trn[i]= trnman_new_trn(0); if (!trn[i]) { diag("trnman_new_trn() failed"); litmus++; } } for (i= 0; i < n; i++) { y= (y*19 + 7) % 31; trnman_end_trn(trn[i], y & 1); } } pthread_mutex_lock(&rt_mutex); rt_num_threads--; pthread_mutex_unlock(&rt_mutex); my_thread_end(); return 0; }
static TDHS_INLINE THD* init_THD(char* db, const void *stack_bottom, bool need_write) { THD *thd = NULL; my_thread_init(); thd = new THD; if (thd == NULL) { my_thread_end(); return NULL; } thd->thread_stack = (char*) stack_bottom; easy_debug_log("TDHS:thread_stack = %p sizeof(THD)=%zu sizeof(mtx)=%zu ", thd->thread_stack, sizeof(THD), sizeof(LOCK_thread_count)); thd->store_globals(); thd->system_thread = static_cast<enum_thread_type>(1 << 30UL); const NET v = { 0 }; thd->net = v; if (need_write) { //for write #if MYSQL_VERSION_ID >= 50505 thd->variables.option_bits |= OPTION_BIN_LOG; #else thd->options |= OPTION_BIN_LOG; #endif } //for db safeFree(thd->db); thd->db = db; my_pthread_setspecific_ptr(THR_THD, thd); tdhs_mysql_mutex_lock(&LOCK_thread_count); thd->thread_id = thread_id++; threads.append(thd); ++thread_count; tdhs_mysql_mutex_unlock(&LOCK_thread_count); return thd; }
void *issueAdd(void *arg) { int mysocfd = (int) arg; struct betaler_keywords_visninger_format { int kid; int betaler_side_id; }; struct betaler_keywords_visninger_format betaler_keywords_visninger[10]; char buff[1024]; struct timeval globalstart_time, globalend_time; unsigned int addid; char *strpointer; int siderType_ppctopNr,siderType_ppcsideNr; struct queryNodeHederFormat queryNodeHeder; char queryEscaped[MaxQueryLen*2+1]; char ppcprovider[32]; int i,n, y, net_status, showabal;; //sjekker vårt egent anonsesystem char mysql_query [2048]; static MYSQL demo_db; MYSQL_RES *mysqlres; /* To be used to fetch information into */ MYSQL_ROW mysqlrow; struct SiderHederFormat SiderHeder; struct ppcPagesFormat ppcPages[10]; struct SiderFormat *Sider; gettimeofday(&globalstart_time, NULL); if ((i=recv(mysocfd, &queryNodeHeder, sizeof(queryNodeHeder),MSG_WAITALL)) == -1) { perror("recv"); } printf("Query %s\n",queryNodeHeder.query); Sider = (struct SiderFormat *)malloc(sizeof(struct SiderFormat) * (queryNodeHeder.MaxsHits)); //setter alle sidene som sletett for (i=0;i<queryNodeHeder.MaxsHits;i++) { Sider[i].deletet = 1; } //sender svar med en gang at vi kan gjøre dette net_status = net_CanDo; if ((n=sendall(mysocfd,&net_status, sizeof(net_status))) != sizeof(net_status)) { printf("send only %i of %i\n",n,sizeof(net_status)); perror("sendall net_status"); } /********************************************************************************************/ #ifdef DEBUG printf("sending query to ppc db\n"); #endif mysql_init(&demo_db); #ifdef WITH_THREAD my_thread_init(); // kalt mysql_thread_init() i mysql 5.0 #endif //if(!mysql_real_connect(&demo_db, "www2.boitho.com", "boitho_remote", "G7J7v5L5Y7", "boitho", 3306, NULL, 0)){ if(!mysql_real_connect(&demo_db, "localhost", "boitho", "G7J7v5L5Y7", "boithoweb", 3306, NULL, 0)){ printf(mysql_error(&demo_db)); //return(1); pthread_exit((void *)1); /* exit with status */ } //escaper queryet rikit mysql_real_escape_string(&demo_db,queryEscaped,queryNodeHeder.query,strlen(queryNodeHeder.query)); sprintf(mysql_query, "select tittel,url,beskrivelse,betaler_sider.bruker_navn,betaler_keywords.betaler,betaler_keywords.kid,betaler_sider.id from betaler_keywords,betaler_sider where betaler_keywords.keyword ='%s' and betaler_keywords.betaler_side_id=betaler_sider.id order by betaler desc",queryEscaped); if(mysql_real_query(&demo_db, mysql_query, strlen(mysql_query))){ /* Make query */ printf(mysql_error(&demo_db)); //return(1); pthread_exit((void *)1); /* exit with status */ } #ifdef DEBUG printf("sending query to ppc db end\n"); #endif /********************************************************************************************/ SiderHeder.TotaltTreff = 0; int nrOfppcPages = 0; int nrOfBoithoAds = 0; //printer ut eventuelt ppc ord mysqlres=mysql_store_result(&demo_db); /* Download result from server */ while ((mysqlrow=mysql_fetch_row(mysqlres)) != NULL) { /* Get a row from the results */ //printf("\t<beskrivelse>%s</beskrivelse>\n",mysqlrow[2]); //Sider[showabal].type = siderType_ppctop; strncpy(ppcPages[nrOfppcPages].title,mysqlrow[0],sizeof(ppcPages[nrOfppcPages].title)); strncpy(ppcPages[nrOfppcPages].url,mysqlrow[1],sizeof(ppcPages[nrOfppcPages].url)); strncpy(ppcPages[nrOfppcPages].uri,mysqlrow[1],sizeof(ppcPages[nrOfppcPages].uri)); strncpy(ppcPages[nrOfppcPages].description,mysqlrow[2],sizeof(ppcPages[nrOfppcPages].description)); strncpy(ppcPages[nrOfppcPages].user,mysqlrow[3],sizeof(ppcPages[nrOfppcPages].user)); ppcPages[nrOfppcPages].thumbnail[0] = '\0'; ppcPages[nrOfppcPages].bid = atof(mysqlrow[4]); ppcPages[nrOfppcPages].keyword_id = atoi(mysqlrow[5]); ppcPages[nrOfppcPages].DocID = strtoul(mysqlrow[6], (char **)NULL, 10); ppcPages[nrOfppcPages].allrank = 10000; #ifdef DEBUG printf("aa bid %f\n",ppcPages[nrOfppcPages].bid); printf("\tUrl: %s\n",ppcPages[nrOfppcPages].url); printf("\tTitle: %s\n",ppcPages[nrOfppcPages].title); printf("keyword_id -%s-\n",mysqlrow[5]); #endif betaler_keywords_visninger[nrOfBoithoAds].kid = ppcPages[nrOfppcPages].keyword_id; betaler_keywords_visninger[nrOfBoithoAds].betaler_side_id = ppcPages[nrOfppcPages].DocID; ++nrOfppcPages; ++nrOfBoithoAds; } mysql_free_result(mysqlres); /*********************************/ printf("contry: %s\n",queryNodeHeder.GeoIPcontry); if (strcmp(queryNodeHeder.GeoIPcontry,"NO") == 0) { strcpy(ppcprovider,"hent"); //strcpy(ppcprovider,"revenuepilot"); } else { //alle språk //strcpy(ppcprovider,"revenuepilot"); //strcpy(ppcprovider,"searchboss"); } strcpy(ppcprovider,"amazon"); //temp: skrur av 3p xml feeds //getPpcAds(ppcprovider,ppcPages,&nrOfppcPages,&queryNodeHeder); //temp: Viser en mindre side da vi får problemer med siste? //nrOfppcPages--; showabal = 0; for (i=0;i<nrOfppcPages;i++) { /*********************************************/ //Sider[showabal].type = siderType_ppcside; #ifdef DEBUG printf("issue add. keyword_id %i\n",ppcPages[i].keyword_id); #endif sprintf(mysql_query, "insert into issuedadds values(%s,'%s','%f','%s',%s,'%s','%s','%s','%s','%s','%s','%s','%i','%i')", "NULL", queryEscaped, ppcPages[i].bid, ppcPages[i].uri, "NOW()", 0, ppcPages[i].user, queryNodeHeder.search_user, queryNodeHeder.userip, queryNodeHeder.HTTP_ACCEPT_LANGUAGE, queryNodeHeder.HTTP_USER_AGENT, queryNodeHeder.HTTP_REFERER, ppcPages[i].keyword_id, ppcPages[i].DocID ); #ifdef DEBUG printf("ppc user %s\naffuser %s\n",Sider[i].user,queryNodeHeder.search_user); #endif if(mysql_real_query(&demo_db, mysql_query, strlen(mysql_query))){ /* Make query */ printf("Cant insert into issuedadds: %s\nSql query vas %s\n",mysql_error(&demo_db),mysql_query); //return(1); pthread_exit((void *)1); /* exit with status */ } addid = mysql_insert_id(&demo_db); #ifdef DEBUG printf("addid %u\n",addid); #endif //sprintf(ppcPages[showabal].uri,"http://search.boitho.com/cgi-bin/addout.cgi?addid=%u&addurl=%s",addid,ppcPages[showabal].url); sprintf(ppcPages[showabal].uri,"http://bbh-001.boitho.com/cgi-bin/addout.cgi?addid=%u&addurl=%s",addid,ppcPages[showabal].url); //strcpy(Sider[i].uri,buff); /*********************************************/ if (strlen(ppcPages[i].title) == (sizeof(ppcPages[i].title) -1)) { //strcpy(Sider[showabal].title,"Title to long."); strncpy(Sider[showabal].title,ppcPages[i].title,sizeof(Sider[showabal].title) -3); strcat(Sider[showabal].title,".."); } else { strncpy(Sider[showabal].title,ppcPages[i].title,sizeof(Sider[showabal].title)); } strncpy(Sider[showabal].description,ppcPages[i].description,sizeof(Sider[showabal].description)); strncpy(Sider[showabal].url,ppcPages[i].url,sizeof(Sider[showabal].url)); strncpy(Sider[showabal].uri,ppcPages[i].uri,sizeof(Sider[showabal].uri)); strncpy(Sider[showabal].user,ppcPages[i].user,sizeof(Sider[showabal].user)); strscpy(Sider[showabal].domain,ppcPages[i].domain,sizeof(Sider[showabal].domain)); strscpy(Sider[showabal].thumbnale,ppcPages[i].thumbnail,sizeof(Sider[showabal].thumbnale)); Sider[showabal].thumbnailwidth = atol(ppcPages[i].thumbnailwidth); Sider[showabal].thumbnailheight = atol(ppcPages[i].thumbnailheight); Sider[showabal].bid = ppcPages[i].bid; Sider[showabal].iindex.allrank = ppcPages[i].allrank; #ifdef DEBUG printf("%s\t%s\t%f\n",Sider[showabal].url,Sider[showabal].title,ppcPages[i].bid); #endif ++showabal; } /*********************************/ siderType_ppctopNr = 0; siderType_ppcsideNr = 0; for(i=0;i<showabal;i++) { #ifdef DEBUG printf("uri %s\n",Sider[i].uri); #endif Sider[i].DocumentIndex.crc32 = crc32boitho(Sider[i].description); Sider[i].deletet = 0; //lager fin beskrivlse som slutter på .. isteden får bare et kappet ord, hvis beskrivlese er for lang if (strlen(Sider[i].description) >= 250) { //søker oss til siste space , eller ; og avslutter der if ((strpointer = (char *)strrchr(Sider[i].description,' ')) != NULL) { strpointer[0] = '\0'; } else if ((strpointer = (char *)strrchr(Sider[i].description,';')) != NULL) { ++strpointer; //pekeren peker på semikolonet. SKal ha det med, så må legge il en strpointer[0] = '\0'; } strncat(Sider[i].description,"..",2); } //hiliter ordet sprintf(buff,"<b>%s</b>",queryNodeHeder.query); strcasesandr(Sider[i].description,sizeof(Sider[i].description),queryNodeHeder.query,buff); //bestemmer ppc type //Sider[showabal].type = siderType_ppcside //Sider[i].type = siderType_ppctop; if ((siderType_ppctopNr < 2) && (strcasestr(Sider[i].description,queryNodeHeder.query) != 0)) { Sider[i].type = siderType_ppctop; ++siderType_ppctopNr; } else { Sider[i].type = siderType_ppcside; ++siderType_ppcsideNr; } } //legger datane in i mysql database. for(i=0;i<showabal;i++) { } gettimeofday(&globalend_time, NULL); SiderHeder.total_usecs = getTimeDifference(&globalstart_time,&globalend_time); SiderHeder.TotaltTreff = showabal; SiderHeder.showabal = showabal; SiderHeder.filtered = 0; SiderHeder.hiliteQuery[0] = '\0'; sprintf(SiderHeder.servername,"adserver.boitho.com"); //SiderHeder.queryTime = 0; if ((n=sendall(mysocfd,&SiderHeder, sizeof(SiderHeder))) != sizeof(SiderHeder)) { printf("send only %i of %i\n",n,sizeof(SiderHeder)); perror("sendall SiderHeder"); } for(i=0;i<SiderHeder.showabal;i++) { //for (i=0;i<queryNodeHeder.MaxsHits;i++) { #ifdef DEBUG printf("sending %s, deletet %i\n",Sider[i].url,Sider[i].deletet); printf("bb: -%s-\n",Sider[i].title); printf("url: -%s-\n",Sider[i].url); #endif //if (!Sider[i].deletet) { if ((n=sendall(mysocfd,&Sider[i], sizeof(struct SiderFormat))) != sizeof(struct SiderFormat)) { printf("send only %i of %i\n",n,sizeof(struct SiderFormat)); perror("sendall"); } //} } //logger alle visningene vi har hatt på egen ppc ord for (i=0;i<nrOfBoithoAds;i++) { sprintf(mysql_query, "insert DELAYED into betaler_keywords_visninger values(NULL,'%i','%i',NOW())",betaler_keywords_visninger[i].kid,betaler_keywords_visninger[i].betaler_side_id); if(mysql_real_query(&demo_db, mysql_query, strlen(mysql_query))){ /* Make query */ printf(mysql_error(&demo_db)); //return(1); pthread_exit((void *)0); /* exit with status */ } } mysql_close(&demo_db); //close(mysocfd); free(Sider); close(mysocfd); #ifdef WITH_THREAD my_thread_end(); // kalt mysql_thread_end() i mysql 5.0 pthread_exit((void *)0); /* exit with status */ #endif printf("end\n"); //return 0; }
void my_end(int infoflag) { /* this code is suboptimal to workaround a bug in Sun CC: Sun C++ 5.6 2004/06/02 for x86, and should not be optimized until this compiler is not in use anymore */ FILE *info_file= DBUG_FILE; my_bool print_info= (info_file != stderr); DBUG_ENTER("my_end"); if (!info_file) { info_file= stderr; print_info= 0; } DBUG_PRINT("info",("Shutting down: print_info: %d", print_info)); if ((infoflag & MY_CHECK_ERROR) || print_info) { /* Test if some file is left open */ if (my_file_opened | my_stream_opened) { sprintf(errbuff[0],EE(EE_OPEN_WARNING),my_file_opened,my_stream_opened); (void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL); DBUG_PRINT("error",("%s",errbuff[0])); } } free_charsets(); my_once_free(); if ((infoflag & MY_GIVE_INFO) || print_info) { #ifdef HAVE_GETRUSAGE struct rusage rus; #ifdef HAVE_purify /* Purify assumes that rus is uninitialized after getrusage call */ bzero((char*) &rus, sizeof(rus)); #endif if (!getrusage(RUSAGE_SELF, &rus)) fprintf(info_file,"\n\ User time %.2f, System time %.2f\n\ Maximum resident set size %ld, Integral resident set size %ld\n\ Non-physical pagefaults %ld, Physical pagefaults %ld, Swaps %ld\n\ Blocks in %ld out %ld, Messages in %ld out %ld, Signals %ld\n\ Voluntary context switches %ld, Involuntary context switches %ld\n", (rus.ru_utime.tv_sec * SCALE_SEC + rus.ru_utime.tv_usec / SCALE_USEC) / 100.0, (rus.ru_stime.tv_sec * SCALE_SEC + rus.ru_stime.tv_usec / SCALE_USEC) / 100.0, rus.ru_maxrss, rus.ru_idrss, rus.ru_minflt, rus.ru_majflt, rus.ru_nswap, rus.ru_inblock, rus.ru_oublock, rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals, rus.ru_nvcsw, rus.ru_nivcsw); #endif #if ( defined(MSDOS) || defined(__NETWARE__) ) && !defined(__WIN__) fprintf(info_file,"\nRun time: %.1f\n",(double) clock()/CLOCKS_PER_SEC); #endif #if defined(SAFEMALLOC) TERMINATE(stderr); /* Give statistic on screen */ #elif defined(__WIN__) && defined(_MSC_VER) _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR ); _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR ); _CrtCheckMemory(); _CrtDumpMemoryLeaks(); #endif } #ifdef THREAD DBUG_POP(); /* Must be done before my_thread_end */ my_thread_end(); my_thread_global_end(); #if defined(SAFE_MUTEX) /* Check on destroying of mutexes. A few may be left that will get cleaned up by C++ destructors */ safe_mutex_end(infoflag & MY_GIVE_INFO ? stderr : (FILE *) 0); #endif /* defined(SAFE_MUTEX) */ #endif /* THREAD */ #ifdef __WIN__ if (have_tcpip) WSACleanup(); #endif /* __WIN__ */ my_init_done=0; } /* my_end */
void my_end(int infoflag) { /* this code is suboptimal to workaround a bug in Sun CC: Sun C++ 5.6 2004/06/02 for x86, and should not be optimized until this compiler is not in use anymore */ FILE *info_file= DBUG_FILE; my_bool print_info= (info_file != stderr); if (!my_init_done) return; /* We do not use DBUG_ENTER here, as after cleanup DBUG is no longer operational, so we cannot use DBUG_RETURN. */ DBUG_PRINT("info",("Shutting down: infoflag: %d print_info: %d", infoflag, print_info)); if (!info_file) { info_file= stderr; print_info= 0; } if ((infoflag & MY_CHECK_ERROR) || print_info) { /* Test if some file is left open */ if (my_file_opened | my_stream_opened) { char ebuff[512]; my_snprintf(ebuff, sizeof(ebuff), EE(EE_OPEN_WARNING), my_file_opened, my_stream_opened); my_message_stderr(EE_OPEN_WARNING, ebuff, ME_BELL); DBUG_PRINT("error", ("%s", ebuff)); my_print_open_files(); } } free_charsets(); my_error_unregister_all(); my_once_free(); if ((infoflag & MY_GIVE_INFO) || print_info) { #ifdef HAVE_GETRUSAGE struct rusage rus; #ifdef HAVE_purify /* Purify assumes that rus is uninitialized after getrusage call */ bzero((char*) &rus, sizeof(rus)); #endif if (!getrusage(RUSAGE_SELF, &rus)) fprintf(info_file,"\n\ User time %.2f, System time %.2f\n\ Maximum resident set size %ld, Integral resident set size %ld\n\ Non-physical pagefaults %ld, Physical pagefaults %ld, Swaps %ld\n\ Blocks in %ld out %ld, Messages in %ld out %ld, Signals %ld\n\ Voluntary context switches %ld, Involuntary context switches %ld\n", (rus.ru_utime.tv_sec * SCALE_SEC + rus.ru_utime.tv_usec / SCALE_USEC) / 100.0, (rus.ru_stime.tv_sec * SCALE_SEC + rus.ru_stime.tv_usec / SCALE_USEC) / 100.0, rus.ru_maxrss, rus.ru_idrss, rus.ru_minflt, rus.ru_majflt, rus.ru_nswap, rus.ru_inblock, rus.ru_oublock, rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals, rus.ru_nvcsw, rus.ru_nivcsw); #endif #if defined(__WIN__) && defined(_MSC_VER) _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR ); _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR ); _CrtCheckMemory(); _CrtDumpMemoryLeaks(); #endif } if (!(infoflag & MY_DONT_FREE_DBUG)) { DBUG_END(); /* Must be done before my_thread_end */ } my_thread_end(); my_thread_global_end(); #if defined(SAFE_MUTEX) /* Check on destroying of mutexes. A few may be left that will get cleaned up by C++ destructors */ safe_mutex_end((infoflag & (MY_GIVE_INFO | MY_CHECK_ERROR)) ? stderr : (FILE *) 0); #endif /* defined(SAFE_MUTEX) */ #ifdef __WIN__ if (have_tcpip) WSACleanup(); #endif /* __WIN__ */ my_init_done=0; } /* my_end */
/* stress test: wait on a random number of random threads. it always succeeds (unless crashes or hangs). */ pthread_handler_t test_wt(void *arg) { int m, n, i, id, res; struct my_rnd_struct rand; my_thread_init(); mysql_mutex_lock(&mutex); id= cnt++; wt_thd_lazy_init(& thds[id].thd, & wt_deadlock_search_depth_short, & wt_timeout_short, & wt_deadlock_search_depth_long, & wt_timeout_long); /* now, wait for everybody to be ready to run */ if (cnt >= THREADS) mysql_cond_broadcast(&thread_sync); else while (cnt < THREADS) mysql_cond_wait(&thread_sync, &mutex); mysql_mutex_unlock(&mutex); my_rnd_init(&rand, (ulong)(intptr)&m, id); if (kill_strategy == YOUNGEST) thds[id].thd.weight= (ulong)~my_getsystime(); if (kill_strategy == LOCKS) thds[id].thd.weight= 0; for (m= *(int *)arg; m ; m--) { WT_RESOURCE_ID resid; int blockers[THREADS/10], j, k; resid.value= id; resid.type= &restype; res= 0; /* prepare for waiting for a random number of random threads */ for (j= n= (rnd() % THREADS)/10; !res && j >= 0; j--) { retry: i= rnd() % (THREADS-1); /* pick a random thread */ if (i >= id) i++; /* with a number from 0 to THREADS-1 excluding ours */ for (k=n; k >=j; k--) /* the one we didn't pick before */ if (blockers[k] == i) goto retry; blockers[j]= i; if (kill_strategy == RANDOM) thds[id].thd.weight= rnd(); mysql_mutex_lock(& thds[i].lock); res= wt_thd_will_wait_for(& thds[id].thd, & thds[i].thd, &resid); mysql_mutex_unlock(& thds[i].lock); } if (!res) { mysql_mutex_lock(&lock); res= wt_thd_cond_timedwait(& thds[id].thd, &lock); mysql_mutex_unlock(&lock); } if (res) { mysql_mutex_lock(& thds[id].lock); mysql_mutex_lock(&lock); wt_thd_release_all(& thds[id].thd); mysql_mutex_unlock(&lock); mysql_mutex_unlock(& thds[id].lock); if (kill_strategy == LOCKS) thds[id].thd.weight= 0; if (kill_strategy == YOUNGEST) thds[id].thd.weight= (ulong)~my_getsystime(); } else if (kill_strategy == LOCKS) thds[id].thd.weight++; } mysql_mutex_lock(&mutex); /* wait for everybody to finish */ if (!--cnt) mysql_cond_broadcast(&thread_sync); else while (cnt) mysql_cond_wait(&thread_sync, &mutex); mysql_mutex_lock(& thds[id].lock); mysql_mutex_lock(&lock); wt_thd_release_all(& thds[id].thd); mysql_mutex_unlock(&lock); mysql_mutex_unlock(& thds[id].lock); wt_thd_destroy(& thds[id].thd); if (!--running_threads) /* now, signal when everybody is done with deinit */ mysql_cond_signal(&cond); mysql_mutex_unlock(&mutex); DBUG_PRINT("wt", ("exiting")); my_thread_end(); return 0; }
void my_end(int infoflag) { FILE *info_file; if (!(info_file=DBUG_FILE)) info_file=stderr; if (infoflag & MY_CHECK_ERROR || info_file != stderr) { /* Test if some file is left open */ if (my_file_opened | my_stream_opened) { sprintf(errbuff[0],EE(EE_OPEN_WARNING),my_file_opened,my_stream_opened); (void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL); DBUG_PRINT("error",("%s",errbuff[0])); } } free_charsets(); if (infoflag & MY_GIVE_INFO || info_file != stderr) { #ifdef HAVE_GETRUSAGE struct rusage rus; if (!getrusage(RUSAGE_SELF, &rus)) fprintf(info_file,"\n\ User time %.2f, System time %.2f\n\ Maximum resident set size %ld, Integral resident set size %ld\n\ Non-physical pagefaults %ld, Physical pagefaults %ld, Swaps %ld\n\ Blocks in %ld out %ld, Messages in %ld out %ld, Signals %ld\n\ Voluntary context switches %ld, Involuntary context switches %ld\n", (rus.ru_utime.tv_sec * SCALE_SEC + rus.ru_utime.tv_usec / SCALE_USEC) / 100.0, (rus.ru_stime.tv_sec * SCALE_SEC + rus.ru_stime.tv_usec / SCALE_USEC) / 100.0, rus.ru_maxrss, rus.ru_idrss, rus.ru_minflt, rus.ru_majflt, rus.ru_nswap, rus.ru_inblock, rus.ru_oublock, rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals, rus.ru_nvcsw, rus.ru_nivcsw); #endif #if ( defined(MSDOS) || defined(__NETWARE__) ) && !defined(__WIN__) fprintf(info_file,"\nRun time: %.1f\n",(double) clock()/CLOCKS_PER_SEC); #endif #if defined(SAFEMALLOC) TERMINATE(stderr); /* Give statistic on screen */ #elif defined(__WIN__) && defined(_MSC_VER) _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR ); _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR ); _CrtCheckMemory(); _CrtDumpMemoryLeaks(); #endif } #ifdef THREAD DBUG_POP(); /* Must be done before my_thread_end */ my_once_free(); my_thread_end(); my_thread_global_end(); #if defined(SAFE_MUTEX) /* Check on destroying of mutexes. A few may be left that will get cleaned up by C++ destructors */ safe_mutex_end(infoflag & MY_GIVE_INFO ? stderr : (FILE *) 0); #endif /* defined(SAFE_MUTEX) */ #endif /* THREAD */ #ifdef __WIN__ if (have_tcpip) WSACleanup(); #endif /* __WIN__ */ my_init_done=0; } /* my_end */