my_init.c
上传用户:jmzj888
上传日期:2007-01-02
资源大小:220k
文件大小:4k
- /* Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
- This file is public domain and comes with NO WARRANTY of any kind */
- #include "mysys_priv.h"
- #include "my_static.h"
- #include "mysys_err.h"
- #include <m_string.h>
- #ifdef THREAD
- #include <my_pthread.h>
- #endif
- #ifdef HAVE_GETRUSAGE
- #include <sys/resource.h>
- extern int getrusage(int, struct rusage *);
- #endif
- #ifdef VMS
- #include <my_static.c>
- #include <m_ctype.h>
- #endif
- #ifdef __WIN32__
- #ifdef _MSC_VER
- #include <crtdbg.h>
- #endif
- static void my_win_init(void);
- #else
- #define my_win_init()
- #endif
- /* Init my_sys functions and my_sys variabels */
- void my_init(void)
- {
- my_string str;
- #if defined(HAVE_PTHREAD_INIT) && defined(THREAD)
- pthread_init(); /* Must be called before DBUG_ENTER */
- #endif
- {
- DBUG_ENTER("my_init");
- DBUG_PROCESS(my_progname ? my_progname : "unknown");
- if (!home_dir)
- { /* Don't initialize twice */
- if ((home_dir=getenv("HOME")) != 0)
- home_dir=intern_filename(home_dir_buff,home_dir);
- #ifndef VMS
- if ((str=getenv("UMASK")) != 0)
- my_umask=atoi(str) | 0600; /* Default creation of new files */
- #endif
- #ifdef VMS
- init_ctype(); /* Stupid linker don't link _ctype.c */
- #endif
- #ifdef THREAD
- my_thread_global_init();
- #ifndef __WIN32__
- sigfillset(&my_signals); /* signals blocked by mf_brkhant */
- #endif
- #endif
- DBUG_PRINT("exit",("home: '%s'",home_dir));
- }
- DBUG_VOID_RETURN;
- }
- } /* my_init */
- /* End my_sys */
- void my_end(int infoflag)
- {
- FILE *info_file;
- DBUG_ENTER("my_end");
- 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]));
- }
- }
- if (infoflag & MY_GIVE_INFO || info_file != stderr)
- {
- #ifdef HAVE_GETRUSAGE
- struct rusage rus;
- if (!getrusage(RUSAGE_SELF, &rus))
- fprintf(info_file,"nUser time %.2f, System time %.2fnMaximum resident set size %d, Integral resident set size %dnNon physical pagefaults %d, Physical pagefaults %d, Swaps %dnBlocks in %d out %d, Messages in %d out %d, Signals %dnVouluntary contexts switches %d, Invouluntary contexts switches %dn",
- (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
- #ifdef MSDOS
- fprintf(info_file,"nRun time: %.1fn",(double) clock()/CLOCKS_PER_SEC);
- #endif
- #if defined(SAFEMALLOC)
- TERMINATE(stderr); /* Give statistic on screen */
- #elif defined(__WIN32__) && 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
- pthread_mutex_destroy(&THR_LOCK_keycache);
- pthread_mutex_destroy(&THR_LOCK_malloc);
- pthread_mutex_destroy(&THR_LOCK_open);
- #endif
- DBUG_VOID_RETURN;
- } /* my_end */