Changeset: 635c9e9b87b1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=635c9e9b87b1
Modified Files:
gdk/gdk_posix.mx
gdk/gdk_system.mx
Branch: default
Log Message:
Moved definition of gprof_pthread_create to gdk_system.
Now the definition of pthread_create to gprof_pthread_create and the
definition of gprof_pthread_create itself are in the same file.
Note, pthread_create is only defined to gprof_pthread_create when
--enable-profile.
diffs (238 lines):
diff --git a/gdk/gdk_posix.mx b/gdk/gdk_posix.mx
--- a/gdk/gdk_posix.mx
+++ b/gdk/gdk_posix.mx
@@ -62,11 +62,6 @@
#ifdef NATIVE_WIN32
#include <io.h>
#include <direct.h>
-#else
-#ifdef PROFILE
-/* Linux gprof messes up on multithreaded programs */
-gdk_export int gprof_pthread_create(pthread_t * __restrict, __const
pthread_attr_t * __restrict, void *(*fcn) (void *), void *__restrict);
-#endif
#endif
/* Some systems (SGI, Sun) call malloc before we get a chance to call
@@ -1002,81 +997,6 @@
#endif
#endif
-#if !defined(WIN32) && defined(PROFILE)
-#ifdef HAVE_PTHREAD_H
-#undef pthread_create
-/* for profiling purposes (btw configure with --enable-profile *and*
--disable-shared --enable-static)
- * without setting the ITIMER_PROF per thread, all profiling info for
everything except the main thread is lost.
- */
-#include <stdlib.h>
-
-/* Our data structure passed to the wrapper */
-typedef struct wrapper_s {
- void *(*start_routine) (void *);
- void *arg;
-
- pthread_mutex_t lock;
- pthread_cond_t wait;
-
- struct itimerval itimer;
-
-} wrapper_t;
-
-/* The wrapper function in charge for setting the itimer value */
-static void *
-wrapper_routine(void *data)
-{
- /* Put user data in thread-local variables */
- void *(*start_routine) (void *) = ((wrapper_t *) data)->start_routine;
- void *arg = ((wrapper_t *) data)->arg;
-
- /* Set the profile timer value */
- setitimer(ITIMER_PROF, &((wrapper_t *) data)->itimer, NULL);
-
- /* Tell the calling thread that we don't need its data anymore */
- pthread_mutex_lock(&((wrapper_t *) data)->lock);
-
- pthread_cond_signal(&((wrapper_t *) data)->wait);
- pthread_mutex_unlock(&((wrapper_t *) data)->lock);
-
- /* Call the real function */
- return start_routine(arg);
-}
-
-/* Our wrapper function for the real pthread_create() */
-int
-gprof_pthread_create(pthread_t * __restrict thread, __const pthread_attr_t *
__restrict attr, void *(*start_routine) (void *), void *__restrict arg)
-{
- wrapper_t wrapper_data;
- int i_return;
-
- /* Initialize the wrapper structure */
- wrapper_data.start_routine = start_routine;
- wrapper_data.arg = arg;
- getitimer(ITIMER_PROF, &wrapper_data.itimer);
- pthread_cond_init(&wrapper_data.wait, NULL);
- pthread_mutex_init(&wrapper_data.lock, NULL);
- pthread_mutex_lock(&wrapper_data.lock);
-
- /* The real pthread_create call */
- i_return = pthread_create(thread, attr, &wrapper_routine,
&wrapper_data);
-
- /* If the thread was successfully spawned, wait for the data
- to be released */
- if (i_return == 0) {
- pthread_cond_wait(&wrapper_data.wait, &wrapper_data.lock);
- }
-
- pthread_mutex_unlock(&wrapper_data.lock);
- pthread_mutex_destroy(&wrapper_data.lock);
-
- pthread_cond_destroy(&wrapper_data.wait);
-
- return i_return;
-}
-#endif
-#endif
-
void
MT_init_posix(int alloc_map)
{
diff --git a/gdk/gdk_system.mx b/gdk/gdk_system.mx
--- a/gdk/gdk_system.mx
+++ b/gdk/gdk_system.mx
@@ -64,6 +64,8 @@
#ifndef WIN32
/* Linux gprof messes up on multithreaded programs */
#ifdef PROFILE
+/* Linux gprof messes up on multithreaded programs */
+gdk_export int gprof_pthread_create(pthread_t * __restrict, __const
pthread_attr_t * __restrict, void *(*fcn) (void *), void *__restrict);
#define pthread_create gprof_pthread_create
#endif
#endif
@@ -226,6 +228,23 @@
#include "monetdb_config.h"
#include "gdk_system.h"
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
+#ifndef HAVE_GETTIMEOFDAY
+#ifdef HAVE_FTIME
+#include <sys/timeb.h>
+#endif
+#endif
+
#ifdef HAVE_SIGNAL_H
# include <signal.h>
#endif
@@ -683,6 +702,80 @@
#endif
#endif
+#if !defined(WIN32) && defined(PROFILE) && defined(HAVE_PTHREAD_H)
+#undef pthread_create
+/* for profiling purposes (btw configure with --enable-profile *and*
+ --disable-shared --enable-static) without setting the ITIMER_PROF
+ per thread, all profiling info for everything except the main
+ thread is lost. */
+#include <stdlib.h>
+
+/* Our data structure passed to the wrapper */
+typedef struct wrapper_s {
+ void *(*start_routine) (void *);
+ void *arg;
+
+ pthread_mutex_t lock;
+ pthread_cond_t wait;
+
+ struct itimerval itimer;
+
+} wrapper_t;
+
+/* The wrapper function in charge for setting the itimer value */
+static void *
+wrapper_routine(void *data)
+{
+ /* Put user data in thread-local variables */
+ void *(*start_routine) (void *) = ((wrapper_t *) data)->start_routine;
+ void *arg = ((wrapper_t *) data)->arg;
+
+ /* Set the profile timer value */
+ setitimer(ITIMER_PROF, &((wrapper_t *) data)->itimer, NULL);
+
+ /* Tell the calling thread that we don't need its data anymore */
+ pthread_mutex_lock(&((wrapper_t *) data)->lock);
+
+ pthread_cond_signal(&((wrapper_t *) data)->wait);
+ pthread_mutex_unlock(&((wrapper_t *) data)->lock);
+
+ /* Call the real function */
+ return start_routine(arg);
+}
+
+/* Our wrapper function for the real pthread_create() */
+int
+gprof_pthread_create(pthread_t * __restrict thread, __const pthread_attr_t *
__restrict attr, void *(*start_routine) (void *), void *__restrict arg)
+{
+ wrapper_t wrapper_data;
+ int i_return;
+
+ /* Initialize the wrapper structure */
+ wrapper_data.start_routine = start_routine;
+ wrapper_data.arg = arg;
+ getitimer(ITIMER_PROF, &wrapper_data.itimer);
+ pthread_cond_init(&wrapper_data.wait, NULL);
+ pthread_mutex_init(&wrapper_data.lock, NULL);
+ pthread_mutex_lock(&wrapper_data.lock);
+
+ /* The real pthread_create call */
+ i_return = pthread_create(thread, attr, &wrapper_routine,
&wrapper_data);
+
+ /* If the thread was successfully spawned, wait for the data
+ to be released */
+ if (i_return == 0) {
+ pthread_cond_wait(&wrapper_data.wait, &wrapper_data.lock);
+ }
+
+ pthread_mutex_unlock(&wrapper_data.lock);
+ pthread_mutex_destroy(&wrapper_data.lock);
+
+ pthread_cond_destroy(&wrapper_data.wait);
+
+ return i_return;
+}
+#endif
+
/* coverity[+kill] */
void
MT_global_exit(int s)
@@ -798,23 +891,6 @@
gdk_export int GDKms(void);
@c
-#ifdef TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
-#endif
-
-#ifndef HAVE_GETTIMEOFDAY
-#ifdef HAVE_FTIME
-#include <sys/timeb.h>
-#endif
-#endif
-
lng
GDKusec(void)
{
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list