Changeset: 00238cf87502 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=00238cf87502
Modified Files:
        clients/mapilib/mapi.c
        common/stream/Makefile.ag
        common/stream/stream.c
Branch: default
Log Message:

Use atomic instructions for static variables.


diffs (131 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -688,6 +688,7 @@
 #include "stream_socket.h"
 #include "mapi.h"
 #include "mcrypt.h"
+#include "matomic.h"
 
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
@@ -952,7 +953,7 @@ static int unquote(const char *msg, char
 static int mapi_slice_row(struct MapiResultSet *result, int cr);
 static void mapi_store_bind(struct MapiResultSet *result, int cr);
 
-static bool mapi_initialized = false;
+static ATOMIC_FLAG mapi_initialized = ATOMIC_FLAG_INIT;
 
 #define check_stream(mid,s,msg,f,e)                                    \
        do {                                                            \
@@ -1036,7 +1037,7 @@ mapi_error_str(Mapi mid)
 }
 
 #ifdef _MSC_VER
-static struct {
+static const struct {
        int e;
        const char *m;
 } wsaerrlist[] = {
@@ -1796,7 +1797,7 @@ static Mapi
 mapi_new(void)
 {
        Mapi mid;
-       static uint32_t index = 0;
+       static ATOMIC_TYPE index = ATOMIC_VAR_INIT(0);
 
        mid = malloc(sizeof(*mid));
        if (mid == NULL)
@@ -1804,7 +1805,7 @@ mapi_new(void)
 
        /* then fill in some details */
        *mid = (struct MapiStruct) {
-               .index = index++,       /* for distinctions in log records */
+               .index = (uint32_t) ATOMIC_ADD(&index, 1),      /* for 
distinctions in log records */
                .auto_commit = true,
                .error = MOK,
                .languageId = LANG_SQL,
@@ -1912,8 +1913,7 @@ mapi_mapiuri(const char *url, const char
        char *dbname;
        char *query;
 
-       if (!mapi_initialized) {
-               mapi_initialized = true;
+       if (!ATOMIC_TAS(&mapi_initialized)) {
                if (mnstr_init() < 0)
                        return NULL;
        }
@@ -2028,8 +2028,7 @@ mapi_mapi(const char *host, int port, co
 {
        Mapi mid;
 
-       if (!mapi_initialized) {
-               mapi_initialized = true;
+       if (!ATOMIC_TAS(&mapi_initialized)) {
                if (mnstr_init() < 0)
                        return NULL;
        }
diff --git a/common/stream/Makefile.ag b/common/stream/Makefile.ag
--- a/common/stream/Makefile.ag
+++ b/common/stream/Makefile.ag
@@ -8,7 +8,8 @@
 
 MTSAFE
 
-INCLUDES = $(zlib_CFLAGS) \
+INCLUDES = ../utils \
+                  $(zlib_CFLAGS) \
                   $(bzip2_CFLAGS) \
                   $(snappy_CFLAGS) \
                   $(lz4_CFLAGS) \
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -52,6 +52,7 @@
 #include "monetdb_config.h"
 #include "stream.h"
 #include "stream_socket.h"
+#include "matomic.h"
 
 #include <string.h>
 #include <stddef.h>
@@ -211,9 +212,9 @@ struct stream {
 int
 mnstr_init(void)
 {
-       static bool inited = false;
-
-       if (inited)
+       static ATOMIC_FLAG inited = ATOMIC_FLAG_INIT;
+
+       if (ATOMIC_TAS(&inited))
                return 0;
 
 #ifdef NATIVE_WIN32
@@ -224,7 +225,6 @@ mnstr_init(void)
                        return -1;
        }
 #endif
-       inited = true;
        return 0;
 }
 
@@ -2149,10 +2149,6 @@ open_wastream(const char *filename)
 #ifdef HAVE_CURL
 #include <curl/curl.h>
 
-#ifdef USE_CURL_MULTI
-static CURLM *multi_handle;
-#endif
-
 struct curl_data {
        CURL *handle;
        char *buffer;           /* buffer to store incoming data */
@@ -2166,6 +2162,7 @@ struct curl_data {
 #endif
 };
 #ifdef USE_CURL_MULTI
+static CURLM *multi_handle;
 static struct curl_data *curl_handles;
 #endif
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to