[gimp] pdb: Added a procedure to check how many processors GIMP is configured to use.



commit b22880c32f599eb082c52d06a43d40a6615976ee
Author: Barak Itkin <lightningismyname gmail com>
Date:   Fri Jul 9 02:31:07 2010 +0300

    pdb: Added a procedure to check how many processors GIMP is configured to use.
    
    Added the procedure get_number_of_processors to gimprc.pdb and regenerated the
    other files using pdbgen.

 app/pdb/gimprc-cmds.c       |   51 +++++++++++++++++++++++++++++++++++++++++++
 app/pdb/internal-procs.c    |    2 +-
 libgimp/gimpgimprc_pdb.c    |   34 ++++++++++++++++++++++++++++
 libgimp/gimpgimprc_pdb.h    |    1 +
 tools/pdbgen/pdb/gimprc.pdb |   40 ++++++++++++++++++++++++++++++++-
 5 files changed, 126 insertions(+), 2 deletions(-)
---
diff --git a/app/pdb/gimprc-cmds.c b/app/pdb/gimprc-cmds.c
index acb6800..cc905a5 100644
--- a/app/pdb/gimprc-cmds.c
+++ b/app/pdb/gimprc-cmds.c
@@ -29,6 +29,7 @@
 
 #include "pdb-types.h"
 
+#include "base/pixel-processor.h"
 #include "config/gimprc.h"
 #include "core/gimp-utils.h"
 #include "core/gimp.h"
@@ -226,6 +227,33 @@ get_module_load_inhibit_invoker (GimpProcedure      *procedure,
   return return_vals;
 }
 
+static GValueArray *
+get_number_of_processors_invoker (GimpProcedure      *procedure,
+                                  Gimp               *gimp,
+                                  GimpContext        *context,
+                                  GimpProgress       *progress,
+                                  const GValueArray  *args,
+                                  GError            **error)
+{
+  GValueArray *return_vals;
+  gint32 num_proc = 0;
+
+  gchar  *str;
+
+  str = gimp_rc_query (GIMP_RC (gimp->config), "num-processors");
+  num_proc = (gint32) g_ascii_strtoll (str, NULL, 0);
+
+  /* Although this is probably not necessary, still be safe */
+  num_proc = CLAMP (num_proc, 1, GIMP_MAX_NUM_THREADS);
+
+  g_free (str);
+
+  return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
+  g_value_set_int (&return_vals->values[1], num_proc);
+
+  return return_vals;
+}
+
 void
 register_gimprc_procs (GimpPDB *pdb)
 {
@@ -442,4 +470,27 @@ register_gimprc_procs (GimpPDB *pdb)
                                                            GIMP_PARAM_READWRITE));
   gimp_pdb_register_procedure (pdb, procedure);
   g_object_unref (procedure);
+
+  /*
+   * gimp-get-number-of-processors
+   */
+  procedure = gimp_procedure_new (get_number_of_processors_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-get-number-of-processors");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-get-number-of-processors",
+                                     "Get the number of processors which GIMP was configured to use.",
+                                     "Returns the number of processors which GIMP was configured to use. This value is taken from the Preferences and there's no guarantee for the value to be reasonable. This function is mainly intended for plugin writers who want to write multithreaded plugins and need to know how many threads to create.",
+                                     "Barak Itkin <lightningismyname gmail com>",
+                                     "Barak Itkin",
+                                     "2010",
+                                     NULL);
+  gimp_procedure_add_return_value (procedure,
+                                   gimp_param_spec_int32 ("num-proc",
+                                                          "num proc",
+                                                          "The number of processors",
+                                                          1, GIMP_MAX_NUM_THREADS, 1,
+                                                          GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
 }
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index cbe9a72..c8a6aae 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 602 procedures registered total */
+/* 603 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimpgimprc_pdb.c b/libgimp/gimpgimprc_pdb.c
index b67846d..209c0cf 100644
--- a/libgimp/gimpgimprc_pdb.c
+++ b/libgimp/gimpgimprc_pdb.c
@@ -294,3 +294,37 @@ gimp_get_module_load_inhibit (void)
 
   return load_inhibit;
 }
+
+/**
+ * gimp_get_number_of_processors:
+ *
+ * Get the number of processors which GIMP was configured to use.
+ *
+ * Returns the number of processors which GIMP was configured to use.
+ * This value is taken from the Preferences and there's no guarantee
+ * for the value to be reasonable. This function is mainly intended for
+ * plugin writers who want to write multithreaded plugins and need to
+ * know how many threads to create.
+ *
+ * Returns: The number of processors.
+ *
+ * Since: GIMP 2.8
+ */
+gint
+gimp_get_number_of_processors (void)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gint num_proc = 0;
+
+  return_vals = gimp_run_procedure ("gimp-get-number-of-processors",
+                                    &nreturn_vals,
+                                    GIMP_PDB_END);
+
+  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+    num_proc = return_vals[1].data.d_int32;
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return num_proc;
+}
diff --git a/libgimp/gimpgimprc_pdb.h b/libgimp/gimpgimprc_pdb.h
index d4f2005..dd8928d 100644
--- a/libgimp/gimpgimprc_pdb.h
+++ b/libgimp/gimpgimprc_pdb.h
@@ -38,6 +38,7 @@ gboolean               gimp_get_monitor_resolution   (gdouble     *xres,
 gchar*                 gimp_get_theme_dir            (void);
 G_GNUC_INTERNAL gchar* _gimp_get_color_configuration (void);
 gchar*                 gimp_get_module_load_inhibit  (void);
+gint                   gimp_get_number_of_processors (void);
 
 
 G_END_DECLS
diff --git a/tools/pdbgen/pdb/gimprc.pdb b/tools/pdbgen/pdb/gimprc.pdb
index b8863f6..ab5a20f 100644
--- a/tools/pdbgen/pdb/gimprc.pdb
+++ b/tools/pdbgen/pdb/gimprc.pdb
@@ -233,8 +233,45 @@ CODE
     );
 }
 
+sub get_number_of_processors {
+    $blurb = 'Get the number of processors which GIMP was configured to use.';
+    $help = <<'HELP';
+Returns the number of processors which GIMP was configured to use. This value
+is taken from the Preferences and there's no guarantee for the value to be
+reasonable. This function is mainly intended for plugin writers who want to
+write multithreaded plugins and need to know how many threads to create.
+HELP
+
+    	$author = 'Barak Itkin <lightningismyname gmail com>';
+	$copyright = 'Barak Itkin';
+	$date = '2010';
+	$since = '2.8';
+
+    @outargs = (
+	{  name => 'num_proc', type => '1 <= int32 <= GIMP_MAX_NUM_THREADS',
+	   desc => 'The number of processors' }
+    );
+
+    %invoke = (
+	code => <<'CODE'
+{
+  gchar  *str;
+
+  str = gimp_rc_query (GIMP_RC (gimp->config), "num-processors");
+  num_proc = (gint32) g_ascii_strtoll (str, NULL, 0);
+
+  /* Although this is probably not necessary, still be safe */
+  num_proc = CLAMP (num_proc, 1, GIMP_MAX_NUM_THREADS);
+
+  g_free (str);
+}
+CODE
+    );
+}
+
 
 @headers = qw(<string.h>
+              "base/pixel-processor.h"
               "config/gimprc.h"
               "core/gimp.h");
 
@@ -245,7 +282,8 @@ CODE
             get_monitor_resolution
 	    get_theme_dir
             get_color_configuration
-            get_module_load_inhibit);
+            get_module_load_inhibit
+            get_number_of_processors);
 
 %exports = (app => [ procs], lib => [ procs]);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]