Changeset: 626fb8b0daa2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/626fb8b0daa2
Modified Files:
        gdk/gdk_bbp.c
Branch: Sep2022
Log Message:

Use an external lock to potentially synchronize with external programs.


diffs (42 lines):

diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -265,18 +265,37 @@ static volatile MT_Id locked_by = 0;
 static int BBPunloadCnt = 0;
 static MT_Lock GDKunloadLock = MT_LOCK_INITIALIZER(GDKunloadLock);
 
-/* GDKtmLock protects all accesses and changes to BAKDIR and SUBDIR */
+/* GDKtmLock protects all accesses and changes to BAKDIR and SUBDIR
+ * must use BBPtmlock()/BBPtmunlock() to set/unset the lock */
 static MT_Lock GDKtmLock = MT_LOCK_INITIALIZER(GDKtmLock);
+static char *lockfile;
+static int lockfd;
 
 void
 BBPtmlock(void)
 {
        MT_lock_set(&GDKtmLock);
+       if (GDKinmemory(0))
+               return;
+       /* also use an external lock file to synchronize with external
+        * programs */
+       if (lockfile == NULL) {
+               lockfile = GDKfilepath(0, NULL, ".tm_lock", NULL);
+               if (lockfile == NULL)
+                       return;
+       }
+       lockfd = MT_lockf(lockfile, F_LOCK);
 }
 
 void
 BBPtmunlock(void)
 {
+       if (lockfile && lockfd >= 0) {
+               assert(!GDKinmemory(0));
+               MT_lockf(lockfile, F_ULOCK);
+               close(lockfd);
+               lockfd = -1;
+       }
        MT_lock_unset(&GDKtmLock);
 }
 
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to