summaryrefslogtreecommitdiff
path: root/gs/psi
diff options
context:
space:
mode:
Diffstat (limited to 'gs/psi')
-rw-r--r--gs/psi/apitest.c99
-rw-r--r--gs/psi/iapi.c12
-rw-r--r--gs/psi/int.mak5
3 files changed, 110 insertions, 6 deletions
diff --git a/gs/psi/apitest.c b/gs/psi/apitest.c
new file mode 100644
index 000000000..7d0469377
--- /dev/null
+++ b/gs/psi/apitest.c
@@ -0,0 +1,99 @@
+#include <pthread.h>
+#include "ierrors.h"
+#include "iapi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define NUM_THREADS 10
+
+static int my_argc;
+static char **my_argv;
+static int my_argv_file;
+
+static void *gs_main(void *arg)
+{
+ int threadnum = (int)(void *)arg;
+ int code, code1;
+ char text[256];
+ void *minst;
+ char **gsargv;
+ int gsargc;
+ int i, pos, len;
+
+ gsargv = malloc(sizeof(*gsargv)*my_argc);
+ if (!gsargv)
+ {
+ fprintf(stderr, "Failed to allocate arg space in thread %d\n", threadnum);
+ return (void *)-1;
+ }
+
+ for (i=0; i < my_argc; i++)
+ gsargv[i] = my_argv[i];
+ gsargv[my_argv_file] = text;
+ gsargc = my_argc;
+
+ strncpy(text, my_argv[my_argv_file], sizeof(text));
+ text[sizeof(text)-1]=0;
+ pos = strlen(text);
+ len = sizeof(text)+1-pos;
+ snprintf(text+pos, len, "%d", threadnum);
+
+ code = gsapi_new_instance(&minst, NULL);
+ if (code < 0)
+ {
+ fprintf(stderr, "gsapi_new_instance failure in thread %d\n", threadnum);
+ return (void *)-1;
+ }
+
+ code = gsapi_init_with_args(minst, gsargc, gsargv);
+ code1 = gsapi_exit(minst);
+ if ((code == 0) || (code == e_Quit))
+ code = code1;
+
+ gsapi_delete_instance(minst);
+
+ if ((code == 0) || (code == e_Quit))
+ return (void *)0;
+
+ return (void *)1;
+}
+
+int main(int argc, char *argv[])
+{
+ int i;
+ pthread_t thread[NUM_THREADS];
+
+ my_argc = argc;
+ my_argv = argv;
+
+ for (i=0; i < argc; i++)
+ if (!strcmp(argv[i], "-o"))
+ break;
+
+ if (i >= argc-1)
+ {
+ fprintf(stderr, "Expected a -o argument to rewrite!\n");
+ exit(EXIT_FAILURE);
+ }
+ my_argv_file = i+1;
+
+ for (i=0; i < NUM_THREADS; i++)
+ {
+ if (pthread_create(&thread[i], NULL, gs_main, (void *)i) < 0)
+ {
+ fprintf(stderr, "Thread %d creation failed\n", i);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ for (i=0; i < NUM_THREADS; i++)
+ {
+ if (pthread_join(thread[i], NULL) < 0)
+ {
+ fprintf(stderr, "Thread %d join failed\n", i);
+ exit(EXIT_FAILURE);
+ }
+ }
+ return EXIT_SUCCESS;
+}
diff --git a/gs/psi/iapi.c b/gs/psi/iapi.c
index 540d148b5..2846aab45 100644
--- a/gs/psi/iapi.c
+++ b/gs/psi/iapi.c
@@ -33,8 +33,8 @@
/* number of threads to allow per process
* currently more than 1 is guarenteed to fail
*/
-static int gsapi_instance_counter = 0;
-static const int gsapi_instance_max = 1;
+//static int gsapi_instance_counter = 0;
+//static const int gsapi_instance_max = 1;
/* Return revision numbers and strings of Ghostscript. */
/* Used for determining if wrong GSDLL loaded. */
@@ -66,9 +66,9 @@ gsapi_new_instance(void **pinstance, void *caller_handle)
return e_Fatal;
/* limited to 1 instance, till it works :) */
- if ( gsapi_instance_counter >= gsapi_instance_max )
- return e_Fatal;
- ++gsapi_instance_counter;
+ //if ( gsapi_instance_counter >= gsapi_instance_max )
+ // return e_Fatal;
+ //++gsapi_instance_counter;
if (*pinstance == NULL)
/* first instance in this process */
@@ -120,7 +120,7 @@ gsapi_delete_instance(void *lib)
/* Release the memory (frees up everything) */
gs_malloc_release(minst->heap);
- --gsapi_instance_counter;
+ //--gsapi_instance_counter;
}
}
diff --git a/gs/psi/int.mak b/gs/psi/int.mak
index 16fc02f15..5d9bed461 100644
--- a/gs/psi/int.mak
+++ b/gs/psi/int.mak
@@ -1995,6 +1995,11 @@ $(PSOBJ)gs.$(OBJ) : $(PSSRC)gs.c $(GH)\
$(locale__h)
$(PSCC) $(PSO_)gs.$(OBJ) $(C_) $(PSSRC)gs.c
+$(PSOBJ)apitest.$(OBJ) : $(PSSRC)apitest.c $(GH)\
+ $(ierrors_h) $(iapi_h) $(imain_h) $(imainarg_h) $(iminst_h) $(gsmalloc_h)\
+ $(locale__h)
+ $(PSCC) $(PSO_)apitest.$(OBJ) $(C_) $(PSSRC)apitest.c
+
$(PSOBJ)iapi.$(OBJ) : $(PSSRC)iapi.c $(AK)\
$(string__h) $(ierrors_h) $(gscdefs_h) $(gstypes_h) $(iapi_h)\
$(iref_h) $(imain_h) $(imainarg_h) $(iminst_h) $(gslibctx_h)