Quellcode durchsuchen

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 vor 16 Jahren
Ursprung
Commit
e4164ed7e4
10 geänderte Dateien mit 1105 neuen und 789 gelöschten Zeilen
  1. 1008 732
      configure
  2. 39 0
      configure.in
  3. 6 0
      include/Make/Platform.make.in
  4. 3 0
      include/config.h.in
  5. 2 8
      lib/gis/Makefile
  6. 30 26
      lib/gis/counter.c
  7. 2 1
      lib/gis/worker.c
  8. 3 10
      raster/r.mapcalc/Makefile
  9. 1 1
      raster/r.mapcalc/evaluate.c
  10. 11 11
      raster/r.mapcalc/map.c

Datei-Diff unterdrückt, da er zu groß ist
+ 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(readline, Readline, no)
 LOC_ARG_WITH(opendwg, openDWG, no)
 LOC_ARG_WITH(opendwg, openDWG, no)
 LOC_ARG_WITH(regex, regex)
 LOC_ARG_WITH(regex, regex)
+LOC_ARG_WITH(pthread, POSIX threads, no)
 AC_ARG_WITH(python,
 AC_ARG_WITH(python,
 [  --with-python[=path/python-config] enable support for Python SWIG bindings (python-config with path, \
 [  --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")
 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_INC(regex, regex)
 LOC_ARG_WITH_LIB(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
 # Put this early on so CPPFLAGS and LDFLAGS have any additional dirs
 
 
 # With includes option
 # With includes option
@@ -1517,6 +1521,39 @@ AC_SUBST(USE_OPENDWG)
 
 
 # Done checking 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)
 # Enable LFS (from cdr-tools)
 dnl Check for large file support
 dnl Check for large file support
 dnl Do this last to make sure that no large file definition
 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(wxWidgets support,USE_WXWIDGETS)
 LOC_MSG_USE(TIFF support,USE_TIFF)
 LOC_MSG_USE(TIFF support,USE_TIFF)
 LOC_MSG_USE(X11 support,USE_X11)
 LOC_MSG_USE(X11 support,USE_X11)
+LOC_MSG_USE(Regex support,USE_REGEX)
+LOC_MSG_USE(POSIX thread support,USE_PTHREAD)
 LOC_MSG()
 LOC_MSG()

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

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

+ 3 - 0
include/config.h.in

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

+ 2 - 8
lib/gis/Makefile

@@ -4,9 +4,9 @@ GDAL_LINK = $(USE_GDAL)
 GDAL_DYNAMIC = 1
 GDAL_DYNAMIC = 1
 
 
 LIB_NAME = $(GIS_LIBNAME)
 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
 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/Lib.make
 include $(MODULE_TOPDIR)/include/Make/Doxygen.make
 include $(MODULE_TOPDIR)/include/Make/Doxygen.make
@@ -37,12 +37,6 @@ endif
 
 
 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
 default: lib $(FMODE_OBJ) $(DATAFILES) $(COLORFILES) $(ETC)/colors.desc $(ETC)/element_list
 
 
 $(FMODE_OBJ): fmode.dat
 $(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>
 #include <grass/gis.h>
 
 
-#ifdef USE_PTHREADS
+#ifdef HAVE_PTHREAD_H
 #include <pthread.h>
 #include <pthread.h>
 static pthread_mutex_t mutex;
 static pthread_mutex_t mutex;
 #endif
 #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 void make_mutex(void)
 {
 {
     static pthread_mutex_t t_mutex = PTHREAD_MUTEX_INITIALIZER;
     static pthread_mutex_t t_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -45,19 +28,40 @@ static void make_mutex(void)
 
 
     pthread_mutexattr_init(&attr);
     pthread_mutexattr_init(&attr);
     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-    pthread_mutex_init(&r_mutex, &attr);
+    pthread_mutex_init(&mutex, &attr);
     initialized = 1;
     initialized = 1;
 
 
     pthread_mutex_unlock(&t_mutex);
     pthread_mutex_unlock(&t_mutex);
 }
 }
 #endif
 #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)
 int G_is_initialized(int *p)
 {
 {
     if (*p)
     if (*p)
 	return 1;
 	return 1;
 
 
-#ifdef USE_PTHREADS
+#ifdef HAVE_PTHREAD_H
     make_mutex();
     make_mutex();
     pthread_mutex_lock(&mutex);
     pthread_mutex_lock(&mutex);
 #endif
 #endif
@@ -68,7 +72,7 @@ void G_initialize_done(int *p)
 {
 {
     *p = 1;
     *p = 1;
 
 
-#ifdef USE_PTHREADS
+#ifdef HAVE_PTHREAD_H
     pthread_mutex_unlock(&mutex);
     pthread_mutex_unlock(&mutex);
 #endif
 #endif
 }
 }

+ 2 - 1
lib/gis/worker.c

@@ -4,7 +4,7 @@
 #include <grass/gis.h>
 #include <grass/gis.h>
 #include <grass/glocale.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++) {
     for (i = 0; i < num_workers; i++) {
 	struct worker *w = &workers[i];
 	struct worker *w = &workers[i];
 	w->cancel = 1;
 	w->cancel = 1;
+	pthread_cancel(w->thread);
     }
     }
 
 
     for (i = 0; i < num_workers; i++) {
     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
 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
 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)
 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)
 static void end_evaluate(struct expression *e)

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

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