Changeset: 30f7a1ca108a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=30f7a1ca108a
Modified Files:
gdk/gdk_utils.c
Branch: Feb2013
Log Message:
Terminate vmthread asap.
Don't rely on timeouts to terminate this monitor thread.
diffs (60 lines):
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -329,6 +329,7 @@ volatile ATOMIC_TYPE GDK_nmallocs[MAX_BI
#ifdef ATOMIC_LOCK
static MT_Lock mbyteslock;
static MT_Lock GDKstoppedLock;
+static MT_Lock vmtrimLock;
#endif
size_t _MT_pagesize = 0; /* variable holding memory size */
@@ -932,7 +933,10 @@ GDKmunmap(void *addr, size_t size)
#define CATNAP 500
int GDKrecovery = 0;
+#define VMTRIM_IDLE 0
+#define VMTRIM_BUSY 1
static MT_Id GDKvmtrim_id;
+static int vmtrimStatus = VMTRIM_BUSY; /* owned by vmtrim thread */
static void
GDKvmtrim(void *limit)
@@ -942,6 +946,7 @@ GDKvmtrim(void *limit)
(void) limit;
+ ATOMIC_INIT(vmtrim_lock, "GDKvmtrim")
do {
int t;
size_t rss;
@@ -950,9 +955,11 @@ GDKvmtrim(void *limit)
/* sleep using catnaps so we can exit in a timely fashion */
for (t = highload ? CATNAP : 10 * CATNAP; t > 0; t -= CATNAP) {
+ /* allow GDKexit to kill GDKvmtrim thread while
sleeping */
+ (void) ATOMIC_COMP_SWAP(vmtrimStatus, VMTRIM_BUSY,
VMTRIM_IDLE,vmtrimLock, "GDKvmtrim");
MT_sleep_ms(CATNAP);
- if (GDKexiting())
- return;
+ /* prevent from being killed while active */
+ (void) ATOMIC_COMP_SWAP(vmtrimStatus, VMTRIM_IDLE,
VMTRIM_BUSY, vmtrimLock, "GDKvmtrim");
}
rss = MT_getrss();
rssdiff = (ssize_t) rss - (ssize_t) prevrss;
@@ -1162,8 +1169,13 @@ GDKexit(int status)
{
MT_lock_set(&GDKthreadLock, "GDKexit");
if (ATOMIC_COMP_SWAP(GDKstopped, 0, 1, GDKstoppedLock, "GDKexit") == 0)
{
- if (GDKvmtrim_id)
- MT_join_thread(GDKvmtrim_id);
+ /* we have to wait for possible concurrent vmtrim actions to
finish properly */
+ if (GDKvmtrim_id) {
+ if (ATOMIC_GET(vmtrimStatus, vmtrimLock, "GDKexit") ==
VMTRIM_IDLE)
+ MT_kill_thread(GDKvmtrim_id);
+ else
+ MT_join_thread(GDKvmtrim_id);
+ }
GDKnrofthreads = 0;
MT_lock_unset(&GDKthreadLock, "GDKexit");
MT_sleep_ms(50);
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list