summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Concurrency/CC_LockSet.cpp
blob: 0fe25901e2a6d50ca8d29ec424e589b7ca85d818 (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
/* -*- C++ -*- */

// $Id$

// ============================================================================
//
// = LIBRARY
//    cos
// 
// = FILENAME
//   CC_LockSet.cpp
//
// = AUTHOR
//    Torben Worm <tworm@cs.wustl.edu>
// 
// ============================================================================

#include "CC_LockSet.h"

// Default constructor. We cannot create the lock at this point because we
// are not locking anything, and we do not know the mode of the lock. In a
// full fledged version the lock set (implementation) will be instantiated
// here
CC_LockSet::CC_LockSet(void)
  : related_lockset_ (0)
{
  // Do nothing
}

// Constructor used to create related lock sets.
CC_LockSet::CC_LockSet(CosConcurrencyControl::LockSet_ptr related)
  : related_lockset_ (related)
{
  // Do nothing
}

// Destructor. Remove the lock if it exists. In a later version the lock set
// must be removed here. Actually if all locks have been unlocked no lock
// instances should exist at this point.
CC_LockSet::~CC_LockSet(void)
{
  if(lock_!=0)
    delete lock_;
}

// Locks the lock in the desired mode. Blocks until success. In a later
// version the lock set should be searched for incompatible locks
void CC_LockSet::lock(CosConcurrencyControl::lock_mode mode,
		      CORBA::Environment &env)
{
  if(lock==0) {
    lock_ = new CC_Lock(mode);
  }
  lock_->lock();
}

// Tries to lock. If it is not possible false is returned. Comments for lock
// holds for later version
CORBA::Boolean CC_LockSet::try_lock(CosConcurrencyControl::lock_mode mode,
				    CORBA::Environment &env)
{
  return lock_->try_lock();
}

// Drops the specified lock. In this simple case we have only one lock at
// any time so we just drop that lock.
void CC_LockSet::unlock(CosConcurrencyControl::lock_mode mode,
			CORBA::Environment &env)
{
  lock_->unlock();
}

// Changes the mode of a held lock. In this version we deal with only
// one type of lock (in reality) and therefore the type is of no meaning
void CC_LockSet::change_mode (CosConcurrencyControl::lock_mode held_mode,
			      CosConcurrencyControl::lock_mode new_mode,
			      CORBA::Environment &env)
{
  lock_->change_mode(new_mode);
}