Changeset: c240750706fe for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c240750706fe
Modified Files:
MonetDB/NT/MonetDB-Common/MonetDB-Common.vdproj
MonetDB/NT/MonetDB-Common/MonetDB-Common64.vdproj
MonetDB/src/gdk/gdk_system.mx
MonetDB/src/gdk/gdk_utils.mx
MonetDB4/src/tools/embeddedclient.c.in
MonetDB5/src/modules/mal/tablet_sql.mx
MonetDB5/src/tools/embeddedclient.c.in
buildtools/ChangeLog.Oct2010
buildtools/conf/winconfig.h
buildtools/conf/winrules.msc
buildtools/doc/windowsbuild.rst
clients/src/mapiclient/stethoscope.c
pathfinder/NT/MonetDB4-XQuery/MonetDB4-XQuery-Installer.vdproj
pathfinder/NT/MonetDB4-XQuery64/MonetDB4-XQuery-Installer.vdproj
pathfinder/src/tools/embeddedclient.c.in
sql/NT/MonetDB5-SQL/MonetDB5-SQL-Installer.vdproj
sql/NT/MonetDB5-SQL64/MonetDB5-SQL-Installer.vdproj
sql/src/backends/monet5/embeddedclient.c.in
Branch: Oct2010
Log Message:
Get rid of the pthreds library on Windows.
We now use the Windows native calls for threads, semaphores, and
mutexes, and we have an implementation of condition variables based on
those calls.
We cannot use the Windows CRITICAL_SECTION type for mutexes because we
can't implement condition variables using those CRITICAL_SECTIONs.
diffs (truncated from 1191 to 300 lines):
diff -r ae4dfe043718 -r c240750706fe
MonetDB/NT/MonetDB-Common/MonetDB-Common.vdproj
--- a/MonetDB/NT/MonetDB-Common/MonetDB-Common.vdproj Mon Nov 01 14:50:05
2010 +0100
+++ b/MonetDB/NT/MonetDB-Common/MonetDB-Common.vdproj Fri Oct 29 10:26:30
2010 +0200
@@ -51,12 +51,6 @@
}
"Entry"
{
- "MsmKey" = "8:_BB4791ABAA4349E4A0DE1EDA0772E622"
- "OwnerKey" = "8:_UNDEFINED"
- "MsmSig" = "8:_UNDEFINED"
- }
- "Entry"
- {
"MsmKey" = "8:_BFB12BC46509499A943E79B9BECB1E9A"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
@@ -305,26 +299,6 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
-
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_BB4791ABAA4349E4A0DE1EDA0772E622"
- {
- "SourcePath" = "8:C:\\Libraries\\Pthreads\\lib\\pthreadVC2.dll"
- "TargetName" = "8:pthreadVC2.dll"
- "Tag" = "8:"
- "Folder" = "8:_AC71646495814C55B03F69019B5070C2"
- "Condition" = "8:"
- "Transitive" = "11:FALSE"
- "Vital" = "11:TRUE"
- "ReadOnly" = "11:FALSE"
- "Hidden" = "11:FALSE"
- "System" = "11:FALSE"
- "Permanent" = "11:FALSE"
- "SharedLegacy" = "11:FALSE"
- "PackageAs" = "3:1"
- "Register" = "3:1"
- "Exclude" = "11:FALSE"
- "IsDependency" = "11:FALSE"
- "IsolateTo" = "8:"
- }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_BFB12BC46509499A943E79B9BECB1E9A"
{
"SourcePath" = "8:C:\\Program Files\\PCRE\\bin\\pcre.dll"
diff -r ae4dfe043718 -r c240750706fe
MonetDB/NT/MonetDB-Common/MonetDB-Common64.vdproj
--- a/MonetDB/NT/MonetDB-Common/MonetDB-Common64.vdproj Mon Nov 01 14:50:05
2010 +0100
+++ b/MonetDB/NT/MonetDB-Common/MonetDB-Common64.vdproj Fri Oct 29 10:26:30
2010 +0200
@@ -51,12 +51,6 @@
}
"Entry"
{
- "MsmKey" = "8:_BB4791ABAA4349E4A0DE1EDA0772E622"
- "OwnerKey" = "8:_UNDEFINED"
- "MsmSig" = "8:_UNDEFINED"
- }
- "Entry"
- {
"MsmKey" = "8:_BFB12BC46509499A943E79B9BECB1E9A"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
@@ -285,26 +279,6 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
-
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_BB4791ABAA4349E4A0DE1EDA0772E622"
- {
- "SourcePath" = "8:C:\\Libraries\\Pthreads\\lib64\\pthreadVC2.dll"
- "TargetName" = "8:pthreadVC2.dll"
- "Tag" = "8:"
- "Folder" = "8:_AC71646495814C55B03F69019B5070C2"
- "Condition" = "8:"
- "Transitive" = "11:FALSE"
- "Vital" = "11:TRUE"
- "ReadOnly" = "11:FALSE"
- "Hidden" = "11:FALSE"
- "System" = "11:FALSE"
- "Permanent" = "11:FALSE"
- "SharedLegacy" = "11:FALSE"
- "PackageAs" = "3:1"
- "Register" = "3:1"
- "Exclude" = "11:FALSE"
- "IsDependency" = "11:FALSE"
- "IsolateTo" = "8:"
- }
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_BFB12BC46509499A943E79B9BECB1E9A"
{
"SourcePath" = "8:C:\\Program Files\\PCRE\\bin\\pcre.dll"
diff -r ae4dfe043718 -r c240750706fe MonetDB/src/gdk/gdk_system.mx
--- a/MonetDB/src/gdk/gdk_system.mx Mon Nov 01 14:50:05 2010 +0100
+++ b/MonetDB/src/gdk/gdk_system.mx Fri Oct 29 10:26:30 2010 +0200
@@ -179,6 +179,16 @@
@- MT Lock API
@h
+#if !defined(HAVE_PTHREAD_H) && defined(_MSC_VER)
+typedef HANDLE pthread_mutex_t;
+typedef void *pthread_mutexattr_t;
+gdk_export void pthread_mutex_init(pthread_mutex_t *, const
pthread_mutexattr_t *);
+gdk_export void pthread_mutex_destroy(pthread_mutex_t *);
+gdk_export int pthread_mutex_lock(pthread_mutex_t *);
+gdk_export int pthread_mutex_trylock(pthread_mutex_t *);
+gdk_export int pthread_mutex_unlock(pthread_mutex_t *);
+#endif
+
typedef pthread_mutex_t MT_Lock;
#define MT_lock_init(l,n) { pthread_mutex_init((pthread_mutex_t*) l, 0);
MT_locktrace_set(l,n); }
@@ -200,7 +210,13 @@
@- MT Semaphore API
@h
-#if defined(_AIX) || defined(__MACH__)
+#if !defined(HAVE_PTHREAD_H) && defined(_MSC_VER)
+typedef HANDLE pthread_sema_t;
+gdk_export void pthread_sema_init(pthread_sema_t *s, int flag, int nresources);
+gdk_export void pthread_sema_destroy(pthread_sema_t *s);
+gdk_export void pthread_sema_up(pthread_sema_t *s);
+gdk_export void pthread_sema_down(pthread_sema_t *s);
+#elif defined(_AIX) || defined(__MACH__)
typedef struct {
int cnt;
pthread_mutex_t mutex;
@@ -236,6 +252,18 @@
@- MT Conditional Variable API
@h
+#if !defined(HAVE_PTHREAD_H) && defined(_MSC_VER)
+typedef struct {
+ int waiters_count; /* number of waiting threads */
+ CRITICAL_SECTION waiters_count_lock; /* serialize access to
waiters_count_ */
+ HANDLE sema; /* queue up threads waiting for condition */
+} pthread_cond_t;
+typedef void *pthread_condattr_t;
+gdk_export int pthread_cond_init(pthread_cond_t *, pthread_condattr_t *);
+gdk_export int pthread_cond_destroy(pthread_cond_t *);
+gdk_export int pthread_cond_signal(pthread_cond_t *);
+gdk_export int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
+#endif
typedef pthread_cond_t MT_Cond;
#define MT_cond_init(c,n) { pthread_cond_init((pthread_cond_t*) c, NULL);
MT_locktrace_set(c,n); }
@@ -262,7 +290,11 @@
size_t _MT_pagesize = 0; /* variable holding memory size */
size_t _MT_npages = 0; /* variable holding page size */
-MT_Lock MT_system_lock = PTHREAD_MUTEX_INITIALIZER;
+MT_Lock MT_system_lock
+#ifdef PTHREAD_MUTEX_INITIALIZER
+ = PTHREAD_MUTEX_INITIALIZER
+#endif
+ ;
#ifdef MT_LOCK_TRACE
unsigned long long MT_locktrace_cnt[65536] = { 0 };
@@ -410,6 +442,249 @@
#endif
}
+#if !defined(HAVE_PTHREAD_H) && defined(_MSC_VER)
+static struct winthread {
+ struct winthread *next;
+ HANDLE hdl;
+ DWORD tid;
+ void (*func) (void *);
+ void *arg;
+} *winthreads = NULL;
+static CRITICAL_SECTION winthread_cs;
+static int winthread_cs_init = 0;
+
+static void
+rm_winthread(struct winthread *w)
+{
+ struct winthread **wp;
+
+ assert(winthread_cs_init);
+ EnterCriticalSection(&winthread_cs);
+ for (wp = &winthreads; *wp && *wp != w; wp = &(*wp)->next)
+ ;
+ if (*wp)
+ *wp = w->next;
+ LeaveCriticalSection(&winthread_cs);
+ GDKfree(w);
+}
+
+static DWORD WINAPI
+thread_starter(LPVOID arg)
+{
+ (*((struct winthread *) arg)->func)(((struct winthread *) arg)->arg);
+ if (((struct winthread *) arg)->hdl == NULL)
+ rm_winthread((struct winthread *) arg);
+ ExitThread(0);
+ return TRUE;
+}
+
+int
+MT_create_thread(MT_Id *t, void (*f) (void *), void *arg, enum MT_thr_detach d)
+{
+ struct winthread *w = GDKmalloc(sizeof(*w));
+
+ if (winthread_cs_init == 0) {
+ /* we only get here before any threads are created,
+ and this is the only time that winthread_cs_init is
+ ever changed */
+ InitializeCriticalSection(&winthread_cs);
+ winthread_cs_init = 1;
+ }
+ w->func = f;
+ w->arg = arg;
+ EnterCriticalSection(&winthread_cs);
+ w->next = winthreads;
+ winthreads = w;
+ LeaveCriticalSection(&winthread_cs);
+ w->hdl = CreateThread(NULL, THREAD_STACK_SIZE, thread_starter, w, 0,
&w->tid);
+ if (w->hdl == NULL) {
+ rm_winthread(w);
+ return -1;
+ }
+ *t = (MT_Id) w->tid;
+ if (d == MT_THR_DETACHED) {
+ /* not joinable */
+ CloseHandle(w->hdl);
+ w->hdl = NULL;
+ }
+ return 0;
+}
+
+void
+MT_exit_thread(int s)
+{
+ DWORD t;
+ struct winthread *w;
+
+ assert(winthread_cs_init);
+ t = GetCurrentThreadId();
+ EnterCriticalSection(&winthread_cs);
+ for (w = winthreads; w && w->tid != t; w = w->next)
+ ;
+ LeaveCriticalSection(&winthread_cs);
+ if (w->hdl == NULL)
+ rm_winthread(w);
+ ExitThread(s);
+}
+
+int
+MT_join_thread(MT_Id t)
+{
+ struct winthread *w;
+
+ assert(winthread_cs_init);
+ EnterCriticalSection(&winthread_cs);
+ for (w = winthreads; w && w->tid != t; w = w->next)
+ ;
+ LeaveCriticalSection(&winthread_cs);
+ if (w == NULL || w->hdl == NULL)
+ return -1;
+ if (WaitForSingleObject(w->hdl, INFINITE) == WAIT_OBJECT_0 &&
+ CloseHandle(w->hdl)) {
+ rm_winthread(w);
+ return 0;
+ }
+ return -1;
+}
+
+int
+MT_kill_thread(MT_Id t)
+{
+ struct winthread *w;
+
+ assert(winthread_cs_init);
+ EnterCriticalSection(&winthread_cs);
+ for (w = winthreads; w && w->tid != t; w = w->next)
+ ;
+ LeaveCriticalSection(&winthread_cs);
+ if (w == NULL)
+ return -1;
+ if (w->hdl == NULL) {
+ /* detached thread */
+ HANDLE h;
+ int ret = 0;
+ h = OpenThread(THREAD_ALL_ACCESS, 0, (DWORD) t);
+ if (h == NULL)
+ return -1;
+ if (TerminateThread(h, -1))
+ ret = -1;
+ CloseHandle(h);
+ return ret;
+ }
+ if (TerminateThread(w->hdl, -1))
+ return 0;
+ return -1;
+}
+
+void
+pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t
*mutexattr)
+{
+ (void) mutexattr;
+ *mutex = CreateMutex(NULL, 0, NULL);
+}
+
+void
+pthread_mutex_destroy(pthread_mutex_t *mutex)
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list