示例#1
0
void my_thread_end(void)
{
  struct st_my_thread_var *tmp;
  tmp= _my_thread_var();

#ifdef EXTRA_DEBUG_THREADS
    my_message_local(INFORMATION_LEVEL, "my_thread_end(): tmp: 0x%lx  "
                     "pthread_self: 0x%lx  thread_id: %ld",
                     (long) tmp, (long) pthread_self(),
                     tmp ? (long) tmp->id : 0L);
#endif

#ifdef HAVE_PSI_INTERFACE
  /*
    Remove the instrumentation for this thread.
    This must be done before trashing st_my_thread_var,
    because the LF_HASH depends on it.
  */
  PSI_THREAD_CALL(delete_current_thread)();
#endif

  if (tmp && tmp->init)
  {
#if !defined(DBUG_OFF)
    /* tmp->dbug is allocated inside DBUG library */
    if (tmp->dbug)
    {
      DBUG_POP();
      free(tmp->dbug);
      tmp->dbug=0;
    }
#endif
    mysql_cond_destroy(&tmp->suspend);
    mysql_mutex_destroy(&tmp->mutex);
    free(tmp);

    /*
      Decrement counter for number of running threads. We are using this
      in my_thread_global_end() to wait until all threads have called
      my_thread_end and thus freed all memory they have allocated in
      my_thread_init() and DBUG_xxxx
    */
    mysql_mutex_lock(&THR_LOCK_threads);
    DBUG_ASSERT(THR_thread_count != 0);
    if (--THR_thread_count == 0)
      mysql_cond_signal(&THR_COND_threads);
    mysql_mutex_unlock(&THR_LOCK_threads);
  }
  set_mysys_var(NULL);
}
示例#2
0
static
void CheckDisableDbug( compiler_phase_t phase)
{
  DBUG_ENTER("CheckDisableDbug");
    
  if (global.my_dbug
      && global.my_dbug_active
      && (phase >= global.my_dbug_to)) {
    DBUG_POP();
    global.my_dbug_active = FALSE;
  }

  DBUG_VOID_RETURN;
}
示例#3
0
文件: my_init.c 项目: OPSF/uClinux
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 */
示例#4
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 */