aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/message.cc
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2010-02-08 11:33:33 -0800
committerGravatar Carl Worth <cworth@cworth.org>2010-02-09 11:14:11 -0800
commit9439b217c349478b3603d5368f534acb1cd23974 (patch)
treed7c7ebd26b6a3256671eee5bd8a28a424f38b894 /lib/message.cc
parent0d58d46f7af39ba85209a7026644d36998c88a45 (diff)
Switch from random to sequential thread identifiers.
The sequential identifiers have the advantage of being guaranteed to be unique (until we overflow a 64-bit unsigned integer), and also take up half as much space in the "notmuch search" output (16 columns rather than 32). This change also has the side effect of fixing a bug where notmuch could block on /dev/random at startup (waiting for some entropy to appear). This bug was hit hard by the test suite, (which could easily exhaust the available entropy on common systems---resulting in large delays of the test suite).
Diffstat (limited to 'lib/message.cc')
-rw-r--r--lib/message.cc46
1 files changed, 0 insertions, 46 deletions
diff --git a/lib/message.cc b/lib/message.cc
index f0e905b7..01950505 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -42,13 +42,6 @@ struct _notmuch_message {
Xapian::Document doc;
};
-/* "128 bits of thread-id ought to be enough for anybody" */
-#define NOTMUCH_THREAD_ID_BITS 128
-#define NOTMUCH_THREAD_ID_DIGITS (NOTMUCH_THREAD_ID_BITS / 4)
-typedef struct _thread_id {
- char str[NOTMUCH_THREAD_ID_DIGITS + 1];
-} thread_id_t;
-
/* We end up having to call the destructor explicitly because we had
* to use "placement new" in order to initialize C++ objects within a
* block that we allocated with talloc. So C++ is making talloc
@@ -557,45 +550,6 @@ _notmuch_message_set_date (notmuch_message_t *message,
Xapian::sortable_serialise (time_value));
}
-static void
-thread_id_generate (thread_id_t *thread_id)
-{
- static int seeded = 0;
- FILE *dev_random;
- uint32_t value;
- char *s;
- int i;
-
- if (! seeded) {
- dev_random = fopen ("/dev/random", "r");
- if (dev_random == NULL) {
- srand (time (NULL));
- } else {
- fread ((void *) &value, sizeof (value), 1, dev_random);
- srand (value);
- fclose (dev_random);
- }
- seeded = 1;
- }
-
- s = thread_id->str;
- for (i = 0; i < NOTMUCH_THREAD_ID_DIGITS; i += 8) {
- value = rand ();
- sprintf (s, "%08x", value);
- s += 8;
- }
-}
-
-void
-_notmuch_message_ensure_thread_id (notmuch_message_t *message)
-{
- /* If not part of any existing thread, generate a new thread_id. */
- thread_id_t thread_id;
-
- thread_id_generate (&thread_id);
- _notmuch_message_add_term (message, "thread", thread_id.str);
-}
-
/* Synchronize changes made to message->doc out into the database. */
void
_notmuch_message_sync (notmuch_message_t *message)