summaryrefslogtreecommitdiff
path: root/csharp/LockingInfo.cs
blob: cb5630ca6ef039bef330d3a5892902bb4aee29ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2009 Oracle.  All rights reserved.
 *
 */
using System;
using System.Collections.Generic;
using System.Text;
using BerkeleyDB.Internal;

namespace BerkeleyDB {
    /// <summary>
    /// A class representing the locking options for Berkeley DB operations.
    /// </summary>
    public class LockingInfo {
        /// <summary>
        /// The isolation degree of the operation.
        /// </summary>
        public Isolation IsolationDegree;
        /// <summary>
        /// If true, acquire write locks instead of read locks when doing a
        /// read, if locking is configured.
        /// </summary>
        /// <remarks>
        /// Setting ReadModifyWrite can eliminate deadlock during a
        /// read-modify-write cycle by acquiring the write lock during the read
        /// part of the cycle so that another thread of control acquiring a read
        /// lock for the same item, in its own read-modify-write cycle, will not
        /// result in deadlock.
        /// </remarks>
        public bool ReadModifyWrite;

        /// <summary>
        /// Instantiate a new LockingInfo object
        /// </summary>
        public LockingInfo() {
            IsolationDegree = Isolation.DEGREE_THREE;
            ReadModifyWrite = false;
        }

        internal uint flags {
            get {
                uint ret = 0;
                switch (IsolationDegree) {
                    case (Isolation.DEGREE_ONE):
                        ret |= DbConstants.DB_READ_UNCOMMITTED;
                        break;
                    case (Isolation.DEGREE_TWO):
                        ret |= DbConstants.DB_READ_COMMITTED;
                        break;
                }
                if (ReadModifyWrite)
                    ret |= DbConstants.DB_RMW;
                return ret;
            }
        }

    }
}