summaryrefslogtreecommitdiff
path: root/include/my_pthread.h
diff options
context:
space:
mode:
authorunknown <tsmith/tim@siva.hindu.god>2006-12-26 16:49:10 -0700
committerunknown <tsmith/tim@siva.hindu.god>2006-12-26 16:49:10 -0700
commit6e84e11da5f4d9168005f48c90fd169047a9e950 (patch)
treee6bcbe8baaed6b27ac43fd5aa816ebe6f1e949f8 /include/my_pthread.h
parent4dabfa5de70c59c4f7ea1e4a33224c5a3f798d66 (diff)
parente87d593ae1598c4e93da59ba249bb01a649c5772 (diff)
downloadmariadb-git-6e84e11da5f4d9168005f48c90fd169047a9e950.tar.gz
Merge siva.hindu.god:/usr/home/tim/m/bk/g51
into siva.hindu.god:/usr/home/tim/m/bk/tmp/mrg51-dec26 Makefile.am: Auto merged client/mysqlbinlog.cc: Auto merged configure.in: Auto merged client/mysqltest.c: Auto merged include/config-win.h: Auto merged include/my_global.h: Auto merged include/my_pthread.h: Auto merged include/mysql.h: Auto merged include/typelib.h: Auto merged mysql-test/Makefile.am: Auto merged mysql-test/r/sp.result: Auto merged mysql-test/r/type_timestamp.result: Auto merged mysql-test/r/warnings.result: Auto merged mysys/default.c: Auto merged mysys/my_wincond.c: Auto merged mysys/typelib.c: Auto merged server-tools/instance-manager/Makefile.am: Auto merged server-tools/instance-manager/guardian.cc: Auto merged server-tools/instance-manager/instance.cc: Auto merged sql/field.cc: Auto merged sql/item_sum.cc: Auto merged sql/item_sum.h: Auto merged sql/net_serv.cc: Auto merged sql/opt_range.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_parse.cc: Auto merged sql/share/charsets/hebrew.xml: Auto merged sql/sql_show.cc: Auto merged storage/federated/ha_federated.cc: Auto merged strings/conf_to_src.c: Auto merged vio/viossl.c: Auto merged sql/field.h: Manual merge sql/log_event.cc: Manual merge
Diffstat (limited to 'include/my_pthread.h')
-rw-r--r--include/my_pthread.h78
1 files changed, 71 insertions, 7 deletions
diff --git a/include/my_pthread.h b/include/my_pthread.h
index 17b7b98da02..b608f3ee647 100644
--- a/include/my_pthread.h
+++ b/include/my_pthread.h
@@ -55,16 +55,41 @@ typedef struct {
} pthread_cond_t;
-struct timespec { /* For pthread_cond_timedwait() */
- time_t tv_sec;
- long tv_nsec;
-};
-
typedef int pthread_mutexattr_t;
#define win_pthread_self my_thread_var->pthread_self
#define pthread_handler_t EXTERNC void * __cdecl
typedef void * (__cdecl *pthread_handler)(void *);
+/*
+ Struct and macros to be used in combination with the
+ windows implementation of pthread_cond_timedwait
+*/
+
+/*
+ Declare a union to make sure FILETIME is properly aligned
+ so it can be used directly as a 64 bit value. The value
+ stored is in 100ns units.
+ */
+ union ft64 {
+ FILETIME ft;
+ __int64 i64;
+ };
+struct timespec {
+ union ft64 tv;
+ /* The max timeout value in millisecond for pthread_cond_timedwait */
+ long max_timeout_msec;
+};
+#define set_timespec(ABSTIME,SEC) { \
+ GetSystemTimeAsFileTime(&((ABSTIME).tv.ft)); \
+ (ABSTIME).tv.i64+= (__int64)(SEC)*10000000; \
+ (ABSTIME).max_timeout_msec= (long)((SEC)*1000); \
+}
+#define set_timespec_nsec(ABSTIME,NSEC) { \
+ GetSystemTimeAsFileTime(&((ABSTIME).tv.ft)); \
+ (ABSTIME).tv.i64+= (__int64)(NSEC)/100; \
+ (ABSTIME).max_timeout_msec= (long)((NSEC)/1000000); \
+}
+
void win_pthread_init(void);
int win_pthread_setspecific(void *A,void *B,uint length);
int pthread_create(pthread_t *,pthread_attr_t *,pthread_handler,void *);
@@ -140,8 +165,6 @@ void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/
#define pthread_condattr_init(A)
#define pthread_condattr_destroy(A)
-/*Irena: compiler does not like this: */
-/*#define my_pthread_getprio(pthread_t thread_id) pthread_dummy(0) */
#define my_pthread_getprio(thread_id) pthread_dummy(0)
#else /* Normal threads */
@@ -366,6 +389,47 @@ void my_pthread_attr_getstacksize(pthread_attr_t *attrib, size_t *size);
int my_pthread_mutex_trylock(pthread_mutex_t *mutex);
#endif
+/*
+ The defines set_timespec and set_timespec_nsec should be used
+ for calculating an absolute time at which
+ pthread_cond_timedwait should timeout
+*/
+#ifdef HAVE_TIMESPEC_TS_SEC
+#ifndef set_timespec
+#define set_timespec(ABSTIME,SEC) \
+{ \
+ (ABSTIME).ts_sec=time(0) + (time_t) (SEC); \
+ (ABSTIME).ts_nsec=0; \
+}
+#endif /* !set_timespec */
+#ifndef set_timespec_nsec
+#define set_timespec_nsec(ABSTIME,NSEC) \
+{ \
+ ulonglong now= my_getsystime() + (NSEC/100); \
+ (ABSTIME).ts_sec= (now / ULL(10000000)); \
+ (ABSTIME).ts_nsec= (now % ULL(10000000) * 100 + ((NSEC) % 100)); \
+}
+#endif /* !set_timespec_nsec */
+#else
+#ifndef set_timespec
+#define set_timespec(ABSTIME,SEC) \
+{\
+ struct timeval tv;\
+ gettimeofday(&tv,0);\
+ (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\
+ (ABSTIME).tv_nsec=tv.tv_usec*1000;\
+}
+#endif /* !set_timespec */
+#ifndef set_timespec_nsec
+#define set_timespec_nsec(ABSTIME,NSEC) \
+{\
+ ulonglong now= my_getsystime() + (NSEC/100); \
+ (ABSTIME).tv_sec= (time_t) (now / ULL(10000000)); \
+ (ABSTIME).tv_nsec= (long) (now % ULL(10000000) * 100 + ((NSEC) % 100)); \
+}
+#endif /* !set_timespec_nsec */
+#endif /* HAVE_TIMESPEC_TS_SEC */
+
/* safe_mutex adds checking to mutex for easier debugging */
#if defined(__NETWARE__) && !defined(SAFE_MUTEX_DETECT_DESTROY)