~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/internal/my_pthread.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#define DRIZZLED_INTERNAL_MY_PTHREAD_H
20
20
 
21
21
#include <unistd.h>
22
 
#include <signal.h>
23
22
 
24
23
#ifndef ETIME
25
24
#define ETIME ETIMEDOUT                         /* For FreeBSD */
45
44
#define pthread_handler_t void *
46
45
typedef void *(* pthread_handler)(void *);
47
46
 
48
 
 
49
 
/*
50
 
  We define my_sigset() and use that instead of the system sigset() so that
51
 
  we can favor an implementation based on sigaction(). On some systems, such
52
 
  as Mac OS X, sigset() results in flags such as SA_RESTART being set, and
53
 
  we want to make sure that no such flags are set.
54
 
*/
55
 
#if !defined(my_sigset)
56
 
#define my_sigset(A,B) do { struct sigaction l_s; sigset_t l_set; int l_rc; \
57
 
                            assert((A) != 0);                          \
58
 
                            sigemptyset(&l_set);                            \
59
 
                            l_s.sa_handler = (B);                           \
60
 
                            l_s.sa_mask   = l_set;                          \
61
 
                            l_s.sa_flags   = 0;                             \
62
 
                            l_rc= sigaction((A), &l_s, (struct sigaction *) NULL);\
63
 
                            assert(l_rc == 0);                         \
64
 
                          } while (0)
65
 
#elif defined(HAVE_SIGSET) && !defined(my_sigset)
66
 
#define my_sigset(A,B) sigset((A),(B))
67
 
#elif !defined(my_sigset)
68
 
#define my_sigset(A,B) signal((A),(B))
69
 
#endif
70
 
 
71
 
#ifndef my_pthread_attr_setprio
72
 
#ifdef HAVE_PTHREAD_ATTR_SETPRIO
73
 
#define my_pthread_attr_setprio(A,B) pthread_attr_setprio((A),(B))
74
 
#else
75
 
extern void my_pthread_attr_setprio(pthread_attr_t *attr, int priority);
76
 
#endif
77
 
#endif
78
 
 
79
47
#if !defined(HAVE_PTHREAD_YIELD_ONE_ARG) && !defined(HAVE_PTHREAD_YIELD_ZERO_ARG)
80
48
/* no pthread_yield() available */
81
49
#ifdef HAVE_SCHED_YIELD
108
76
}
109
77
#endif /* !set_timespec_nsec */
110
78
 
111
 
        /* safe_mutex adds checking to mutex for easier debugging */
112
 
 
113
 
typedef struct st_safe_mutex_t
114
 
{
115
 
  pthread_mutex_t global,mutex;
116
 
  const char *file;
117
 
  uint32_t line,count;
118
 
  pthread_t thread;
119
 
} safe_mutex_t;
120
 
 
121
 
int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr,
122
 
                    const char *file, uint32_t line);
123
 
int safe_mutex_lock(safe_mutex_t *mp, bool try_lock, const char *file, uint32_t line);
124
 
int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint32_t line);
125
 
int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint32_t line);
126
 
int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file,
127
 
                   uint32_t line);
128
 
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
129
 
                        struct timespec *abstime, const char *file, uint32_t line);
130
 
void safe_mutex_global_init(void);
131
 
void safe_mutex_end(void);
132
 
 
133
79
        /* Wrappers if safe mutex is actually used */
134
80
#define safe_mutex_assert_owner(mp)
135
81
#define safe_mutex_assert_not_owner(mp)
161
107
 
162
108
/* All thread specific variables are in the following struct */
163
109
 
164
 
/*
165
 
  Drizzle can survive with 32K, but some glibc libraries require > 128K stack
166
 
  to resolve hostnames. Also recursive stored procedures needs stack.
167
 
*/
168
 
#define DEFAULT_THREAD_STACK    (256*INT32_C(1024))
169
 
 
170
 
struct st_my_thread_var
171
 
{
172
 
  pthread_cond_t suspend;
173
 
  pthread_mutex_t mutex;
174
 
  pthread_mutex_t * volatile current_mutex;
175
 
  pthread_cond_t * volatile current_cond;
176
 
  pthread_t pthread_self;
177
 
  uint64_t id;
178
 
  int volatile abort;
179
 
  bool init;
180
 
  struct st_my_thread_var *next,**prev;
181
 
  void *opt_info;
182
 
};
183
 
 
184
 
extern struct st_my_thread_var *_my_thread_var(void);
185
 
#define my_thread_var (::drizzled::internal::_my_thread_var())
186
 
/*
187
 
  Keep track of shutdown,signal, and main threads so that my_end() will not
188
 
  report errors with them
189
 
*/
190
 
 
191
 
/* Which kind of thread library is in use */
192
 
 
193
 
#define THD_LIB_OTHER 1
194
 
#define THD_LIB_NPTL  2
195
 
#define THD_LIB_LT    4
196
 
 
197
 
extern uint32_t thd_lib_detected;
198
 
 
199
 
/*
200
 
  thread_safe_xxx functions are for critical statistic or counters.
201
 
  The implementation is guaranteed to be thread safe, on all platforms.
202
 
  Note that the calling code should *not* assume the counter is protected
203
 
  by the mutex given, as the implementation of these helpers may change
204
 
  to use my_atomic operations instead.
205
 
*/
206
 
 
207
 
#ifndef thread_safe_increment
208
 
#define thread_safe_increment(V,L) \
209
 
        (pthread_mutex_lock((L)), (V)++, pthread_mutex_unlock((L)))
210
 
#define thread_safe_decrement(V,L) \
211
 
        (pthread_mutex_lock((L)), (V)--, pthread_mutex_unlock((L)))
212
 
#endif
213
 
 
214
 
#ifndef thread_safe_add
215
 
#define thread_safe_add(V,C,L) \
216
 
        (pthread_mutex_lock((L)), (V)+=(C), pthread_mutex_unlock((L)))
217
 
#define thread_safe_sub(V,C,L) \
218
 
        (pthread_mutex_lock((L)), (V)-=(C), pthread_mutex_unlock((L)))
219
 
#endif
220
 
 
221
 
/*
222
 
  statistics_xxx functions are for non critical statistic,
223
 
  maintained in global variables.
224
 
  - race conditions can occur, making the result slightly inaccurate.
225
 
  - the lock given is not honored.
226
 
*/
227
 
#define statistic_decrement(V,L) (V)--
228
 
#define statistic_increment(V,L) (V)++
229
 
#define statistic_add(V,C,L)     (V)+=(C)
230
 
#define statistic_sub(V,C,L)     (V)-=(C)
231
 
 
232
 
/*
233
 
  No locking needed, the counter is owned by the thread
234
 
*/
235
 
#define status_var_increment(V) (V)++
236
 
#define status_var_decrement(V) (V)--
237
 
#define status_var_add(V,C)     (V)+=(C)
238
 
#define status_var_sub(V,C)     (V)-=(C)
 
110
/**
 
111
  A default thread stack size of zero means that we are going to use
 
112
  the OS defined thread stack size (this varies from OS to OS).
 
113
 */
 
114
#define DEFAULT_THREAD_STACK    0
239
115
 
240
116
} /* namespace internal */
241
117
} /* namespace drizzled */