KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > perseus > concurrency > lib > ReadWriteLockValue


1 package org.objectweb.perseus.concurrency.lib;
2
3
4 /**
5  * Copyright (C) 2003-2004
6  * - France Telecom R&D
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  * Release: 1.0
23  *
24  * Authors: Olivier Lobry (olivier.lobry@rd.francetelecom.com)
25  *
26  */

27 public class ReadWriteLockValue implements LockValue {
28
29     public static final byte READ = 1;
30     public static final byte UPGRADE = 2;
31     public static final byte WRITE = 3;
32
33
34 /*
35  * 3 2 1 0
36  * X U S N
37  * 0: N 1 1 1 1 = 15
38  * 1: S 0 0 1 1 = 3
39  * 2: U 0 0 0 1 = 1
40  * 3: X 0 0 0 1 = 1
41  */

42
43     static final byte compTable[] = { 15, 3, 1, 1 };
44
45
46     public byte maxValue() {
47         return WRITE;
48     }
49
50     public boolean isCompatibleWith(byte l1, byte l2) {
51         boolean res = (((1 << l1) & compTable[l2]) != 0);
52         return res;
53     }
54
55     public byte getCompatibleWith(byte l1, byte l2) {
56         while (!isCompatibleWith(l1, l2)) l1--;
57         return l1;
58     }
59     
60     public String JavaDoc str(byte l) {
61         switch(l) {
62         case NOLOCK: return "NOLOCK";
63         case READ: return "READ";
64         case UPGRADE: return "UPGRADE";
65         case WRITE: return "WRITE";
66         default: return "UNDEFINED";
67         }
68     }
69 }
70
Popular Tags