~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/my_pthread.h

  • Committer: Brian Aker
  • Date: 2010-05-27 01:22:55 UTC
  • mto: This revision was merged to the branch mainline in revision 1568.
  • Revision ID: brian@gaz-20100527012255-ssmjt4un8ptpg4jv
Remove dead .opt files. Removed two options from Innodb which do not relate
to drizzle (backwards compatible options for old MySQL). 

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* Defines to make different thread packages compatible */
17
17
 
18
 
 
19
 
 
20
18
#ifndef DRIZZLED_INTERNAL_MY_PTHREAD_H
21
19
#define DRIZZLED_INTERNAL_MY_PTHREAD_H
22
20
 
23
21
#include <unistd.h>
24
22
 
25
 
#include <boost/date_time.hpp>
26
 
 
27
23
#ifndef ETIME
28
24
#define ETIME ETIMEDOUT                         /* For FreeBSD */
29
25
#endif
39
35
#include <synch.h>
40
36
#endif
41
37
 
42
 
#include <drizzled/visibility.h>
43
 
 
44
38
namespace drizzled
45
39
{
46
40
namespace internal
50
44
#define pthread_handler_t void *
51
45
typedef void *(* pthread_handler)(void *);
52
46
 
 
47
#ifndef my_pthread_attr_setprio
 
48
#ifdef HAVE_PTHREAD_ATTR_SETPRIO
 
49
#define my_pthread_attr_setprio(A,B) pthread_attr_setprio((A),(B))
 
50
#else
 
51
extern void my_pthread_attr_setprio(pthread_attr_t *attr, int priority);
 
52
#endif
 
53
#endif
 
54
 
53
55
#if !defined(HAVE_PTHREAD_YIELD_ONE_ARG) && !defined(HAVE_PTHREAD_YIELD_ZERO_ARG)
54
56
/* no pthread_yield() available */
55
57
#ifdef HAVE_SCHED_YIELD
76
78
#ifndef set_timespec_nsec
77
79
#define set_timespec_nsec(ABSTIME,NSEC) \
78
80
{\
79
 
  boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());\
80
 
  boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));\
81
 
  uint64_t t_mark= (mytime-epoch).total_microseconds();\
82
 
  uint64_t now= t_mark + (NSEC/100); \
 
81
  uint64_t now= my_getsystime() + (NSEC/100); \
83
82
  (ABSTIME).tv_sec=  (time_t) (now / 10000000UL);                  \
84
83
  (ABSTIME).tv_nsec= (long) (now % 10000000UL * 100 + ((NSEC) % 100)); \
85
84
}
86
85
#endif /* !set_timespec_nsec */
87
86
 
 
87
        /* safe_mutex adds checking to mutex for easier debugging */
 
88
 
 
89
typedef struct st_safe_mutex_t
 
90
{
 
91
  pthread_mutex_t global,mutex;
 
92
  const char *file;
 
93
  uint32_t line,count;
 
94
  pthread_t thread;
 
95
} safe_mutex_t;
 
96
 
 
97
int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr,
 
98
                    const char *file, uint32_t line);
 
99
int safe_mutex_lock(safe_mutex_t *mp, bool try_lock, const char *file, uint32_t line);
 
100
int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint32_t line);
 
101
int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint32_t line);
 
102
int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file,
 
103
                   uint32_t line);
 
104
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
 
105
                        struct timespec *abstime, const char *file, uint32_t line);
 
106
void safe_mutex_global_init(void);
 
107
void safe_mutex_end(void);
 
108
 
88
109
        /* Wrappers if safe mutex is actually used */
89
110
#define safe_mutex_assert_owner(mp)
90
111
#define safe_mutex_assert_not_owner(mp)
110
131
 
111
132
extern bool my_thread_global_init(void);
112
133
extern void my_thread_global_end(void);
113
 
DRIZZLED_API bool my_thread_init(void);
114
 
DRIZZLED_API void my_thread_end(void);
 
134
extern bool my_thread_init(void);
 
135
extern void my_thread_end(void);
115
136
extern const char *my_thread_name(void);
116
137
 
117
138
/* All thread specific variables are in the following struct */
118
139
 
119
 
/**
120
 
  A default thread stack size of zero means that we are going to use
121
 
  the OS defined thread stack size (this varies from OS to OS).
122
 
 */
123
 
#define DEFAULT_THREAD_STACK    0
 
140
/*
 
141
  Drizzle can survive with 32K, but some glibc libraries require > 128K stack
 
142
  to resolve hostnames. Also recursive stored procedures needs stack.
 
143
*/
 
144
#define DEFAULT_THREAD_STACK    (256*INT32_C(1024))
 
145
 
 
146
struct st_my_thread_var
 
147
{
 
148
  pthread_cond_t suspend;
 
149
  pthread_mutex_t mutex;
 
150
  pthread_mutex_t * volatile current_mutex;
 
151
  pthread_cond_t * volatile current_cond;
 
152
  pthread_t pthread_self;
 
153
  uint64_t id;
 
154
  int volatile abort;
 
155
  bool init;
 
156
  struct st_my_thread_var *next,**prev;
 
157
  void *opt_info;
 
158
};
 
159
 
 
160
extern struct st_my_thread_var *_my_thread_var(void);
 
161
#define my_thread_var (::drizzled::internal::_my_thread_var())
 
162
/*
 
163
  Keep track of shutdown,signal, and main threads so that my_end() will not
 
164
  report errors with them
 
165
*/
 
166
 
 
167
/* Which kind of thread library is in use */
 
168
 
 
169
#define THD_LIB_OTHER 1
 
170
#define THD_LIB_NPTL  2
 
171
#define THD_LIB_LT    4
 
172
 
 
173
extern uint32_t thd_lib_detected;
 
174
 
 
175
/*
 
176
  thread_safe_xxx functions are for critical statistic or counters.
 
177
  The implementation is guaranteed to be thread safe, on all platforms.
 
178
  Note that the calling code should *not* assume the counter is protected
 
179
  by the mutex given, as the implementation of these helpers may change
 
180
  to use my_atomic operations instead.
 
181
*/
 
182
 
 
183
#ifndef thread_safe_increment
 
184
#define thread_safe_increment(V,L) \
 
185
        (pthread_mutex_lock((L)), (V)++, pthread_mutex_unlock((L)))
 
186
#define thread_safe_decrement(V,L) \
 
187
        (pthread_mutex_lock((L)), (V)--, pthread_mutex_unlock((L)))
 
188
#endif
 
189
 
 
190
#ifndef thread_safe_add
 
191
#define thread_safe_add(V,C,L) \
 
192
        (pthread_mutex_lock((L)), (V)+=(C), pthread_mutex_unlock((L)))
 
193
#define thread_safe_sub(V,C,L) \
 
194
        (pthread_mutex_lock((L)), (V)-=(C), pthread_mutex_unlock((L)))
 
195
#endif
 
196
 
 
197
/*
 
198
  statistics_xxx functions are for non critical statistic,
 
199
  maintained in global variables.
 
200
  - race conditions can occur, making the result slightly inaccurate.
 
201
  - the lock given is not honored.
 
202
*/
 
203
#define statistic_decrement(V,L) (V)--
 
204
#define statistic_increment(V,L) (V)++
 
205
#define statistic_add(V,C,L)     (V)+=(C)
 
206
#define statistic_sub(V,C,L)     (V)-=(C)
 
207
 
 
208
/*
 
209
  No locking needed, the counter is owned by the thread
 
210
*/
 
211
#define status_var_increment(V) (V)++
 
212
#define status_var_decrement(V) (V)--
 
213
#define status_var_add(V,C)     (V)+=(C)
 
214
#define status_var_sub(V,C)     (V)-=(C)
124
215
 
125
216
} /* namespace internal */
126
217
} /* namespace drizzled */