mesa/main: use call_once instead of open-coding
[mesa.git] / src / mesa / main / context.c
index db34c941329ed797f02a277bc24387ae98b141df..be2e7df5824e0f75f31ba441083871e66de57445 100644 (file)
@@ -77,7 +77,7 @@
 
 
 #include "glheader.h"
-#include "imports.h"
+
 #include "accum.h"
 #include "api_exec.h"
 #include "api_loopback.h"
 #include "compiler/glsl/builtin_functions.h"
 #include "compiler/glsl/glsl_parser_extras.h"
 #include <stdbool.h>
+#include "util/u_memory.h"
 
 
 #ifndef MESA_VERBOSE
@@ -339,14 +340,6 @@ _mesa_destroy_visual( struct gl_config *vis )
 /*@{*/
 
 
-/**
- * One-time initialization mutex lock.
- *
- * \sa Used by one_time_init().
- */
-mtx_t OneTimeLock = _MTX_INITIALIZER_NP;
-
-
 /**
  * Calls all the various one-time-fini functions in Mesa
  */
@@ -359,64 +352,68 @@ one_time_fini(void)
 }
 
 /**
- * Calls all the various one-time-init functions in Mesa.
- *
- * While holding a global mutex lock, calls several initialization functions,
- * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
- * defined.
- *
- * \sa _math_init().
+ * Calls all the various one-time-init functions in Mesa
  */
+
 static void
-one_time_init( struct gl_context *ctx )
+one_time_init(void)
 {
-   static GLbitfield api_init_mask = 0x0;
-
-   mtx_lock(&OneTimeLock);
-
-   /* truly one-time init */
-   if (!api_init_mask) {
-      GLuint i;
+   GLuint i;
 
-      STATIC_ASSERT(sizeof(GLbyte) == 1);
-      STATIC_ASSERT(sizeof(GLubyte) == 1);
-      STATIC_ASSERT(sizeof(GLshort) == 2);
-      STATIC_ASSERT(sizeof(GLushort) == 2);
-      STATIC_ASSERT(sizeof(GLint) == 4);
-      STATIC_ASSERT(sizeof(GLuint) == 4);
+   STATIC_ASSERT(sizeof(GLbyte) == 1);
+   STATIC_ASSERT(sizeof(GLubyte) == 1);
+   STATIC_ASSERT(sizeof(GLshort) == 2);
+   STATIC_ASSERT(sizeof(GLushort) == 2);
+   STATIC_ASSERT(sizeof(GLint) == 4);
+   STATIC_ASSERT(sizeof(GLuint) == 4);
 
-      _mesa_locale_init();
+   _mesa_locale_init();
 
-      _mesa_one_time_init_extension_overrides(ctx);
+   _mesa_one_time_init_extension_overrides();
 
-      _mesa_get_cpu_features();
+   _mesa_get_cpu_features();
 
-      for (i = 0; i < 256; i++) {
-         _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
-      }
+   for (i = 0; i < 256; i++) {
+      _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
+   }
 
-      atexit(one_time_fini);
+   atexit(one_time_fini);
 
 #if defined(DEBUG)
-      if (MESA_VERBOSE != 0) {
-         _mesa_debug(ctx, "Mesa " PACKAGE_VERSION " DEBUG build" MESA_GIT_SHA1 "\n");
-      }
+   if (MESA_VERBOSE != 0) {
+      _mesa_debug(NULL, "Mesa " PACKAGE_VERSION " DEBUG build" MESA_GIT_SHA1 "\n");
+   }
 #endif
 
-      /* Take a glsl type reference for the duration of libGL's life to avoid
-       * unecessary creation/destruction of glsl types.
-       */
-      glsl_type_singleton_init_or_ref();
-   }
+   /* Take a glsl type reference for the duration of libGL's life to avoid
+    * unecessary creation/destruction of glsl types.
+    */
+   glsl_type_singleton_init_or_ref();
 
-   /* per-API one-time init */
-   if (!(api_init_mask & (1 << ctx->API))) {
-      _mesa_init_remap_table();
-   }
+   _mesa_init_remap_table();
+}
+
+/**
+ * One-time initialization flag
+ *
+ * \sa Used by _mesa_initialize().
+ */
+static once_flag init_once = ONCE_FLAG_INIT;
 
-   api_init_mask |= 1 << ctx->API;
 
-   mtx_unlock(&OneTimeLock);
+/**
+ * Calls all the various one-time-init functions in Mesa.
+ *
+ * While holding a global mutex lock, calls several initialization functions,
+ * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
+ * defined.
+ *
+ * \sa _math_init().
+ */
+void
+_mesa_initialize(void)
+{
+   call_once(&init_once, one_time_init);
 }
 
 
@@ -754,6 +751,8 @@ _mesa_init_constants(struct gl_constants *consts, gl_api api)
    consts->ConservativeRasterDilateRange[0] = 0.0;
    consts->ConservativeRasterDilateRange[1] = 0.0;
    consts->ConservativeRasterDilateGranularity = 0.0;
+
+   consts->glBeginEndBufferSize = 512 * 1024;
 }
 
 
@@ -1204,7 +1203,7 @@ _mesa_initialize_context(struct gl_context *ctx,
    _mesa_override_gl_version(ctx);
 
    /* misc one-time initializations */
-   one_time_init(ctx);
+   _mesa_initialize();
 
    /* Plug in driver functions and context pointer here.
     * This is important because when we call alloc_shared_state() below
@@ -1763,6 +1762,7 @@ _mesa_make_current( struct gl_context *newCtx,
              * changed since the last time this FBO was bound).
              */
             _mesa_update_draw_buffers(newCtx);
+            _mesa_update_allow_draw_out_of_order(newCtx);
          }
          if (!newCtx->ReadBuffer || _mesa_is_winsys_fbo(newCtx->ReadBuffer)) {
             _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
@@ -1874,7 +1874,6 @@ void
 _mesa_flush(struct gl_context *ctx)
 {
    FLUSH_VERTICES( ctx, 0 );
-   FLUSH_CURRENT( ctx, 0 );
    if (ctx->Driver.Flush) {
       ctx->Driver.Flush(ctx);
    }
@@ -1895,7 +1894,6 @@ _mesa_Finish(void)
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    FLUSH_VERTICES(ctx, 0);
-   FLUSH_CURRENT(ctx, 0);
 
    if (ctx->Driver.Finish) {
       ctx->Driver.Finish(ctx);