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 */
16
16
/* Defines to make different thread packages compatible */
44
44
#define pthread_handler_t void *
45
45
typedef void *(* pthread_handler)(void *);
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))
51
extern void my_pthread_attr_setprio(pthread_attr_t *attr, int priority);
47
55
#if !defined(HAVE_PTHREAD_YIELD_ONE_ARG) && !defined(HAVE_PTHREAD_YIELD_ZERO_ARG)
48
56
/* no pthread_yield() available */
49
57
#ifdef HAVE_SCHED_YIELD
77
85
#endif /* !set_timespec_nsec */
87
/* safe_mutex adds checking to mutex for easier debugging */
89
typedef struct st_safe_mutex_t
91
pthread_mutex_t global,mutex;
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,
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);
79
109
/* Wrappers if safe mutex is actually used */
80
110
#define safe_mutex_assert_owner(mp)
81
111
#define safe_mutex_assert_not_owner(mp)
108
138
/* All thread specific variables are in the following struct */
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).
114
#define DEFAULT_THREAD_STACK 0
141
Drizzle can survive with 32K, but some glibc libraries require > 128K stack
142
to resolve hostnames. Also recursive stored procedures needs stack.
144
#define DEFAULT_THREAD_STACK (256*INT32_C(1024))
146
struct st_my_thread_var
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;
156
struct st_my_thread_var *next,**prev;
160
extern struct st_my_thread_var *_my_thread_var(void);
161
#define my_thread_var (::drizzled::internal::_my_thread_var())
163
Keep track of shutdown,signal, and main threads so that my_end() will not
164
report errors with them
167
/* Which kind of thread library is in use */
169
#define THD_LIB_OTHER 1
170
#define THD_LIB_NPTL 2
173
extern uint32_t thd_lib_detected;
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.
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)))
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)))
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.
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)
209
No locking needed, the counter is owned by the thread
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)
116
216
} /* namespace internal */
117
217
} /* namespace drizzled */