Commit ad968a63 authored by David Schleef's avatar David Schleef

once: Add orc once mutex and use it in orcc

parent 6c668cd1
......@@ -24,6 +24,7 @@ liborc_@ORC_MAJORMINOR@_la_SOURCES = \
orcprogram.h \
orcopcodes.c \
orcparse.c \
orconce.c \
orcrules-altivec.c \
orcrules-mmx.c \
orcrules-sse.c \
......@@ -56,6 +57,7 @@ pkginclude_HEADERS = \
orcutils.h \
orcparse.h \
opcodes.h \
orconce.h \
orcsse.h \
orcmmx.h \
orcx86.h \
......
......@@ -7,6 +7,7 @@
#include <orc/orcarm.h>
#include <orc/orcdebug.h>
#include <orc/orcmmx.h>
#include <orc/orconce.h>
#include <orc/orcparse.h>
#include <orc/orcprogram.h>
#include <orc/orcsse.h>
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <orc/orconce.h>
#include <pthread.h>
pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
void
orc_once_mutex_lock (void)
{
pthread_mutex_lock (&once_mutex);
}
void
orc_mutex_unlock (OrcMutex *mutex)
{
pthread_mutex_unlock (&once_mutex);
}
#ifndef _ORC_ONCE_H_
#define _ORC_ONCE_H_
typedef struct _OrcMutex OrcMutex;
typedef struct _OrcOnce OrcOnce;
struct _OrcOnce {
int inited;
void *value;
};
void orc_once_mutex_lock (void);
void orc_once_mutex_unlock (void);
#endif
......@@ -13,12 +13,6 @@ void output_code_test (OrcProgram *p, FILE *output);
void output_code_backup (OrcProgram *p, FILE *output);
static void print_defines (FILE *output);
typedef enum {
MUTEX_STYLE_SCHRO,
MUTEX_STYLE_GLIB
} MutexStyle;
MutexStyle mutex_style = MUTEX_STYLE_SCHRO;
int
main (int argc, char *argv[])
{
......@@ -51,29 +45,7 @@ main (int argc, char *argv[])
fprintf(output, "#include <orc/orc.h>\n");
fprintf(output, "#include <stdio.h>\n");
fprintf(output, "#include <stdlib.h>\n");
switch (mutex_style) {
case MUTEX_STYLE_SCHRO:
fprintf(output, "#include <schroedinger/schro.h>\n");
fprintf(output, "#define MUTEX_LOCK() schro_mutex_lock (orc_mutex)\n");
fprintf(output, "#define MUTEX_UNLOCK() schro_mutex_unlock (orc_mutex)\n");
fprintf(output, "SchroMutex *orc_mutex;\n");
break;
case MUTEX_STYLE_GLIB:
fprintf(output, "#include <glib/gthread.h>\n");
fprintf(output, "#define MUTEX_LOCK() g_static_mutex_lock (&orc_mutex)\n");
fprintf(output, "#define MUTEX_UNLOCK() g_static_mutex_unlock (&orc_mutex)\n");
fprintf(output, "static GStaticMutex orc_mutex = G_STATIC_MUTEX_INIT;\n");
break;
default:
break;
}
fprintf(output, "\n");
fprintf(output, "#ifndef MUTEX_LOCK\n");
fprintf(output, "#define MUTEX_LOCK do { } while (0)\n");
fprintf(output, "#endif\n");
fprintf(output, "#ifndef MUTEX_UNLOCK\n");
fprintf(output, "#define MUTEX_UNLOCK do { } while (0)\n");
fprintf(output, "#endif\n");
fprintf(output, "\n");
fprintf(output, "\n");
print_defines (output);
fprintf(output, "\n");
......@@ -374,7 +346,7 @@ output_code (OrcProgram *p, FILE *output)
fprintf(output, " OrcExecutor _ex, *ex = &_ex;\n");
fprintf(output, "\n");
fprintf(output, " if (!p_inited) {\n");
fprintf(output, " MUTEX_LOCK ();\n");
fprintf(output, " orc_once_mutex_lock ();\n");
fprintf(output, " if (!p_inited) {\n");
fprintf(output, " OrcCompileResult result;\n");
fprintf(output, "\n");
......@@ -454,7 +426,7 @@ output_code (OrcProgram *p, FILE *output)
#endif
fprintf(output, " }\n");
fprintf(output, " p_inited = TRUE;\n");
fprintf(output, " MUTEX_UNLOCK ();\n");
fprintf(output, " orc_once_mutex_unlock ();\n");
fprintf(output, " }\n");
fprintf(output, "\n");
//fprintf(output, " orc_executor_set_program (ex, p);\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment