~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
 
44
44
#define pthread_handler_t void *
45
45
typedef void *(* pthread_handler)(void *);
46
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
 
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
76
84
}
77
85
#endif /* !set_timespec_nsec */
78
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
 
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)
107
137
 
108
138
/* All thread specific variables are in the following struct */
109
139
 
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
 
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)
115
215
 
116
216
} /* namespace internal */
117
217
} /* namespace drizzled */