blob: 29fed9c52e367aa013c3a9d67f3e2b40a4b5c120 (
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
|
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect( "perthis( readOperations() || writeOperations() )" )
public abstract class pr121197 {
@Pointcut( "" )
protected abstract void readOperations();
@Pointcut( "" )
protected abstract void writeOperations();
private ReadWriteLock _lock = new ReentrantReadWriteLock();
@Before( "readOperations()" )
public void beforeReading() {
_lock.readLock().lock();
}
@After( "readOperations()" )
public void afterReading() {
_lock.readLock().unlock();
}
@Before( "writeOperations()" )
public void beforeWriting() {
_lock.writeLock().lock();
}
@After( "writeOperations()" )
public void afterWriting() {
_lock.writeLock().unlock();
}
}
@Aspect
class ModelThreadSafety extends pr121197 {
@Pointcut( "execution( * C.read*(..) )" )
@Override
protected void readOperations() {}
@Pointcut( "execution( * C.write*(..) )" )
@Override
protected void writeOperations() { }
}
class C {
public void readSomething() {}
public void writeSomething() {}
}
|