[banshee] [Hyena] Optimize the sqlite layer



commit 4920427d2f1f0e3c62b719424f405cb93677d0d3
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Thu Dec 10 15:06:17 2009 -0800

    [Hyena] Optimize the sqlite layer
    
    Make some internal properties fields instead, and fix a bug causing many
    excessive WaitOne calls.

 .../Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs  |   14 ++++++--------
 .../Hyena.Data.Sqlite/HyenaSqliteConnection.cs     |   12 ++++--------
 2 files changed, 10 insertions(+), 16 deletions(-)
---
diff --git a/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs b/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
index be45a9e..b0970d3 100644
--- a/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
+++ b/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
@@ -81,11 +81,7 @@ namespace Hyena.Data.Sqlite
             get { return command; }
         }
 
-        private HyenaCommandType command_type;
-        internal HyenaCommandType CommandType {
-            get { return command_type; }
-            set { command_type = value; }
-        }
+        internal HyenaCommandType CommandType;
 
 #endregion
 
@@ -118,7 +114,7 @@ namespace Hyena.Data.Sqlite
                     if (log_all)
                         ticks = System.Environment.TickCount;
 
-                    switch (command_type) {
+                    switch (CommandType) {
                         case HyenaCommandType.Reader:
                             using (SqliteDataReader reader = sql_command.ExecuteReader ()) {
                                 result = new HyenaSqliteArrayDataReader (reader);
@@ -159,7 +155,9 @@ namespace Hyena.Data.Sqlite
                 conn.ResultReadySignal.WaitOne ();
             }
 
+            // Reference the results since they could be overwritten
             object ret = result;
+            var exception = execution_exception;
 
             // Reset to false in case run again
             finished = false;
@@ -167,8 +165,8 @@ namespace Hyena.Data.Sqlite
             conn.ClaimResult ();
             finished_event.Set ();
 
-            if (execution_exception != null) {
-                throw execution_exception;
+            if (exception != null) {
+                throw exception;
             }
 
             return ret;
diff --git a/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs b/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
index 65a53e1..037c192 100644
--- a/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
+++ b/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
@@ -100,7 +100,7 @@ namespace Hyena.Data.Sqlite
         private volatile bool dispose_requested = false;
         private volatile int results_ready = 0;
         private AutoResetEvent queue_signal = new AutoResetEvent (false);
-        private ManualResetEvent result_ready_signal = new ManualResetEvent (false);
+        internal ManualResetEvent ResultReadySignal = new ManualResetEvent (false);
 
         private volatile Thread transaction_thread = null;
         private ManualResetEvent transaction_signal = new ManualResetEvent (true);
@@ -111,10 +111,6 @@ namespace Hyena.Data.Sqlite
             set { warn_if_called_from_thread = value; }
         }
 
-        internal ManualResetEvent ResultReadySignal {
-            get { return result_ready_signal; }
-        }
-
         public event EventHandler<ExecutingEventArgs> Executing;
 
         public HyenaSqliteConnection(string dbpath)
@@ -402,9 +398,9 @@ namespace Hyena.Data.Sqlite
         internal void ClaimResult ()
         {
             lock (command_queue) {
-                results_ready++;
+                results_ready--;
                 if (results_ready == 0) {
-                    result_ready_signal.Reset ();
+                    ResultReadySignal.Reset ();
                 }
             }
         }
@@ -443,7 +439,7 @@ namespace Hyena.Data.Sqlite
 
                     lock (command_queue) {
                         results_ready++;
-                        result_ready_signal.Set ();
+                        ResultReadySignal.Set ();
                     }
                 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]