~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Monty Taylor
  • Date: 2009-03-04 02:48:12 UTC
  • mto: (917.1.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 918.
  • Revision ID: mordred@inaugust.com-20090304024812-5wb6wpye5c1iitbq
Applied atomic patch to current tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include <drizzled/errmsg.h>
45
45
#include <drizzled/unireg.h>
46
46
#include <drizzled/plugin_scheduling.h>
 
47
 
 
48
#include <drizzled/atomics.h>
 
49
 
47
50
#include "drizzled/temporal_format.h" /* For init_temporal_formats() */
48
51
 
49
52
#if TIME_WITH_SYS_TIME
129
132
#include <sys/fpu.h>
130
133
#endif
131
134
 
132
 
 
133
135
inline void setup_fpu()
134
136
{
135
137
#if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H)
171
173
 
172
174
extern "C" void handle_segfault(int sig);
173
175
 
 
176
using namespace tbb;
174
177
using namespace std;
175
178
 
 
179
 
176
180
/* Constants */
177
181
 
178
182
const char *show_comp_option_name[]= {"YES", "NO", "DISABLED"};
291
295
uint32_t delay_key_write_options, protocol_version= PROTOCOL_VERSION;
292
296
uint32_t lower_case_table_names= 1;
293
297
uint32_t tc_heuristic_recover= 0;
294
 
uint32_t volatile thread_count, thread_running;
 
298
uint32_t volatile thread_running;
 
299
atomic<uint32_t> thread_count;
295
300
uint64_t session_startup_options;
296
301
uint32_t back_log;
297
302
uint32_t connect_timeout;
305
310
uint64_t aborted_threads;
306
311
uint64_t aborted_connects;
307
312
uint64_t max_connect_errors;
308
 
ulong thread_id=1L;
 
313
atomic<my_thread_id> thread_id;
309
314
pid_t current_pid;
310
315
uint64_t slow_launch_threads= 0;
311
316
uint64_t expire_logs_days= 0;
444
449
extern scheduling_st thread_scheduler;
445
450
 
446
451
/**
447
 
  Number of currently active user connections. The variable is protected by
448
 
  LOCK_thread_count.
449
 
*/
450
 
uint32_t connection_count= 0;
 
452
 * Number of currently active user connections.
 
453
 */
 
454
atomic<uint32_t> connection_count;
451
455
 
452
456
/* Function declarations */
453
457
 
1000
1004
{
1001
1005
  session->cleanup();
1002
1006
 
1003
 
  (void) pthread_mutex_lock(&LOCK_thread_count);
1004
1007
  connection_count--;
1005
1008
  thread_count--;
1006
1009
  delete session;
1007
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
1010
 
1008
1011
  return;
1009
1012
}
1010
1013
 
1080
1083
  fprintf(stderr, "read_buffer_size=%ld\n", (long) global_system_variables.read_buff_size);
1081
1084
  fprintf(stderr, "max_used_connections=%u\n", max_used_connections);
1082
1085
  fprintf(stderr, "max_threads=%u\n", thread_scheduler.max_threads);
1083
 
  fprintf(stderr, "thread_count=%u\n", thread_count);
1084
 
  fprintf(stderr, "connection_count=%u\n", connection_count);
 
1086
  fprintf(stderr, "thread_count=%u\n", uint32_t(thread_count));
 
1087
  fprintf(stderr, "connection_count=%u\n", uint32_t(connection_count));
1085
1088
  fprintf(stderr, _("It is possible that drizzled could use up to \n"
1086
1089
                    "key_buffer_size + (read_buffer_size + "
1087
1090
                    "sort_buffer_size)*max_threads = %"PRIu64" K\n"
1896
1899
 
1897
1900
static void create_new_thread(Session *session)
1898
1901
{
1899
 
  pthread_mutex_lock(&LOCK_thread_count);
1900
 
 
1901
 
  ++connection_count;
1902
 
 
 
1902
 
 
1903
  connection_count++;
1903
1904
  if (connection_count > max_used_connections)
1904
1905
    max_used_connections= connection_count;
1905
1906
 
1908
1909
    the embedded library.
1909
1910
    TODO: refactor this to avoid code duplication there
1910
1911
  */
1911
 
  session->thread_id= session->variables.pseudo_thread_id= thread_id++;
 
1912
  session->thread_id= session->variables.pseudo_thread_id= ++thread_id;
1912
1913
 
1913
1914
  thread_count++;
1914
1915
 
1915
1916
  /* 
1916
1917
    If we error on creation we drop the connection and delete the session.
1917
1918
  */
 
1919
  pthread_mutex_lock(&LOCK_thread_count);
1918
1920
  if (thread_scheduler.add_connection(session))
1919
1921
  {
1920
1922
    char error_message_buff[DRIZZLE_ERRMSG_SIZE];
1926
1928
    /* Can't use my_error() since store_globals has not been called. */
1927
1929
    snprintf(error_message_buff, sizeof(error_message_buff), ER(ER_CANT_CREATE_THREAD), 1); /* TODO replace will better error message */
1928
1930
    net_send_error(session, ER_CANT_CREATE_THREAD, error_message_buff);
1929
 
    (void) pthread_mutex_lock(&LOCK_thread_count);
1930
 
    --connection_count;
1931
 
    session->close_connection(0, 0);
 
1931
    connection_count--;
 
1932
    session->close_connection(0, true);
1932
1933
    delete session;
1933
 
    (void) pthread_mutex_unlock(&LOCK_thread_count);
1934
1934
  }
1935
1935
}
1936
1936
 
2925
2925
  if (!(tmpenv = getenv("MY_BASEDIR_VERSION")))
2926
2926
    tmpenv = PREFIX;
2927
2927
  (void) strncpy(drizzle_home, tmpenv, sizeof(drizzle_home)-1);
 
2928
 
 
2929
  connection_count= 0;
 
2930
  thread_id= 1;
2928
2931
}
2929
2932
 
2930
2933