drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
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#include <pthread.h>
24#ifndef _REENTRANT
25#define _REENTRANT
26#endif
27#include <sched.h>
28
29#include <drizzled/visibility.h>
30
31namespace drizzled {
32namespace internal {
33
34#if !defined(HAVE_PTHREAD_YIELD_ONE_ARG) && !defined(HAVE_PTHREAD_YIELD_ZERO_ARG)
35/* no pthread_yield() available */
36#define pthread_yield() sched_yield()
37#endif
38
39/*
40 The defines set_timespec and set_timespec_nsec should be used
41 for calculating an absolute time at which
42 pthread_cond_timedwait should timeout
43*/
44#ifndef set_timespec
45#define set_timespec(ABSTIME,SEC) \
46{\
47 struct timeval tv;\
48 gettimeofday(&tv,0);\
49 (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\
50 (ABSTIME).tv_nsec=tv.tv_usec*1000;\
51}
52#endif /* !set_timespec */
53#ifndef set_timespec_nsec
54#define set_timespec_nsec(ABSTIME,NSEC) \
55{\
56 boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());\
57 boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));\
58 uint64_t t_mark= (mytime-epoch).total_microseconds();\
59 uint64_t now= t_mark + (NSEC/100); \
60 (ABSTIME).tv_sec= (time_t) (now / 10000000UL); \
61 (ABSTIME).tv_nsec= (long) (now % 10000000UL * 100 + ((NSEC) % 100)); \
62}
63#endif /* !set_timespec_nsec */
64
65 /* Wrappers if safe mutex is actually used */
66#define safe_mutex_assert_owner(mp)
67#define safe_mutex_assert_not_owner(mp)
68
69 /* READ-WRITE thread locking */
70
71/* Define mutex types, see my_thr_init.c */
72#ifdef THREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
73extern pthread_mutexattr_t my_fast_mutexattr;
74#define MY_MUTEX_INIT_FAST &my_fast_mutexattr
75#else
76#define MY_MUTEX_INIT_FAST NULL
77#endif
78
79#ifndef ESRCH
80/* Define it to something */
81#define ESRCH 1
82#endif
83
84DRIZZLED_API void my_thread_init();
85
86} /* namespace internal */
87} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.
Visibility Control Macros.
#define DRIZZLED_API
Definition visibility.h:38