~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
/* Defines to make different thread packages compatible */
17
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
18
#ifndef DRIZZLED_INTERNAL_MY_PTHREAD_H
19
#define DRIZZLED_INTERNAL_MY_PTHREAD_H
1 by brian
clean slate
20
549 by Monty Taylor
Took gettext.h out of header files.
21
#include <unistd.h>
22
1878.10.1 by Billy Earney
removed my_micro_time, my_micro_time_and_time, along with my_getsystime and replaced with boost:date_time for compatibility between OS.
23
#include <boost/date_time.hpp>
24
1 by brian
clean slate
25
#ifndef ETIME
26
#define ETIME ETIMEDOUT				/* For FreeBSD */
27
#endif
28
29
#include <pthread.h>
30
#ifndef _REENTRANT
31
#define _REENTRANT
32
#endif
33
#ifdef HAVE_SCHED_H
34
#include <sched.h>
35
#endif
36
#ifdef HAVE_SYNCH_H
37
#include <synch.h>
38
#endif
39
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
40
namespace drizzled
41
{
42
namespace internal
43
{
44
1 by brian
clean slate
45
#define pthread_key(T,V) pthread_key_t V
598.1.1 by Super-User
Fixed solaris build crap.
46
#define pthread_handler_t void *
1 by brian
clean slate
47
typedef void *(* pthread_handler)(void *);
48
49
#if !defined(HAVE_PTHREAD_YIELD_ONE_ARG) && !defined(HAVE_PTHREAD_YIELD_ZERO_ARG)
50
/* no pthread_yield() available */
51
#ifdef HAVE_SCHED_YIELD
52
#define pthread_yield() sched_yield()
53
#elif defined(HAVE_PTHREAD_YIELD_NP) /* can be Mac OS X */
54
#define pthread_yield() pthread_yield_np()
55
#endif
56
#endif
57
58
/*
59
  The defines set_timespec and set_timespec_nsec should be used
60
  for calculating an absolute time at which
61
  pthread_cond_timedwait should timeout
62
*/
63
#ifndef set_timespec
64
#define set_timespec(ABSTIME,SEC) \
65
{\
66
  struct timeval tv;\
67
  gettimeofday(&tv,0);\
68
  (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\
69
  (ABSTIME).tv_nsec=tv.tv_usec*1000;\
70
}
71
#endif /* !set_timespec */
72
#ifndef set_timespec_nsec
73
#define set_timespec_nsec(ABSTIME,NSEC) \
74
{\
1878.10.1 by Billy Earney
removed my_micro_time, my_micro_time_and_time, along with my_getsystime and replaced with boost:date_time for compatibility between OS.
75
  boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());\
76
  boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));\
77
  uint64_t t_mark= (mytime-epoch).total_microseconds();\
78
  uint64_t now= t_mark + (NSEC/100); \
398.1.8 by Monty Taylor
Enabled -Wlong-long.
79
  (ABSTIME).tv_sec=  (time_t) (now / 10000000UL);                  \
80
  (ABSTIME).tv_nsec= (long) (now % 10000000UL * 100 + ((NSEC) % 100)); \
1 by brian
clean slate
81
}
82
#endif /* !set_timespec_nsec */
83
84
	/* Wrappers if safe mutex is actually used */
85
#define safe_mutex_assert_owner(mp)
86
#define safe_mutex_assert_not_owner(mp)
87
88
	/* READ-WRITE thread locking */
89
90
#if !defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) && ! defined(pthread_attr_setstacksize)
91
#define pthread_attr_setstacksize(A,B) pthread_dummy(0)
92
#endif
93
94
/* Define mutex types, see my_thr_init.c */
970.1.4 by Brian Aker
Removed dependency on internal_lock for session to lookup global table value
95
#ifdef THREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
1 by brian
clean slate
96
extern pthread_mutexattr_t my_fast_mutexattr;
97
#define MY_MUTEX_INIT_FAST &my_fast_mutexattr
98
#else
99
#define MY_MUTEX_INIT_FAST   NULL
100
#endif
101
102
#ifndef ESRCH
103
/* Define it to something */
104
#define ESRCH 1
105
#endif
106
146 by Brian Aker
my_bool cleanup.
107
extern bool my_thread_global_init(void);
1 by brian
clean slate
108
extern void my_thread_global_end(void);
146 by Brian Aker
my_bool cleanup.
109
extern bool my_thread_init(void);
1 by brian
clean slate
110
extern void my_thread_end(void);
111
extern const char *my_thread_name(void);
112
113
/* All thread specific variables are in the following struct */
114
1703.2.1 by David Shrewsbury
Make 0 thread_stack mean use the OS default
115
/**
116
  A default thread stack size of zero means that we are going to use
117
  the OS defined thread stack size (this varies from OS to OS).
118
 */
119
#define DEFAULT_THREAD_STACK	0
1 by brian
clean slate
120
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
121
} /* namespace internal */
122
} /* namespace drizzled */
123
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
124
#endif /* DRIZZLED_INTERNAL_MY_PTHREAD_H */