Free cookie consent management tool by TermsFeed Policy Generator

Changeset 399


Ignore:
Timestamp:
07/29/08 16:20:12 (16 years ago)
Author:
gkronber
Message:

fixed #202 (Split big R/W lock into separate R/W locks for each table)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.DB/Database.cs

    r398 r399  
    3636  public class Database : IDatabase {
    3737    private string connectionString;
    38     private ReaderWriterLockSlim rwLock;
     38    private ReaderWriterLockSlim agentLock;
     39    private ReaderWriterLockSlim resultLock;
    3940    public Database(string connectionString) {
    4041      this.connectionString = connectionString;
    41       rwLock = new ReaderWriterLockSlim();
     42      agentLock = new ReaderWriterLockSlim();
     43      resultLock = new ReaderWriterLockSlim();
    4244    }
    4345
    4446    #region create empty database
    4547    public void CreateNew() {
    46       rwLock.EnterWriteLock();
     48      agentLock.EnterWriteLock();
    4749      try {
    4850        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
     
    6870        }
    6971      } finally {
    70         rwLock.ExitWriteLock();
     72        agentLock.ExitWriteLock();
    7173      }
    7274    }
     
    7577    #region insert agent/result/sub-result
    7678    public long InsertAgent(long? parentAgentId, string name, byte[] rawData) {
    77       rwLock.EnterWriteLock();
     79      agentLock.EnterWriteLock();
    7880      try {
    7981        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
     
    107109        }
    108110      } finally {
    109         rwLock.ExitWriteLock();
     111        agentLock.ExitWriteLock();
    110112      }
    111113    }
    112114
    113115    public long InsertResult(long agentId, string summary, string description, byte[] rawData) {
    114       rwLock.EnterWriteLock();
     116      resultLock.EnterWriteLock();
    115117      try {
    116118        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     
    149151        }
    150152      } finally {
    151         rwLock.ExitWriteLock();
     153        resultLock.ExitWriteLock();
    152154      }
    153155    }
    154156
    155157    public long InsertSubResult(long resultId, string summary, string description, byte[] rawData) {
    156       rwLock.EnterWriteLock();
     158      resultLock.EnterWriteLock();
    157159      try {
    158160        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     
    191193        }
    192194      } finally {
    193         rwLock.ExitWriteLock();
     195        resultLock.ExitWriteLock();
    194196      }
    195197    }
     
    198200    #region update agent/run
    199201    public void UpdateAgent(long id, string name) {
    200       rwLock.EnterWriteLock();
     202      agentLock.EnterWriteLock();
    201203      try {
    202204        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     
    220222        }
    221223      } finally {
    222         rwLock.ExitWriteLock();
     224        agentLock.ExitWriteLock();
    223225      }
    224226    }
    225227
    226228    public void UpdateAgent(long id, ProcessStatus status) {
    227       rwLock.EnterWriteLock();
     229      agentLock.EnterWriteLock();
    228230      try {
    229231        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     
    247249        }
    248250      } finally {
    249         rwLock.ExitWriteLock();
     251        agentLock.ExitWriteLock();
    250252      }
    251253    }
    252254
    253255    public void UpdateAgent(long id, byte[] rawData) {
    254       rwLock.EnterWriteLock();
     256      agentLock.EnterWriteLock();
    255257      try {
    256258        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     
    274276        }
    275277      } finally {
    276         rwLock.ExitWriteLock();
     278        agentLock.ExitWriteLock();
    277279      }
    278280    }
     
    283285
    284286    public ICollection<AgentEntry> GetAgents(ProcessStatus status) {
    285       rwLock.EnterReadLock();
     287      agentLock.EnterReadLock();
    286288      List<AgentEntry> agents = new List<AgentEntry>();
    287289      try {
     
    306308        }
    307309      } finally {
    308         rwLock.ExitReadLock();
     310        agentLock.ExitReadLock();
    309311      }
    310312      return agents;
     
    312314
    313315    public ICollection<AgentEntry> GetAgents() {
    314       rwLock.EnterReadLock();
     316      agentLock.EnterReadLock();
    315317      List<AgentEntry> agents = new List<AgentEntry>();
    316318      try {
     
    333335        }
    334336      } finally {
    335         rwLock.ExitReadLock();
     337        agentLock.ExitReadLock();
    336338      }
    337339      return agents;
     
    339341
    340342    public ICollection<AgentEntry> GetSubAgents(long parentAgentId) {
    341       rwLock.EnterReadLock();
     343      agentLock.EnterReadLock();
    342344      List<AgentEntry> agents = new List<AgentEntry>();
    343345      try {
     
    365367        }
    366368      } finally {
    367         rwLock.ExitReadLock();
     369        agentLock.ExitReadLock();
    368370      }
    369371      return agents;
     
    372374    public ICollection<ResultEntry> GetResults(long agentId) {
    373375      List<ResultEntry> results = new List<ResultEntry>();
    374       rwLock.EnterReadLock();
     376      resultLock.EnterReadLock();
    375377      try {
    376378        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
     
    397399        }
    398400      } finally {
    399         rwLock.ExitReadLock();
     401        resultLock.ExitReadLock();
    400402      }
    401403      return results;
     
    404406    public ICollection<ResultEntry> GetSubResults(long resultId) {
    405407      List<ResultEntry> results = new List<ResultEntry>();
    406       rwLock.EnterReadLock();
     408      resultLock.EnterReadLock();
    407409      try {
    408410        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
     
    429431        }
    430432      } finally {
    431         rwLock.ExitReadLock();
     433        resultLock.ExitReadLock();
    432434      }
    433435      return results;
Note: See TracChangeset for help on using the changeset viewer.