summaryrefslogtreecommitdiff
path: root/apps/JAWS/server/PROTOTYPE/JAWS/Concurrency.cpp
blob: e49e8b268c0ff505b0b68295b8b8d246800966b6 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// $Id$

#include "JAWS/Concurrency.h"

JAWS_Dispatcher_Singleton jaws_dispatcher;
JAWS_Thread_Pool_Singleton jaws_thread_pool;
JAWS_Thread_Per_Singleton jaws_thread_per;

JAWS_Concurrency_Base::JAWS_Concurrency_Base (void)
{
}

int
JAWS_Concurrency_Base::put (ACE_Message_Block *mb, ACE_Time_Value *tv)
{
  return this->putq (mb, tv);
}

int
JAWS_Concurrency_Base::svc (void)
{
  int result = 0;

  for (;;)
    {
      ACE_Message_Block *mb;

      // At this point we could set a timeout value so that the
      // threading strategy can delete a thread if there is nothing to
      // do.  Carefully think how to implement it so you don't leave
      // yourself with 0 threads.

      result = this->getq (mb);
      if (result == -1 || mb == 0)
        break;

      this->put_next (mb);
    }
  return 0;
}

JAWS_Dispatch_Policy::JAWS_Dispatch_Policy (void)
{
}

JAWS_Dispatch_Policy::~JAWS_Dispatch_Policy (void)
{
}

JAWS_Dispatcher::JAWS_Dispatcher (JAWS_Dispatch_Policy *policy)
  : policy_(policy)
{
}

JAWS_Thread_Pool_Task::JAWS_Thread_Pool_Task (long flags,
                                              int nthreads,
                                              int maxthreads)
  : nthreads_ (nthreads),
    maxthreads_ (maxthreads)
{
  if (this->activate (flags, nthreads) == -1)
    ACE_ERROR ((LM_ERROR, "%p\n", "JAWS_Thread_Pool_Task::activate"));
}

int
JAWS_Thread_Pool_Task::open (long flags, int nthreads, int maxthreads)
{
  this->nthreads_ = nthreads;
  this->maxthreads_ = maxthreads;

  if (this->activate (flags, nthreads) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "JAWS_Thread_Pool_Task::activate"),
                      -1);
}

JAWS_Thread_Per_Task::JAWS_Thread_Per_Task (long flags, int maxthreads)
  : flags_ (flags),
    maxthreads_ (maxthreads)
{
}

int
JAWS_Thread_Per_Task::open (long flags, int maxthreads)
{
  this->flags_ = flags;
  this->maxthreads_ = maxthreads;
  return 0;
}

int
JAWS_Thread_Per_Task::put (ACE_Message_Block *mb, ACE_Time_Value *tv)
{
  const int force_active = 1;
  const int nthreads = 1;

  if (this->activate (this->flags_, nthreads, force_active) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "JAWS_Thread_Pool_Task::activate"),
                      -1);

  this->putq (mb, tv);

  return 0;
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Singleton<JAWS_Dispatcher, ACE_MT_SYNCH>;
template class ACE_Singleton<JAWS_Thread_Pool_Task, ACE_MT_SYNCH>;
template class ACE_Singleton<JAWS_Thread_Per_Task, ACE_MT_SYNCH>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate  ACE_Singleton<JAWS_Dispatcher, ACE_MT_SYNCH>
#pragma instantiate  ACE_Singleton<JAWS_Thread_Pool_Task, ACE_MT_SYNCH>
#pragma instantiate  ACE_Singleton<JAWS_Thread_Per_Task, ACE_MT_SYNCH>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */