~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Jay Pipes
  • Date: 2009-03-20 10:06:30 UTC
  • mfrom: (950 drizzle)
  • mto: This revision was merged to the branch mainline in revision 957.
  • Revision ID: jpipes@serialcoder-20090320100630-ra870urs5tz2g1b4
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include <drizzled/configmake.h>
22
22
#include <drizzled/server_includes.h>
 
23
#include <drizzled/atomics.h>
23
24
 
24
25
#include <netdb.h>
25
26
#include <sys/poll.h>
433
434
  Number of currently active user connections. The variable is protected by
434
435
  LOCK_thread_count.
435
436
*/
436
 
uint32_t connection_count= 0;
 
437
tbb::atomic<uint32_t> connection_count;
437
438
 
438
439
/* Function declarations */
439
440
 
524
525
  }
525
526
  (void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list
526
527
 
 
528
  if (connection_count)
 
529
    sleep(2);                                   // Give threads time to die
 
530
 
527
531
  /*
528
532
    Force remaining threads to die by closing the connection to the client
529
533
    This will ensure that threads that are waiting for a command from the
530
534
    client on a blocking read call are aborted.
531
535
  */
532
 
 
533
536
  for (;;)
534
537
  {
535
538
    (void) pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
541
544
    (void) pthread_mutex_unlock(&LOCK_thread_count);
542
545
    unlink_session(tmp);
543
546
  }
544
 
  /* All threads has now been aborted */
545
 
  (void) pthread_mutex_lock(&LOCK_thread_count);
546
 
  while (!session_list.is_empty())
547
 
  {
548
 
    (void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
549
 
  }
550
 
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
547
  assert(session_list.is_empty());
551
548
}
552
549
 
553
550
 
971
968
 
972
969
void unlink_session(Session *session)
973
970
{
 
971
  connection_count--;
 
972
 
974
973
  session->cleanup();
975
974
 
976
 
  pthread_mutex_lock(&LOCK_thread_count);
977
 
  connection_count--;
 
975
  (void) pthread_mutex_lock(&LOCK_thread_count);
978
976
  pthread_mutex_lock(&session->LOCK_delete);
979
 
  pthread_mutex_unlock(&LOCK_thread_count);
980
977
  delete session;
 
978
  (void) pthread_mutex_unlock(&LOCK_thread_count);
981
979
 
982
980
  return;
983
981
}
1055
1053
  fprintf(stderr, "max_used_connections=%u\n", max_used_connections);
1056
1054
  fprintf(stderr, "max_threads=%u\n", thread_scheduler.max_threads);
1057
1055
  fprintf(stderr, "thread_count=%u\n", thread_scheduler.count());
1058
 
  fprintf(stderr, "connection_count=%u\n", connection_count);
 
1056
  fprintf(stderr, "connection_count=%u\n", uint32_t(connection_count));
1059
1057
  fprintf(stderr, _("It is possible that drizzled could use up to \n"
1060
1058
                    "key_buffer_size + (read_buffer_size + "
1061
1059
                    "sort_buffer_size)*max_threads = %"PRIu64" K\n"
1886
1884
    /* Can't use my_error() since store_globals has not been called. */
1887
1885
    snprintf(error_message_buff, sizeof(error_message_buff), ER(ER_CANT_CREATE_THREAD), 1); /* TODO replace will better error message */
1888
1886
    net_send_error(session, ER_CANT_CREATE_THREAD, error_message_buff);
1889
 
    (void) pthread_mutex_lock(&LOCK_thread_count);
1890
 
    --connection_count;
1891
 
    session->disconnect(0, false);
1892
 
    delete session;
1893
 
    (void) pthread_mutex_unlock(&LOCK_thread_count);
 
1887
    unlink_session(session);
1894
1888
  }
1895
1889
}
1896
1890
 
2856
2850
  if (!(tmpenv = getenv("MY_BASEDIR_VERSION")))
2857
2851
    tmpenv = PREFIX;
2858
2852
  (void) strncpy(drizzle_home, tmpenv, sizeof(drizzle_home)-1);
 
2853
  
 
2854
  connection_count= 0;
2859
2855
}
2860
2856
 
2861
2857