Forráskód Böngészése

Add --with-pthread etc to configure script
Fix bugs in counter.c, r.mapcalc


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@34487 15284696-431f-4ddb-bdfa-cd5b030d7da7

Glynn Clements 16 éve
szülő
commit
e4164ed7e4

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 1008 - 732
configure


+ 39 - 0
configure.in

@@ -195,6 +195,7 @@ LOC_ARG_WITH(nls, NLS, no)
 LOC_ARG_WITH(readline, Readline, no)
 LOC_ARG_WITH(opendwg, openDWG, no)
 LOC_ARG_WITH(regex, regex)
+LOC_ARG_WITH(pthread, POSIX threads, no)
 AC_ARG_WITH(python,
 [  --with-python[=path/python-config] enable support for Python SWIG bindings (python-config with path, \
 e.g. '--with-python=/usr/bin/python2.5-config', default: no)],, with_python="no")
@@ -277,6 +278,9 @@ LOC_ARG_WITH_LIB(opendwg, openDWG)
 LOC_ARG_WITH_INC(regex, regex)
 LOC_ARG_WITH_LIB(regex, regex)
 
+LOC_ARG_WITH_INC(pthread, POSIX threads)
+LOC_ARG_WITH_LIB(pthread, POSIX threads)
+
 # Put this early on so CPPFLAGS and LDFLAGS have any additional dirs
 
 # With includes option
@@ -1517,6 +1521,39 @@ AC_SUBST(USE_OPENDWG)
 
 # Done checking OPENDWG
 
+# Enable pthread option
+
+LOC_CHECK_USE(pthread,POSIX threads,USE_PTHREAD)
+
+PTHREADINCPATH=
+PTHREADLIBPATH=
+PTHREADLIB=
+
+if test -n "$USE_PTHREAD"; then
+
+# With pthread includes directory
+
+LOC_CHECK_INC_PATH(pthread,POSIX threads,PTHREADINCPATH)
+
+LOC_CHECK_INCLUDES(pthread.h,POSIX threads,$PTHREADINCPATH)
+
+# With pthread library directory
+
+LOC_CHECK_LIB_PATH(pthread,POSIX threads,PTHREADLIBPATH)
+
+LOC_CHECK_FUNC(pthread_create,POSIX threads functions,PTHREADLIB,,,,,[
+LOC_CHECK_LIBS(pthread,pthread_create,POSIX threads,$PTHREADLIBPATH,PTHREADLIB,,,)
+])
+
+fi # $USE_PTHREAD
+
+AC_SUBST(PTHREADINCPATH)
+AC_SUBST(PTHREADLIBPATH)
+AC_SUBST(PTHREADLIB)
+AC_SUBST(USE_PTHREAD)
+
+# Done checking pthread
+
 # Enable LFS (from cdr-tools)
 dnl Check for large file support
 dnl Do this last to make sure that no large file definition
@@ -1719,4 +1756,6 @@ LOC_MSG_USE(Tcl/Tk support,USE_TCLTK)
 LOC_MSG_USE(wxWidgets support,USE_WXWIDGETS)
 LOC_MSG_USE(TIFF support,USE_TIFF)
 LOC_MSG_USE(X11 support,USE_X11)
+LOC_MSG_USE(Regex support,USE_REGEX)
+LOC_MSG_USE(POSIX thread support,USE_PTHREAD)
 LOC_MSG()

+ 6 - 0
include/Make/Platform.make.in

@@ -231,6 +231,12 @@ REGEXLIBPATH        = @REGEXLIBPATH@
 REGEXLIB            = @REGEXLIB@
 USE_REGEX           = @USE_REGEX@
 
+#pthreads
+PTHREADINCPATH      = @PTHREADINCPATH@
+PTHREADLIBPATH      = @PTHREADLIBPATH@
+PTHREADLIB          = @PTHREADLIB@
+USE_PTHREAD         = @USE_PTHREAD@
+
 #i18N
 HAVE_NLS            = @HAVE_NLS@
 

+ 3 - 0
include/config.h.in

@@ -236,6 +236,9 @@
 /* define if regex.h exists */
 #undef HAVE_REGEX_H
 
+/* define if pthread.h exists */
+#undef HAVE_PTHREAD_H
+
 /*
  * configuration information solely dependent on the above
  * nothing below this point should need changing

+ 2 - 8
lib/gis/Makefile

@@ -4,9 +4,9 @@ GDAL_LINK = $(USE_GDAL)
 GDAL_DYNAMIC = 1
 
 LIB_NAME = $(GIS_LIBNAME)
-EXTRA_LIBS = $(XDRLIB) $(SOCKLIB) $(DATETIMELIB) $(INTLLIB) $(MATHLIB)
+EXTRA_LIBS = $(XDRLIB) $(SOCKLIB) $(DATETIMELIB) $(PTHREADLIBPATH) $(PTHREADLIB) $(INTLLIB) $(MATHLIB)
 DATASRC = ellipse.table datum.table datumtransform.table FIPS.code state27 state83 projections gui.tcl
-EXTRA_INC = $(ZLIBINCPATH)
+EXTRA_INC = $(ZLIBINCPATH) $(PTHREADINCPATH)
 
 include $(MODULE_TOPDIR)/include/Make/Lib.make
 include $(MODULE_TOPDIR)/include/Make/Doxygen.make
@@ -37,12 +37,6 @@ endif
 
 endif
 
-ifneq ($(USE_PTHREAD),)
-PTHREADLIB = -lpthread
-EXTRA_CFLAGS += -DUSE_PTHREAD
-EXTRA_LIBS += $(PTHREADLIB)
-endif
-
 default: lib $(FMODE_OBJ) $(DATAFILES) $(COLORFILES) $(ETC)/colors.desc $(ETC)/element_list
 
 $(FMODE_OBJ): fmode.dat

+ 30 - 26
lib/gis/counter.c

@@ -1,32 +1,15 @@
+#include <grass/config.h>
+#ifdef HAVE_PTHREAD_H
+#define _XOPEN_SOURCE 500
+#endif
 #include <grass/gis.h>
 
-#ifdef USE_PTHREADS
+#ifdef HAVE_PTHREAD_H
 #include <pthread.h>
 static pthread_mutex_t mutex;
 #endif
 
-void G_init_counter(struct Counter *c, int v)
-{
-#ifdef USE_PTHREADS
-    make_mutex();
-#endif
-    c->value = v;
-}
-
-int G_counter_next(struct Counter *c)
-{
-    int v;
-#ifdef USE_PTHREADS
-    pthread_mutex_lock(&mutex);
-#endif
-    v = c->value++;
-#ifdef USE_PTHREADS
-    pthread_mutex_unlock(&mutex);
-#endif
-    return v;
-}
-
-#ifdef USE_PTHREADS
+#ifdef HAVE_PTHREAD_H
 static void make_mutex(void)
 {
     static pthread_mutex_t t_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -45,19 +28,40 @@ static void make_mutex(void)
 
     pthread_mutexattr_init(&attr);
     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-    pthread_mutex_init(&r_mutex, &attr);
+    pthread_mutex_init(&mutex, &attr);
     initialized = 1;
 
     pthread_mutex_unlock(&t_mutex);
 }
 #endif
 
+void G_init_counter(struct Counter *c, int v)
+{
+#ifdef HAVE_PTHREAD_H
+    make_mutex();
+#endif
+    c->value = v;
+}
+
+int G_counter_next(struct Counter *c)
+{
+    int v;
+#ifdef HAVE_PTHREAD_H
+    pthread_mutex_lock(&mutex);
+#endif
+    v = c->value++;
+#ifdef HAVE_PTHREAD_H
+    pthread_mutex_unlock(&mutex);
+#endif
+    return v;
+}
+
 int G_is_initialized(int *p)
 {
     if (*p)
 	return 1;
 
-#ifdef USE_PTHREADS
+#ifdef HAVE_PTHREAD_H
     make_mutex();
     pthread_mutex_lock(&mutex);
 #endif
@@ -68,7 +72,7 @@ void G_initialize_done(int *p)
 {
     *p = 1;
 
-#ifdef USE_PTHREADS
+#ifdef HAVE_PTHREAD_H
     pthread_mutex_unlock(&mutex);
 #endif
 }

+ 2 - 1
lib/gis/worker.c

@@ -4,7 +4,7 @@
 #include <grass/gis.h>
 #include <grass/glocale.h>
 
-#ifdef USE_PTHREAD
+#ifdef HAVE_PTHREAD_H
 
 /****************************************************************************/
 
@@ -132,6 +132,7 @@ void G_finish_workers(void)
     for (i = 0; i < num_workers; i++) {
 	struct worker *w = &workers[i];
 	w->cancel = 1;
+	pthread_cancel(w->thread);
     }
 
     for (i = 0; i < num_workers; i++) {

+ 3 - 10
raster/r.mapcalc/Makefile

@@ -11,16 +11,9 @@ r3_mapcalc_OBJS := $(filter-out map.o xcoor.o xres.o, $(AUTO_OBJS))
 
 include $(MODULE_TOPDIR)/include/Make/Multi.make
 
-EXTRA_CFLAGS = $(READLINEINCPATH)
-LIBES2 = $(GISLIB) $(BTREELIB) $(ROWIOLIB) $(READLINELIBPATH) $(READLINELIB) $(HISTORYLIB)
-LIBES3 = $(G3DLIB) $(GISLIB) $(BTREELIB) $(READLINELIBPATH) $(READLINELIB) $(HISTORYLIB)
-
-ifneq ($(USE_PTHREAD),)
-PTHREADLIB = -lpthread
-EXTRA_CFLAGS += -DUSE_PTHREAD
-LIBES2 += $(PTHREADLIB)
-LIBES3 += $(PTHREADLIB)
-endif
+EXTRA_CFLAGS = $(READLINEINCPATH) $(PTHREADINCPATH)
+LIBES2 =           $(GISLIB) $(BTREELIB) $(READLINELIBPATH) $(READLINELIB) $(HISTORYLIB) $(PTHREADLIBPATH) $(PTHREADLIB)
+LIBES3 = $(G3DLIB) $(GISLIB) $(BTREELIB) $(READLINELIBPATH) $(READLINELIB) $(HISTORYLIB) $(PTHREADLIBPATH) $(PTHREADLIB)
 
 default: multi
 

+ 1 - 1
raster/r.mapcalc/evaluate.c

@@ -103,7 +103,7 @@ static void do_evaluate(void *p)
 
 static void begin_evaluate(struct expression *e)
 {
-    G_begin_execute(do_evaluate, e, &e->worker, 1);
+    G_begin_execute(do_evaluate, e, &e->worker, 0);
 }
 
 static void end_evaluate(struct expression *e)

+ 11 - 11
raster/r.mapcalc/map.c

@@ -3,7 +3,7 @@
 #include <limits.h>
 #include <string.h>
 #include <unistd.h>
-#ifdef USE_PTHREAD
+#ifdef HAVE_PTHREAD_H
 #include <pthread.h>
 #endif
 
@@ -57,7 +57,7 @@ struct map
     struct Colors colors;
     BTREE btree;
     struct row_cache cache;
-#ifdef USE_PTHREAD
+#ifdef HAVE_PTHREAD_H
     pthread_mutex_t mutex;
 #endif
 };
@@ -75,7 +75,7 @@ static int max_col = -INT_MAX;
 
 static int max_rows_in_memory = 8;
 
-#ifdef USE_PTHREAD
+#ifdef HAVE_PTHREAD_H
 static pthread_mutex_t cats_mutex;
 #endif
 
@@ -307,7 +307,7 @@ static void translate_from_cats(struct map *m, CELL * cell, DCELL * xcell,
     void *ptr;
     char *label;
 
-#ifdef XUSE_PTHREAD
+#ifdef HAVE_PTHREAD_H
     pthread_mutex_lock(&cats_mutex);
 #endif
 
@@ -355,7 +355,7 @@ static void translate_from_cats(struct map *m, CELL * cell, DCELL * xcell,
 	    *xcell = values[idx];
     }
 
-#ifdef XUSE_PTHREAD
+#ifdef HAVE_PTHREAD_H
     pthread_mutex_unlock(&cats_mutex);
 #endif
 }
@@ -370,7 +370,7 @@ static void setup_map(struct map *m)
 {
     int nrows = m->max_row - m->min_row + 1;
 
-#ifdef USE_PTHREAD
+#ifdef HAVE_PTHREAD_H
     pthread_mutex_init(&m->mutex, NULL);
 #endif
 
@@ -430,7 +430,7 @@ static void close_map(struct map *m)
 	G_fatal_error(_("Unable to close raster map <%s@%s>"),
 		      m->name, m->mapset);
 
-#ifdef USE_PTHREAD
+#ifdef HAVE_PTHREAD_H
     pthread_mutex_destroy(&m->mutex);
 #endif
 
@@ -579,7 +579,7 @@ void setup_maps(void)
 {
     int i;
 
-#ifdef USE_PTHREAD
+#ifdef HAVE_PTHREAD_H
     pthread_mutex_init(&cats_mutex, NULL);
 #endif
 
@@ -594,7 +594,7 @@ void get_map_row(int idx, int mod, int depth, int row, int col, void *buf,
     DCELL *fbuf;
     struct map *m = &maps[idx];
 
-#ifdef USE_PTHREAD
+#ifdef HAVE_PTHREAD_H
     pthread_mutex_lock(&m->mutex);
 #endif
 
@@ -624,7 +624,7 @@ void get_map_row(int idx, int mod, int depth, int row, int col, void *buf,
 	break;
     }
 
-#ifdef USE_PTHREAD
+#ifdef HAVE_PTHREAD_H
     pthread_mutex_unlock(&m->mutex);
 #endif
 }
@@ -638,7 +638,7 @@ void close_maps(void)
 
     num_maps = 0;
 
-#ifdef USE_PTHREAD
+#ifdef HAVE_PTHREAD_H
     pthread_mutex_destroy(&cats_mutex);
 #endif
 }