Drizzled Public API Documentation

my_pthread.h
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
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 /* Defines to make different thread packages compatible */
17 
18 #pragma once
19 
20 #include <unistd.h>
21 #include <boost/date_time.hpp>
22 
23 #ifndef ETIME
24 #define ETIME ETIMEDOUT /* For FreeBSD */
25 #endif
26 
27 #include <pthread.h>
28 #ifndef _REENTRANT
29 #define _REENTRANT
30 #endif
31 #ifdef HAVE_SCHED_H
32 #include <sched.h>
33 #endif
34 #ifdef HAVE_SYNCH_H
35 #include <synch.h>
36 #endif
37 
38 #include <drizzled/visibility.h>
39 
40 namespace drizzled {
41 namespace internal {
42 
43 #if !defined(HAVE_PTHREAD_YIELD_ONE_ARG) && !defined(HAVE_PTHREAD_YIELD_ZERO_ARG)
44 /* no pthread_yield() available */
45 #ifdef HAVE_SCHED_YIELD
46 #define pthread_yield() sched_yield()
47 #elif defined(HAVE_PTHREAD_YIELD_NP) /* can be Mac OS X */
48 #define pthread_yield() pthread_yield_np()
49 #endif
50 #endif
51 
52 /*
53  The defines set_timespec and set_timespec_nsec should be used
54  for calculating an absolute time at which
55  pthread_cond_timedwait should timeout
56 */
57 #ifndef set_timespec
58 #define set_timespec(ABSTIME,SEC) \
59 {\
60  struct timeval tv;\
61  gettimeofday(&tv,0);\
62  (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\
63  (ABSTIME).tv_nsec=tv.tv_usec*1000;\
64 }
65 #endif /* !set_timespec */
66 #ifndef set_timespec_nsec
67 #define set_timespec_nsec(ABSTIME,NSEC) \
68 {\
69  boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());\
70  boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));\
71  uint64_t t_mark= (mytime-epoch).total_microseconds();\
72  uint64_t now= t_mark + (NSEC/100); \
73  (ABSTIME).tv_sec= (time_t) (now / 10000000UL); \
74  (ABSTIME).tv_nsec= (long) (now % 10000000UL * 100 + ((NSEC) % 100)); \
75 }
76 #endif /* !set_timespec_nsec */
77 
78  /* Wrappers if safe mutex is actually used */
79 #define safe_mutex_assert_owner(mp)
80 #define safe_mutex_assert_not_owner(mp)
81 
82  /* READ-WRITE thread locking */
83 
84 #if !defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) && ! defined(pthread_attr_setstacksize)
85 #define pthread_attr_setstacksize(A,B) pthread_dummy(0)
86 #endif
87 
88 /* Define mutex types, see my_thr_init.c */
89 #ifdef THREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
90 extern pthread_mutexattr_t my_fast_mutexattr;
91 #define MY_MUTEX_INIT_FAST &my_fast_mutexattr
92 #else
93 #define MY_MUTEX_INIT_FAST NULL
94 #endif
95 
96 #ifndef ESRCH
97 /* Define it to something */
98 #define ESRCH 1
99 #endif
100 
101 DRIZZLED_API void my_thread_init();
102 
103 } /* namespace internal */
104 } /* namespace drizzled */
105 
#define DRIZZLED_API
Definition: visibility.h:62
Visibility Control Macros.