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);
55
47
#if !defined(HAVE_PTHREAD_YIELD_ONE_ARG) && !defined(HAVE_PTHREAD_YIELD_ZERO_ARG)
56
48
/* no pthread_yield() available */
57
49
#ifdef HAVE_SCHED_YIELD
85
77
#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);
109
79
/* Wrappers if safe mutex is actually used */
110
80
#define safe_mutex_assert_owner(mp)
111
81
#define safe_mutex_assert_not_owner(mp)
157
127
extern uint32_t thd_lib_detected;
160
thread_safe_xxx functions are for critical statistic or counters.
161
The implementation is guaranteed to be thread safe, on all platforms.
162
Note that the calling code should *not* assume the counter is protected
163
by the mutex given, as the implementation of these helpers may change
164
to use my_atomic operations instead.
167
#ifndef thread_safe_increment
168
#define thread_safe_increment(V,L) \
169
(pthread_mutex_lock((L)), (V)++, pthread_mutex_unlock((L)))
170
#define thread_safe_decrement(V,L) \
171
(pthread_mutex_lock((L)), (V)--, pthread_mutex_unlock((L)))
174
#ifndef thread_safe_add
175
#define thread_safe_add(V,C,L) \
176
(pthread_mutex_lock((L)), (V)+=(C), pthread_mutex_unlock((L)))
177
#define thread_safe_sub(V,C,L) \
178
(pthread_mutex_lock((L)), (V)-=(C), pthread_mutex_unlock((L)))
181
129
} /* namespace internal */
182
130
} /* namespace drizzled */