Drizzled Public API Documentation

my_pthread.h
00001 /* Copyright (C) 2000 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 /* Defines to make different thread packages compatible */
00017 
00018 
00019 
00020 #pragma once
00021 
00022 #include <unistd.h>
00023 
00024 #include <boost/date_time.hpp>
00025 
00026 #ifndef ETIME
00027 #define ETIME ETIMEDOUT       /* For FreeBSD */
00028 #endif
00029 
00030 #include <pthread.h>
00031 #ifndef _REENTRANT
00032 #define _REENTRANT
00033 #endif
00034 #ifdef HAVE_SCHED_H
00035 #include <sched.h>
00036 #endif
00037 #ifdef HAVE_SYNCH_H
00038 #include <synch.h>
00039 #endif
00040 
00041 #include <drizzled/visibility.h>
00042 
00043 namespace drizzled
00044 {
00045 namespace internal
00046 {
00047 
00048 #define pthread_key(T,V) pthread_key_t V
00049 #define pthread_handler_t void *
00050 typedef void *(* pthread_handler)(void *);
00051 
00052 #if !defined(HAVE_PTHREAD_YIELD_ONE_ARG) && !defined(HAVE_PTHREAD_YIELD_ZERO_ARG)
00053 /* no pthread_yield() available */
00054 #ifdef HAVE_SCHED_YIELD
00055 #define pthread_yield() sched_yield()
00056 #elif defined(HAVE_PTHREAD_YIELD_NP) /* can be Mac OS X */
00057 #define pthread_yield() pthread_yield_np()
00058 #endif
00059 #endif
00060 
00061 /*
00062   The defines set_timespec and set_timespec_nsec should be used
00063   for calculating an absolute time at which
00064   pthread_cond_timedwait should timeout
00065 */
00066 #ifndef set_timespec
00067 #define set_timespec(ABSTIME,SEC) \
00068 {\
00069   struct timeval tv;\
00070   gettimeofday(&tv,0);\
00071   (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\
00072   (ABSTIME).tv_nsec=tv.tv_usec*1000;\
00073 }
00074 #endif /* !set_timespec */
00075 #ifndef set_timespec_nsec
00076 #define set_timespec_nsec(ABSTIME,NSEC) \
00077 {\
00078   boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());\
00079   boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));\
00080   uint64_t t_mark= (mytime-epoch).total_microseconds();\
00081   uint64_t now= t_mark + (NSEC/100); \
00082   (ABSTIME).tv_sec=  (time_t) (now / 10000000UL);                  \
00083   (ABSTIME).tv_nsec= (long) (now % 10000000UL * 100 + ((NSEC) % 100)); \
00084 }
00085 #endif /* !set_timespec_nsec */
00086 
00087   /* Wrappers if safe mutex is actually used */
00088 #define safe_mutex_assert_owner(mp)
00089 #define safe_mutex_assert_not_owner(mp)
00090 
00091   /* READ-WRITE thread locking */
00092 
00093 #if !defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) && ! defined(pthread_attr_setstacksize)
00094 #define pthread_attr_setstacksize(A,B) pthread_dummy(0)
00095 #endif
00096 
00097 /* Define mutex types, see my_thr_init.c */
00098 #ifdef THREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
00099 extern pthread_mutexattr_t my_fast_mutexattr;
00100 #define MY_MUTEX_INIT_FAST &my_fast_mutexattr
00101 #else
00102 #define MY_MUTEX_INIT_FAST   NULL
00103 #endif
00104 
00105 #ifndef ESRCH
00106 /* Define it to something */
00107 #define ESRCH 1
00108 #endif
00109 
00110 extern bool my_thread_global_init(void);
00111 extern void my_thread_global_end(void);
00112 DRIZZLED_API bool my_thread_init(void);
00113 DRIZZLED_API void my_thread_end(void);
00114 extern const char *my_thread_name(void);
00115 
00116 /* All thread specific variables are in the following struct */
00117 
00122 #define DEFAULT_THREAD_STACK  0
00123 
00124 } /* namespace internal */
00125 } /* namespace drizzled */
00126