Changeset: 9d7d4cf85d66 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9d7d4cf85d66
Modified Files:
        gdk/gdk_system.c
        gdk/gdk_system.h
        tools/monetdbe/monetdbe.c
Branch: default
Log Message:

Merged with Jul2021


diffs (truncated from 421 to 300 lines):

diff --git a/ctest/tools/monetdbe/example_append_raw.c 
b/ctest/tools/monetdbe/example_append_raw.c
--- a/ctest/tools/monetdbe/example_append_raw.c
+++ b/ctest/tools/monetdbe/example_append_raw.c
@@ -74,6 +74,13 @@ main(void)
        if ((err = monetdbe_append(mdbe, "sys", "test", (monetdbe_column**) 
&dcol, 6)) != NULL)
                error(err)
 
+       // str with wrong utf8
+       char* dstr2[2] = { "\xc3\x28", "\xe2\x28\xa1" };
+       monetdbe_column col12 = { .type = monetdbe_str, .data = &dstr2, .count 
= 2 };
+       monetdbe_column* dcol2[6] = { &col0, &col12, &col2, &col3, &col4, &col5 
};
+       if ((err = monetdbe_append(mdbe, "sys", "test", (monetdbe_column**) 
&dcol2, 6)) == NULL)
+               error("Invalid UTF-8 string expected")
+
        if ((err = monetdbe_query(mdbe, "SELECT * FROM test; ", &result, NULL)) 
!= NULL)
                error(err)
        fprintf(stdout, "Query result after append with %zu cols and %"PRId64" 
rows\n", result->ncols, result->nrows);
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1615,7 +1615,7 @@ bm_subcommit(logger *lg)
                sizes[i] = BATcount(lg->seqs_id);
                n[i++] = lg->seqs_val->batCacheid;
        }
-       if (lg->seqs_id && BATcount(lg->dseqs) > (BATcount(lg->seqs_id)/2)) {
+       if (!cleanup && lg->seqs_id && BATcount(lg->dseqs) > 
(BATcount(lg->seqs_id)/2)) {
                BAT *tids, *ids, *vals;
 
                tids = bm_tids(lg->seqs_id, lg->dseqs);
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -73,6 +73,7 @@ sortlocklist(MT_Lock *l)
                r = r->next;
        }
        ll->next = NULL;        /* break list into two */
+       r->prev = NULL;
        /* recursively sort both sublists */
        l = sortlocklist(l);
        r = sortlocklist(r);
@@ -92,6 +93,7 @@ sortlocklist(MT_Lock *l)
                                t = ll = l;
                        } else {
                                ll->next = l;
+                               l->prev = ll;
                                ll = ll->next;
                        }
                        l = l->next;
@@ -102,13 +104,20 @@ sortlocklist(MT_Lock *l)
                                t = ll = r;
                        } else {
                                ll->next = r;
+                               r->prev = ll;
                                ll = ll->next;
                        }
                        r = r->next;
                }
        }
        /* append rest of remaining list */
-       ll->next = l ? l : r;
+       if (l) {
+               ll->next = l;
+               l->prev = ll;
+       } else {
+               ll->next = r;
+               r->prev = ll;
+       }
        return t;
 }
 
@@ -143,7 +152,9 @@ GDKlockstatistics(int what)
                return;
        }
        GDKlocklist = sortlocklist(GDKlocklist);
-       fprintf(stderr, "lock 
name\tcount\tcontention\tsleep\tlocked\t(un)locker\tthread\n");
+       fprintf(stderr, "%-18s\t%s\t%s\t%s\t%s\t%s\t%s\n",
+               "lock name", "count", "content", "sleep",
+               "locked", "locker", "thread");
        for (l = GDKlocklist; l; l = l->next) {
                n++;
                if (what == 0 ||
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -182,10 +182,6 @@ gdk_export void MT_thread_set_qry_ctx(Qr
 /* define this to keep lock statistics (can be expensive) */
 /* #define LOCK_STATS 1 */
 
-/* define this if you want to use pthread (or Windows) locks instead
- * of atomic instructions for locking (latching) */
-#define USE_NATIVE_LOCKS 1
-
 #ifdef LOCK_STATS
 #include "gdk_tracer.h"
 
@@ -224,6 +220,9 @@ gdk_export void MT_thread_set_qry_ctx(Qr
                        while (ATOMIC_TAS(&GDKlocklistlock) != 0)       \
                                ;                                       \
                        (l)->next = GDKlocklist;                        \
+                       (l)->prev = NULL;                               \
+                       if (GDKlocklist)                                \
+                               GDKlocklist->prev = (l);                \
                        GDKlocklist = (l);                              \
                        ATOMIC_CLEAR(&GDKlocklistlock);                 \
                }                                                       \
@@ -242,16 +241,17 @@ gdk_export void MT_thread_set_qry_ctx(Qr
                /* SQL storage allocator, and hence we have no control */ \
                /* over when the lock is destroyed and the memory freed */ \
                if (strncmp((l)->name, "sa_", 3) != 0) {                \
-                       MT_Lock * volatile _p;                          \
                        while (ATOMIC_TAS(&GDKlocklistlock) != 0)       \
                                ;                                       \
-                       for (_p = GDKlocklist; _p; _p = _p->next)       \
-                               assert(_p != (l));                      \
+                       if (GDKlocklist)                                \
+                               GDKlocklist->prev = (l);                \
                        (l)->next = GDKlocklist;                        \
+                       (l)->prev = NULL;                               \
                        GDKlocklist = (l);                              \
                        ATOMIC_CLEAR(&GDKlocklistlock);                 \
                } else {                                                \
                        (l)->next = NULL;                               \
+                       (l)->prev = NULL;                               \
                }                                                       \
        } while (0)
 
@@ -262,14 +262,14 @@ gdk_export void MT_thread_set_qry_ctx(Qr
                /* SQL storage allocator, and hence we have no control */ \
                /* over when the lock is destroyed and the memory freed */ \
                if (strncmp((l)->name, "sa_", 3) != 0) {                \
-                       MT_Lock * volatile *_p;                         \
                        while (ATOMIC_TAS(&GDKlocklistlock) != 0)       \
                                ;                                       \
-                       for (_p = &GDKlocklist; *_p; _p = &(*_p)->next) \
-                               if ((l) == *_p) {                       \
-                                       *_p = (l)->next;                \
-                                       break;                          \
-                               }                                       \
+                       if ((l)->next)                                  \
+                               (l)->next->prev = (l)->prev;            \
+                       if ((l)->prev)                                  \
+                               (l)->prev->next = (l)->next;            \
+                       else if (GDKlocklist == (l))                    \
+                               GDKlocklist = (l)->next;                \
                        ATOMIC_CLEAR(&GDKlocklistlock);                 \
                        ATOMIC_DESTROY(&(l)->contention);               \
                        ATOMIC_DESTROY(&(l)->sleep);                    \
@@ -289,8 +289,6 @@ gdk_export void MT_thread_set_qry_ctx(Qr
 
 #endif
 
-#ifdef USE_NATIVE_LOCKS
-
 #if !defined(HAVE_PTHREAD_H) && defined(WIN32)
 typedef struct MT_Lock {
        CRITICAL_SECTION lock;
@@ -299,7 +297,8 @@ typedef struct MT_Lock {
        size_t count;
        ATOMIC_TYPE contention;
        ATOMIC_TYPE sleep;
-       struct MT_Lock * volatile next;
+       struct MT_Lock *volatile next;
+       struct MT_Lock *volatile prev;
        const char *locker;
        const char *thread;
 #endif
@@ -397,7 +396,8 @@ typedef struct MT_Lock {
        size_t count;
        ATOMIC_TYPE contention;
        ATOMIC_TYPE sleep;
-       struct MT_Lock * volatile next;
+       struct MT_Lock *volatile next;
+       struct MT_Lock *volatile prev;
        const char *locker;
        const char *thread;
 #endif
@@ -477,133 +477,6 @@ typedef struct MT_RWLock {
 
 #endif
 
-#else
-
-/* if LOCK_STATS is set, we maintain a bunch of counters and maintain
- * a linked list of active locks */
-typedef struct MT_Lock {
-       ATOMIC_FLAG lock;
-       char name[MT_NAME_LEN];
-#ifdef LOCK_STATS
-       size_t count;
-       ATOMIC_TYPE contention;
-       ATOMIC_TYPE sleep;
-       struct MT_Lock * volatile next;
-       const char *locker;
-       const char *thread;
-#endif
-} MT_Lock;
-
-#ifdef LOCK_STATS
-#define MT_LOCK_INITIALIZER(n) { .lock = ATOMIC_FLAG_INIT, .next = (struct 
MT_Lock *) -1, .name = #n, }
-#else
-#define MT_LOCK_INITIALIZER(n) { .lock = ATOMIC_FLAG_INIT, .name = #n, }
-#endif
-
-#define MT_lock_try(l) (ATOMIC_TAS(&(l)->lock) == 0)
-
-#define MT_lock_set(l)                                         \
-       do {                                                    \
-               _DBG_LOCK_COUNT_0(l);                           \
-               if (!MT_lock_try(l)) {                          \
-                       /* we didn't get the lock */            \
-                       unsigned _spincnt = 0;                  \
-                       _DBG_LOCK_CONTENTION(l);                \
-                       MT_thread_setlockwait(l);               \
-                       do {                                    \
-                               if ((++_spincnt & 2047) == 0) { \
-                                       _DBG_LOCK_SLEEP(l);     \
-                                       MT_sleep_ms(1);         \
-                               }                               \
-                       } while (!MT_lock_try(l));              \
-                       MT_thread_setlockwait(NULL);            \
-               }                                               \
-               _DBG_LOCK_LOCKER(l);                            \
-               _DBG_LOCK_COUNT_2(l);                           \
-       } while (0)
-
-#define MT_lock_init(l, n)                             \
-       do {                                            \
-               size_t nlen;                            \
-               ATOMIC_CLEAR(&(l)->lock);               \
-               nlen = strlen(n);                       \
-               if (nlen >= sizeof((l)->name))          \
-                       nlen = sizeof((l)->name) - 1;   \
-               memcpy((l)->name, (n), nlen + 1);       \
-               (l)->name[sizeof((l)->name) - 1] = 0;   \
-               _DBG_LOCK_INIT(l);                      \
-       } while (0)
-
-#define MT_lock_unset(l)                                       \
-               do {                                            \
-                       /* lock should be locked */             \
-                       assert(ATOMIC_TAS(&(l)->lock) != 0);    \
-                       _DBG_LOCK_UNLOCKER(l);                  \
-                       ATOMIC_CLEAR(&(l)->lock);               \
-               } while (0)
-
-#define MT_lock_destroy(l)     _DBG_LOCK_DESTROY(l)
-
-typedef struct MT_RWLock {
-       MT_Lock lock;
-       ATOMIC_TYPE readers;
-} MT_RWLock;
-
-#define MT_RWLOCK_INITIALIZER(n)                                       \
-       { .lock = MT_LOCK_INITIALIZER(n), .readers = ATOMIC_VAR_INIT(0), }
-
-#define MT_rwlock_init(l, n)                   \
-       do {                                    \
-               MT_lock_init(&(l)->lock, n);    \
-               ATOMIC_INIT(&(l)->readers, 0);  \
-        } while (0)
-
-#define MT_rwlock_destroy(l)                   \
-       do {                                    \
-               MT_lock_destroy(&(l)->lock);    \
-               ATOMIC_DESTROY(&(l)->readers);  \
-       } while (0)
-
-#define MT_rwlock_rdlock(l)                            \
-       do {                                            \
-               MT_lock_set(&(l)->lock);                \
-               (void) ATOMIC_INC(&(l)->readers);       \
-               MT_lock_unset(&(l)->lock);              \
-        } while (0)
-static inline bool
-MT_rwlock_rdtry(MT_RWLock *l)
-{
-       if (!MT_lock_try(l))
-               return false;
-       (void) ATOMIC_INC(&(l)->readers);
-       MT_lock_unset(&(l)->lock);
-       return true;
-}
-
-#define MT_rwlock_rdunlock(l)  ((void) ATOMIC_DEC(&(l)->readers))
-
-#define MT_rwlock_wrlock(l)                            \
-       do {                                            \
-               MT_lock_set(&(l)->lock);                \
-               while (ATOMIC_GET(&(l)->readers) > 0)   \
-                       MT_sleep_ms(1);                 \
-        } while (0)
-static inline bool
-MT_rwlock_wrtry(MT_RWLock *l)
-{
-       if (!MT_lock_try(l))
-               return false;
-       if (ATOMIC_GET(&l->readers) > 0) {
-               MT_lock_unset(l);
-               return false;
-       }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to