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