Changeset: c466b8132f69 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c466b8132f69
Modified Files:
        gdk/gdk_system.c
        gdk/gdk_utils.c
        monetdb5/mal/mal_dataflow.c
        monetdb5/mal/mal_profiler.c
        monetdb5/mal/mal_recycle.c
        monetdb5/mal/mal_session.c
        sql/backends/monet5/rel_bin.c
        sql/common/sql_changeset.c
        sql/common/sql_list.c
        sql/common/sql_types.c
        sql/include/sql_list.h
        sql/server/rel_exp.c
        sql/server/rel_optimizer.c
        sql/server/rel_planner.c
        sql/server/rel_select.c
        sql/storage/sql_catalog.c
        sql/storage/store.c
Branch: default
Log Message:

Merge with Jan2014 branch.


diffs (truncated from 834 to 300 lines):

diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -503,7 +503,9 @@ thread_starter(void *arg)
        struct posthread *p = (struct posthread *) arg;
 
        (*p->func)(p->arg);
+       pthread_mutex_lock(&posthread_lock);
        p->exited = 1;
+       pthread_mutex_unlock(&posthread_lock);
 }
 
 static void
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -1132,7 +1132,15 @@ static int GDKnrofthreads;
 int
 GDKexiting(void)
 {
-       return (int) GDKstopped;
+       int stopped;
+#ifdef ATOMIC_LOCK
+       pthread_mutex_lock(&GDKstoppedLock);
+#endif
+       stopped = GDKstopped != 0;
+#ifdef ATOMIC_LOCK
+       pthread_mutex_unlock(&GDKstoppedLock);
+#endif
+       return stopped;
 }
 
 /* coverity[+kill] */
diff --git a/monetdb5/mal/mal_dataflow.c b/monetdb5/mal/mal_dataflow.c
--- a/monetdb5/mal/mal_dataflow.c
+++ b/monetdb5/mal/mal_dataflow.c
@@ -360,7 +360,9 @@ DFLOWworker(void *T)
                        MALadmission(-fe->argclaim, -fe->hotclaim);
 #endif
 
+                       MT_lock_set(&flow->flowlock, "DFLOWworker");
                        fe->state = DFLOWwrapup;
+                       MT_lock_unset(&flow->flowlock, "DFLOWworker");
                        if (error) {
                                MT_lock_set(&flow->flowlock, "DFLOWworker");
                                /* only collect one error (from one thread, 
needed for stable testing) */
@@ -405,7 +407,11 @@ DFLOWworker(void *T)
 
                q_enqueue(flow->done, fe);
                if ( fnxt == 0) {
-                       if (todo->last == 0)
+                       int last;
+                       MT_lock_set(&todo->l, "DFLOWworker");
+                       last = todo->last;
+                       MT_lock_unset(&todo->l, "DFLOWworker");
+                       if (last == 0)
                                profilerHeartbeatEvent("wait", 0);
                }
        }
diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -1295,7 +1295,10 @@ getDiskSpace(void)
 }
 
 /* the heartbeat process produces a ping event once every X milliseconds */
-static int hbdelay = 0;
+#ifdef ATOMIC_LOCK
+static MT_Lock hbLock MT_LOCK_INITIALIZER("hbLock");
+#endif
+static volatile ATOMIC_TYPE hbdelay = 0;
 
 /* the processor statistics are gathered in Linux settings from the proc files.
  * Given the parsing involved, it should be used sparingly */
@@ -1393,7 +1396,7 @@ void profilerHeartbeatEvent(str msg, lng
        struct tms newTms;
        struct tms prevtimer;
 
-       if( hbdelay ==0 || eventstream  == NULL ) 
+       if (ATOMIC_GET(hbdelay, hbLock, "profilerHeatbeatEvent") == 0 || 
eventstream  == NULL)
                return;
        times(&prevtimer);
 #endif
@@ -1501,46 +1504,51 @@ void profilerHeartbeatEvent(str msg, lng
 }
 
 static MT_Id hbthread;
-static int volatile hbrunning;
+static volatile ATOMIC_TYPE hbrunning;
 
 static void profilerHeartbeat(void *dummy)
 {
        int t;
 
        (void) dummy;
-       while (hbrunning) {
+       while (ATOMIC_GET(hbrunning, hbLock, "profilerHeartbeat")) {
                /* wait until you need this info */
-               while( hbdelay ==0 || eventstream  == NULL ) {
+               while (ATOMIC_GET(hbdelay, hbLock, "profilerHeatbeatEvent") == 
0 || eventstream  == NULL) {
                        for (t = 1000; t > 0; t -= 50) {
                                MT_sleep_ms(50);
-                               if (!hbrunning)
+                               if (!ATOMIC_GET(hbrunning, hbLock, 
"profilerHeartbeat"))
                                        return;
                        }
                }
-               for (t = hbdelay; t > 0; t -= 50) {
+               for (t = ATOMIC_GET(hbdelay, hbLock, "profilerHeatbeatEvent"); 
t > 0; t -= 50) {
                        MT_sleep_ms(t > 50 ? 50 : t);
-                       if (!hbrunning)
+                       if (!ATOMIC_GET(hbrunning, hbLock, "profilerHeartbeat"))
                                return;
                }
                profilerHeartbeatEvent("ping", 0);
        }
-       hbdelay = 0;
+       ATOMIC_SET(hbdelay, 0, hbLock, "profilerHeatbeat");
 }
 
-void startHeartbeat(int delay){
+void startHeartbeat(int delay)
+{
        if ( delay < 0 )
                return;
-       hbdelay = delay;
+       ATOMIC_SET(hbdelay, (ATOMIC_TYPE) delay, hbLock, "startHeatbeat");
 }
 
-void stopHeartbeat(void){
-       hbrunning = 0;
+void stopHeartbeat(void)
+{
+       ATOMIC_SET(hbrunning, 0, hbLock, "stopHeartbeat");
        if (hbthread)
                MT_join_thread(hbthread);
 }
 
 void initHeartbeat(void)
 {
+#ifdef NEED_MT_LOCK_INIT
+       ATOMIC_INIT(hbLock, "hbLock");
+#endif
        hbrunning = 1;
        if (MT_create_thread(&hbthread, profilerHeartbeat, NULL, 
MT_THR_JOINABLE) < 0) {
                /* it didn't happen */
diff --git a/monetdb5/mal/mal_recycle.c b/monetdb5/mal/mal_recycle.c
--- a/monetdb5/mal/mal_recycle.c
+++ b/monetdb5/mal/mal_recycle.c
@@ -53,7 +53,10 @@ int recycleCacheLimit=0; /* No limit by 
 static lng recyclerMemoryUsed = 0;
 static lng recyclerSavings = 0;
 static lng recycled=0;
-static lng statements =0;
+#ifdef ATOMIC_LOCK
+static MT_Lock statementsLock MT_LOCK_INITIALIZER("statementsLock");
+#endif
+static volatile ATOMIC_TYPE statements = 0;
 static lng recycleSearchTime =0;       /* cache search time in ms*/
 static lng recycleSearchCalls =0;      
 
@@ -116,6 +119,7 @@ static void RECYCLEspace(void)
 void RECYCLEinit(void){
 #ifdef NEED_MT_LOCK_INIT
        MT_lock_init(&recycleLock,"recycleLock");
+       ATOMIC_INIT(statementsLock, "statementsLock");
 #endif
        sqlRef = putName("sql",3);
        bindRef = putName("bind",4);
@@ -830,7 +834,7 @@ RECYCLEentry(Client cntxt, MalBlkPtr mb,
 {
        int i=0;
 
-       statements++;
+       ATOMIC_INC(statements, statementsLock, "RECYCLEentry");
        if ( !RECYCLEinterest(p) )  /* don't scan RecyclerPool for 
non-monitored instructions */
                return 0;
        if ( recycleBlk == NULL ){
@@ -1095,7 +1099,7 @@ RECYCLEdumpInternal(stream *s)
 
     mnstr_printf(s,"#RECYCLER CATALOG cached %d instructions, ", 
recycleBlk->stop);
     mnstr_printf(s,"MAL recycled = "LLFMT" total MAL executed = "LLFMT" 
memory= "LLFMT" total searchtime=%5.2f(usec) savings="LLFMT"\n",
-         recycled- recycleBlk->stop, statements, recyclerMemoryUsed, 
((double)recycleSearchTime)/recycleSearchCalls,  recyclerSavings);
+                                recycled- recycleBlk->stop, (lng) 
ATOMIC_GET(statements, statementsLock, "RECYCLEdumpInternal"), 
recyclerMemoryUsed, ((double)recycleSearchTime)/recycleSearchCalls,  
recyclerSavings);
 
 #ifdef _DEBUG_CACHE_
     /* and dump the statistics per instruction*/
diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c
--- a/monetdb5/mal/mal_session.c
+++ b/monetdb5/mal/mal_session.c
@@ -523,7 +523,9 @@ MALreader(Client c)
                        return MAL_SUCCEED;
        } else if (MCreadClient(c) > 0)
                return MAL_SUCCEED;
+       MT_lock_set(&mal_contextLock, "MALreader");
        c->mode = FINISHCLIENT;
+       MT_lock_unset(&mal_contextLock, "MALreader");
        if (c->fdin)
                c->fdin->buf[c->fdin->pos] = 0;
        else
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -65,46 +65,51 @@ list_find_column(sql_allocator *sa, list
        stmt *res = NULL;
        node *n;
 
-       if (l && !l->ht && list_length(l) > HASH_MIN_SIZE) {
-               l->ht = hash_new(l->sa, MAX(list_length(l), l->expected_cnt), 
(fkeyvalue)&stmt_key);
-
-               for (n = l->h; n; n = n->next) {
-                       char *nme = column_name(sa, n->data);
-                       int key = hash_key(nme);
-                       
-                       hash_add(l->ht, key, n->data);
+       if (l) {
+               MT_lock_set(&l->ht_lock, "list_find_column");
+               if (!l->ht && list_length(l) > HASH_MIN_SIZE) {
+                       l->ht = hash_new(l->sa, MAX(list_length(l), 
l->expected_cnt), (fkeyvalue)&stmt_key);
+
+                       for (n = l->h; n; n = n->next) {
+                               char *nme = column_name(sa, n->data);
+                               int key = hash_key(nme);
+
+                               hash_add(l->ht, key, n->data);
+                       }
                }
-       }
-       if (l && l->ht) {
-               int key = hash_key(name);
-               sql_hash_e *e = l->ht->buckets[key&(l->ht->size-1)]; 
-
-               if (rname) {
-                       for (; e; e = e->chain) {
-                               stmt *s = e->value;
-                               char *rnme = table_name(sa, s);
-                               char *nme = column_name(sa, s);
-
-                               if (rnme && strcmp(rnme, rname) == 0 && 
+               if (l->ht) {
+                       int key = hash_key(name);
+                       sql_hash_e *e = l->ht->buckets[key&(l->ht->size-1)];
+
+                       if (rname) {
+                               for (; e; e = e->chain) {
+                                       stmt *s = e->value;
+                                       char *rnme = table_name(sa, s);
+                                       char *nme = column_name(sa, s);
+
+                                       if (rnme && strcmp(rnme, rname) == 0 &&
                                            strcmp(nme, name) == 0) {
-                                       res = s;
-                                       break;
+                                               res = s;
+                                               break;
+                                       }
+                               }
+                       } else {
+                               for (; e; e = e->chain) {
+                                       stmt *s = e->value;
+                                       char *nme = column_name(sa, s);
+
+                                       if (nme && strcmp(nme, name) == 0) {
+                                               res = s;
+                                               break;
+                                       }
                                }
                        }
-               } else {
-                       for (; e; e = e->chain) {
-                               stmt *s = e->value;
-                               char *nme = column_name(sa, s);
-
-                               if (nme && strcmp(nme, name) == 0) {
-                                       res = s;
-                                       break;
-                               }
-                       }
+                       MT_lock_unset(&l->ht_lock, "list_find_column");
+                       if (!res)
+                               return NULL;
+                       return res;
                }
-               if (!res)
-                       return NULL;
-               return res;
+               MT_lock_unset(&l->ht_lock, "list_find_column");
        }
        if (rname) {
                for (n = l->h; n; n = n->next) {
diff --git a/sql/common/sql_changeset.c b/sql/common/sql_changeset.c
--- a/sql/common/sql_changeset.c
+++ b/sql/common/sql_changeset.c
@@ -53,16 +53,20 @@ cs_add(changeset * cs, void *elm, int fl
        list_append(cs->set, elm);
        if (flag == TR_NEW && !cs->nelm)
                cs->nelm = cs->set->t;
+       MT_lock_set(&cs->set->ht_lock, "cs_add");
        if (cs->set->ht)
                hash_add(cs->set->ht, base_key(elm), elm);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to