blob: 2e7b117095b3caecd18d4f8bbe34f7145ead136c (
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/* -*- C++ -*- */
// $Id$
// ============================================================================
//
// = LIBRARY
// TAO/orbsvcs/Concurrency_Service
//
// = FILENAME
// CC_Lock.h
//
// = DESCRIPTION
// This class implements a lock used by the lock set from the
// concurrency control service
//
// = AUTHORS
// Torben Worm <tworm@cs.wustl.edu>
//
// ============================================================================
#if !defined (_CC_LOCK_H)
#define _CC_LOCK_H
#include "ace/Synch.h"
#include "orbsvcs/CosConcurrencyControlC.h"
#define NUMBER_OF_LOCK_MODES 5
// This contant defines the number of lock modes. There is really no
// way to set this constant dynamically because the nuber of lock
// modes are not stated as part of the IDL.
class TAO_ORBSVCS_Export CC_Lock
{
// = TITLE
// CC_Lock
//
// = DESCRIPTION
// This class implements the lock concept from the concurrency
// control service. The lock holds its mode - this might later
// be changed to subclasses depending on the differences of the
// locks. At present the is only a lock-pr-thread/client-type
// which is essentially a write lock since it is not allowed to
// have more than one lock pr. servant in this implementation.
public:
CC_Lock (CosConcurrencyControl::lock_mode mode);
// Creates the lock with the desired mode
~CC_Lock (void);
// Deletes the lock
void lock (CORBA::Environment &env);
// Acquires this lock. Blocks until lock is obtained
CORBA::Boolean try_lock (CORBA::Environment &env);
// Tries to acquire this lock. If it is not possible to acquire the
// lock, false is returned
void unlock (CORBA::Environment &env);
// Releases this lock.
void change_mode (CosConcurrencyControl::lock_mode new_mode,
CORBA::Environment &env);
// Changes the mode of this lock.
CORBA::Boolean Compatible (const CC_Lock &other);
// returns true if this lock is compatible with the other lock.
CORBA::Boolean Compatible (CosConcurrencyControl::lock_mode mode);
// Returns true is this lock is compatible with the referenced mode.
CosConcurrencyControl::lock_mode GetMode (void);
// Returns the mode of the lock.
protected:
CosConcurrencyControl::lock_mode mode_;
// Holds the lock's mode.
private:
ACE_Thread_Semaphore semaphore_;
// Holds the semaphore for this lock.
// @@ Torben, can you please explain this implementation in a bit more detail?
int lock_held_;
// If greater than zero the lock is held (that number of times).
static CORBA::Boolean compatible_[NUMBER_OF_LOCK_MODES][NUMBER_OF_LOCK_MODES];
// Defines the compatibility of the locks.
};
#endif /* !defined (_CC_LOCK_H) */
|