00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <drizzled/internal/my_sys.h>
00024 #include <drizzled/internal/thread_var.h>
00025 #include <drizzled/internal/m_string.h>
00026
00027 #include <cstdio>
00028 #include <signal.h>
00029
00030 #if TIME_WITH_SYS_TIME
00031 # include <sys/time.h>
00032 # include <time.h>
00033 #else
00034 # if HAVE_SYS_TIME_H
00035 # include <sys/time.h>
00036 # else
00037 # include <time.h>
00038 # endif
00039 #endif
00040
00041 #include <boost/thread/thread.hpp>
00042 #include <boost/thread/mutex.hpp>
00043 #include <boost/thread/tss.hpp>
00044
00045 namespace drizzled
00046 {
00047 namespace internal
00048 {
00049
00050 boost::thread_specific_ptr<st_my_thread_var> THR_KEY_mysys;
00051 boost::mutex THR_LOCK_threads;
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 bool my_thread_global_init(void)
00065 {
00066 if (my_thread_init())
00067 {
00068 my_thread_global_end();
00069 return 1;
00070 }
00071 return 0;
00072 }
00073
00074
00075 void my_thread_global_end(void)
00076 {
00077 }
00078
00079 static uint64_t thread_id= 0;
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 bool my_thread_init(void)
00093 {
00094
00095 if (THR_KEY_mysys.get())
00096 return 0;
00097
00098 st_my_thread_var *tmp= new st_my_thread_var;
00099 if (tmp == NULL)
00100 {
00101 return true;
00102 }
00103 THR_KEY_mysys.reset(tmp);
00104
00105 boost::mutex::scoped_lock scopedLock(THR_LOCK_threads);
00106 tmp->id= ++thread_id;
00107
00108 return false;
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 void my_thread_end(void)
00125 {
00126 }
00127
00128 struct st_my_thread_var *_my_thread_var(void)
00129 {
00130 return THR_KEY_mysys.get();
00131 }
00132
00133 }
00134 }