summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Concurrency/CC_Lock.cpp
blob: 95b81728b88a81332d1f28531cd16e136df4d526 (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
/* -*- C++ -*- */
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO/orbsvcs/Concurrency_Service
//
// = FILENAME
//    CC_Lock.cpp
//
// = DESCRIPTION
//      This class implements a lock used by the lock set from the
//      concurrency control service
//
// = AUTHORS
//    Torben Worm <tworm@cs.wustl.edu>
//
// ============================================================================

// #include "tao/corba.h"
#include "CC_Lock.h"

CC_Lock::CC_Lock(CosConcurrencyControl::lock_mode mode) : mode_ (mode)
{
  semaphore_.open("test"); // @@ The semaphore must have a unique name??
}

CC_Lock::~CC_Lock()
{
  semaphore_.close();
}

void CC_Lock::lock(void)
{
  semaphore_.acquire();
}

CORBA::Boolean CC_Lock::try_lock()
{
  semaphore_.tryacquire(); //@@ What does tryacquire return??
  return CORBA::B_TRUE;
}

void CC_Lock::unlock(void)
{
  semaphore_.release();
}

void CC_Lock::change_mode(CosConcurrencyControl::lock_mode new_mode)
{
  // @@TAO Hmmm, we cannot really do anything at present since there is
  // only one lock per lock set and that lock is essentially a write lock
}
  
CORBA::Boolean CC_Lock::Compatible(const CC_Lock &other)
{
  return this->Compatible(other.mode_);
}

CORBA::Boolean CC_Lock::Compatible(CosConcurrencyControl::lock_mode mode)
{
  return compatible_[this->mode_][mode];
}

CosConcurrencyControl::lock_mode CC_Lock::GetMode(void)
{
  return mode_;
}

// The check of compatibility is a hard coded table statically allocated
// This table must be changed if the number of lock modes or their
// compatibility are changed. 5 = number of lock modes
CORBA::Boolean CC_Lock::compatible_[5][5] ={
  {CORBA::B_TRUE, CORBA::B_TRUE, CORBA::B_TRUE, CORBA::B_TRUE, CORBA::B_FALSE},
  {CORBA::B_TRUE, CORBA::B_TRUE, CORBA::B_TRUE, CORBA::B_FALSE, CORBA::B_FALSE},
  {CORBA::B_TRUE, CORBA::B_TRUE, CORBA::B_FALSE, CORBA::B_FALSE, CORBA::B_FALSE},
  {CORBA::B_TRUE, CORBA::B_FALSE, CORBA::B_FALSE, CORBA::B_FALSE, CORBA::B_TRUE},
  {CORBA::B_FALSE, CORBA::B_FALSE, CORBA::B_FALSE, CORBA::B_FALSE, CORBA::B_FALSE}};

//#if defined (__ACE_INLINE__)
//#include "CC_Lock.i"
//#endif // defined INLINE