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 #pragma once
00019 
00020 #include <unistd.h>
00021 #include <boost/date_time.hpp>
00022 
00023 #ifndef ETIME
00024 #define ETIME ETIMEDOUT       /* For FreeBSD */
00025 #endif
00026 
00027 #include <pthread.h>
00028 #ifndef _REENTRANT
00029 #define _REENTRANT
00030 #endif
00031 #ifdef HAVE_SCHED_H
00032 #include <sched.h>
00033 #endif
00034 #ifdef HAVE_SYNCH_H
00035 #include <synch.h>
00036 #endif
00037 
00038 #include <drizzled/visibility.h>
00039 
00040 namespace drizzled {
00041 namespace internal {
00042 
00043 #if !defined(HAVE_PTHREAD_YIELD_ONE_ARG) && !defined(HAVE_PTHREAD_YIELD_ZERO_ARG)
00044 /* no pthread_yield() available */
00045 #ifdef HAVE_SCHED_YIELD
00046 #define pthread_yield() sched_yield()
00047 #elif defined(HAVE_PTHREAD_YIELD_NP) /* can be Mac OS X */
00048 #define pthread_yield() pthread_yield_np()
00049 #endif
00050 #endif
00051 
00052 /*
00053   The defines set_timespec and set_timespec_nsec should be used
00054   for calculating an absolute time at which
00055   pthread_cond_timedwait should timeout
00056 */
00057 #ifndef set_timespec
00058 #define set_timespec(ABSTIME,SEC) \
00059 {\
00060   struct timeval tv;\
00061   gettimeofday(&tv,0);\
00062   (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\
00063   (ABSTIME).tv_nsec=tv.tv_usec*1000;\
00064 }
00065 #endif /* !set_timespec */
00066 #ifndef set_timespec_nsec
00067 #define set_timespec_nsec(ABSTIME,NSEC) \
00068 {\
00069   boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());\
00070   boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));\
00071   uint64_t t_mark= (mytime-epoch).total_microseconds();\
00072   uint64_t now= t_mark + (NSEC/100); \
00073   (ABSTIME).tv_sec=  (time_t) (now / 10000000UL);                  \
00074   (ABSTIME).tv_nsec= (long) (now % 10000000UL * 100 + ((NSEC) % 100)); \
00075 }
00076 #endif /* !set_timespec_nsec */
00077 
00078   /* Wrappers if safe mutex is actually used */
00079 #define safe_mutex_assert_owner(mp)
00080 #define safe_mutex_assert_not_owner(mp)
00081 
00082   /* READ-WRITE thread locking */
00083 
00084 #if !defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) && ! defined(pthread_attr_setstacksize)
00085 #define pthread_attr_setstacksize(A,B) pthread_dummy(0)
00086 #endif
00087 
00088 /* Define mutex types, see my_thr_init.c */
00089 #ifdef THREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
00090 extern pthread_mutexattr_t my_fast_mutexattr;
00091 #define MY_MUTEX_INIT_FAST &my_fast_mutexattr
00092 #else
00093 #define MY_MUTEX_INIT_FAST   NULL
00094 #endif
00095 
00096 #ifndef ESRCH
00097 /* Define it to something */
00098 #define ESRCH 1
00099 #endif
00100 
00101 DRIZZLED_API void my_thread_init();
00102 
00103 } /* namespace internal */
00104 } /* namespace drizzled */
00105