Changeset: 2c89d7203494 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2c89d7203494
Modified Files:
clients/Tests/exports.stable.out
gdk/gdk.h
gdk/gdk_utils.c
monetdb5/mal/mal_client.c
Branch: Apr2019
Log Message:
Simplify. THRnew is now only called once for the main thread.
diffs (125 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -336,7 +336,6 @@ Thread THRget(int tid);
void *THRgetdata(int);
int THRgettid(void);
int THRhighwater(void);
-Thread THRnew(const char *name);
void THRsetdata(int, void *);
void TMabort(void);
gdk_return TMcommit(void);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -2308,7 +2308,6 @@ typedef struct threadStruct {
gdk_export int THRgettid(void);
gdk_export Thread THRget(int tid);
-gdk_export Thread THRnew(const char *name);
gdk_export MT_Id THRcreate(void (*f) (void *), void *arg, enum MT_thr_detach
d, const char *name);
gdk_export void THRdel(Thread t);
gdk_export void THRsetdata(int, void *);
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -1305,50 +1305,46 @@ GDK_find_self(void)
return GDK_find_thread(MT_getpid());
}
-Thread
+static Thread
THRnew(const char *name)
{
int tid = 0;
Thread s;
- MT_Id pid = MT_getpid();
- s = GDK_find_thread(pid);
- if (s == NULL) {
- MT_lock_set(&GDKthreadLock);
- for (s = GDKthreads; s < GDKthreads + THREADS; s++) {
- if (s->pid == 0) {
- break;
- }
- }
- if (s == GDKthreads + THREADS) {
- MT_lock_unset(&GDKthreadLock);
- IODEBUG fprintf(stderr, "#THRnew: too many threads\n");
- GDKerror("THRnew: too many threads\n");
- return NULL;
+ MT_lock_set(&GDKthreadLock);
+ for (s = GDKthreads; s < GDKthreads + THREADS; s++) {
+ if (s->pid == 0) {
+ break;
}
- tid = s->tid;
- *s = (ThreadRec) {
- .pid = pid,
- .tid = tid,
- .data[0] = THRdata[0],
- .data[1] = THRdata[1],
- .sp = THRsp(),
- .name = GDKstrdup(name),
- };
+ }
+ if (s == GDKthreads + THREADS) {
+ MT_lock_unset(&GDKthreadLock);
+ IODEBUG fprintf(stderr, "#THRnew: too many threads\n");
+ GDKerror("THRnew: too many threads\n");
+ return NULL;
+ }
+ tid = s->tid;
+ *s = (ThreadRec) {
+ .pid = MT_getpid(),
+ .tid = tid,
+ .data[0] = THRdata[0],
+ .data[1] = THRdata[1],
+ .sp = THRsp(),
+ .name = GDKstrdup(name),
+ };
- if (s->name == NULL) {
- s->pid = 0;
- MT_lock_unset(&GDKthreadLock);
- IODEBUG fprintf(stderr, "#THRnew: malloc failure\n");
- GDKerror("THRnew: malloc failure\n");
- return NULL;
- }
- MT_thread_setdata(s);
- GDKnrofthreads++;
- PARDEBUG fprintf(stderr, "#%x %zu sp = %zu\n", (unsigned)
s->tid, (size_t) pid, (size_t) s->sp);
- PARDEBUG fprintf(stderr, "#nrofthreads %d\n", GDKnrofthreads);
+ if (s->name == NULL) {
+ s->pid = 0; /* deallocate */
MT_lock_unset(&GDKthreadLock);
+ IODEBUG fprintf(stderr, "#THRnew: malloc failure\n");
+ GDKerror("THRnew: malloc failure\n");
+ return NULL;
}
+ MT_thread_setdata(s);
+ GDKnrofthreads++;
+ PARDEBUG fprintf(stderr, "#%x %zu sp = %zu\n", (unsigned) s->tid,
(size_t) s->pid, (size_t) s->sp);
+ PARDEBUG fprintf(stderr, "#nrofthreads %d\n", GDKnrofthreads);
+ MT_lock_unset(&GDKthreadLock);
return s;
}
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -289,12 +289,9 @@ int
MCinitClientThread(Client c)
{
Thread t;
- char cname[11 + 1];
- snprintf(cname, 11, OIDFMT, c->user);
- cname[11] = '\0';
- t = THRnew(cname);
- if (t == 0) {
+ t = MT_thread_getdata(); /* should succeed */
+ if (t == NULL) {
MPresetProfiler(c->fdout);
return -1;
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list