[PATCH 1/7] Split notmuch_database_close into two functions
authorJustus Winter <4winter@informatik.uni-hamburg.de>
Wed, 25 Apr 2012 13:20:16 +0000 (15:20 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:46:43 +0000 (09:46 -0800)
84/7f2904528dc119b4bb4a3a54917abbe398f284 [new file with mode: 0644]

diff --git a/84/7f2904528dc119b4bb4a3a54917abbe398f284 b/84/7f2904528dc119b4bb4a3a54917abbe398f284
new file mode 100644 (file)
index 0000000..742f0cf
--- /dev/null
@@ -0,0 +1,174 @@
+Return-Path: <teythoon@jade-hamburg.de>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 299F2431FAF\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Apr 2012 06:20:39 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id Cq0k9uzcqU6v for <notmuch@notmuchmail.org>;\r
+       Wed, 25 Apr 2012 06:20:38 -0700 (PDT)\r
+Received: from mail.cryptobitch.de (cryptobitch.de [88.198.7.68])\r
+       (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 0AF1B431FAE\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Apr 2012 06:20:38 -0700 (PDT)\r
+Received: from mail.jade-hamburg.de (mail.jade-hamburg.de [85.183.11.228])\r
+       (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by mail.cryptobitch.de (Postfix) with ESMTPSA id 1007358522A\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Apr 2012 15:20:36 +0200 (CEST)\r
+Received: by mail.jade-hamburg.de (Postfix, from userid 401)\r
+       id 85FA7DF2A3; Wed, 25 Apr 2012 15:20:35 +0200 (CEST)\r
+Received: from thinkbox.jade-hamburg.de (mail.jade-hamburg.de [85.183.11.228])\r
+       (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
+       (No client certificate requested) (Authenticated sender: teythoon)\r
+       by mail.jade-hamburg.de (Postfix) with ESMTPSA id E22D9DF2A1;\r
+       Wed, 25 Apr 2012 15:20:31 +0200 (CEST)\r
+Received: from teythoon by thinkbox.jade-hamburg.de with local (Exim 4.77)\r
+       (envelope-from <teythoon@thinkbox.jade-hamburg.de>)\r
+       id 1SN28u-0005Hq-BJ; Wed, 25 Apr 2012 15:20:24 +0200\r
+From: Justus Winter <4winter@informatik.uni-hamburg.de>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/7] Split notmuch_database_close into two functions\r
+Date: Wed, 25 Apr 2012 15:20:16 +0200\r
+Message-Id:\r
+ <1335360016-20289-1-git-send-email-4winter@informatik.uni-hamburg.de>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <20120422180159.GG17810@mit.edu>\r
+References: <20120422180159.GG17810@mit.edu>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 25 Apr 2012 13:20:39 -0000\r
+\r
+Formerly notmuch_database_close closed the xapian database and\r
+destroyed the talloc structure associated with the notmuch database\r
+object. Split notmuch_database_close into notmuch_database_close and\r
+notmuch_database_destroy.\r
+\r
+This makes it possible for long running programs to close the xapian\r
+database and thus release the lock associated with it without\r
+destroying the data structures obtained from it.\r
+\r
+This also makes the api more consistent since every other data\r
+structure has a destructor function.\r
+\r
+The comments in notmuch.h are a courtesy of Austin Clements.\r
+\r
+Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>\r
+---\r
+ lib/database.cc |   14 ++++++++++++--\r
+ lib/notmuch.h   |   22 ++++++++++++++++++----\r
+ 2 files changed, 30 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 16c4354..2fefcad 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -642,7 +642,7 @@ notmuch_database_open (const char *path,\r
+                        "       read-write mode.\n",\r
+                        notmuch_path, version, NOTMUCH_DATABASE_VERSION);\r
+               notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;\r
+-              notmuch_database_close (notmuch);\r
++              notmuch_database_destroy (notmuch);\r
+               notmuch = NULL;\r
+               goto DONE;\r
+           }\r
+@@ -702,7 +702,7 @@ notmuch_database_open (const char *path,\r
+     } catch (const Xapian::Error &error) {\r
+       fprintf (stderr, "A Xapian exception occurred opening database: %s\n",\r
+                error.get_msg().c_str());\r
+-      notmuch_database_close (notmuch);\r
++      notmuch_database_destroy (notmuch);\r
+       notmuch = NULL;\r
+     }\r
+ \r
+@@ -738,9 +738,19 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
+     }\r
+ \r
+     delete notmuch->term_gen;\r
++    notmuch->term_gen = NULL;\r
+     delete notmuch->query_parser;\r
++    notmuch->query_parser = NULL;\r
+     delete notmuch->xapian_db;\r
++    notmuch->xapian_db = NULL;\r
+     delete notmuch->value_range_processor;\r
++    notmuch->value_range_processor = NULL;\r
++}\r
++\r
++void\r
++notmuch_database_destroy (notmuch_database_t *notmuch)\r
++{\r
++    notmuch_database_close (notmuch);\r
+     talloc_free (notmuch);\r
+ }\r
+ \r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 673c423..7d9e092 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -133,7 +133,7 @@ typedef struct _notmuch_filenames notmuch_filenames_t;\r
+  *\r
+  * After a successful call to notmuch_database_create, the returned\r
+  * database will be open so the caller should call\r
+- * notmuch_database_close when finished with it.\r
++ * notmuch_database_destroy when finished with it.\r
+  *\r
+  * The database will not yet have any data in it\r
+  * (notmuch_database_create itself is a very cheap function). Messages\r
+@@ -165,7 +165,7 @@ typedef enum {\r
+  * An existing notmuch database can be identified by the presence of a\r
+  * directory named ".notmuch" below 'path'.\r
+  *\r
+- * The caller should call notmuch_database_close when finished with\r
++ * The caller should call notmuch_database_destroy when finished with\r
+  * this database.\r
+  *\r
+  * In case of any failure, this function returns NULL, (after printing\r
+@@ -175,11 +175,25 @@ notmuch_database_t *\r
+ notmuch_database_open (const char *path,\r
+                      notmuch_database_mode_t mode);\r
+ \r
+-/* Close the given notmuch database, freeing all associated\r
+- * resources. See notmuch_database_open. */\r
++/* Close the given notmuch database.\r
++ *\r
++ * After notmuch_database_close has been called, calls to other\r
++ * functions on objects derived from this database may either behave\r
++ * as if the database had not been closed (e.g., if the required data\r
++ * has been cached) or may fail with a\r
++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION.\r
++ *\r
++ * notmuch_database_close can be called multiple times.  Later calls\r
++ * have no effect.\r
++ */\r
+ void\r
+ notmuch_database_close (notmuch_database_t *database);\r
+ \r
++/* Destroy the notmuch database, closing it if necessary and freeing\r
++* all associated resources. */\r
++void\r
++notmuch_database_destroy (notmuch_database_t *database);\r
++\r
+ /* Return the database path of the given database.\r
+  *\r
+  * The return value is a string owned by notmuch so should not be\r
+-- \r
+1.7.10\r
+\r