~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/mgmsrv/SignalQueue.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <ndb_global.h>
 
17
#include "SignalQueue.hpp"
 
18
 
 
19
SignalQueue::SignalQueue() {
 
20
  m_mutex = NdbMutex_Create();
 
21
  m_cond = NdbCondition_Create();
 
22
  m_signalQueueHead = NULL;
 
23
}
 
24
 
 
25
SignalQueue::~SignalQueue() {
 
26
  {
 
27
    Guard g(m_mutex);
 
28
    while(m_signalQueueHead != NULL)
 
29
      delete pop();
 
30
  }
 
31
  NdbMutex_Destroy(m_mutex);
 
32
  m_mutex = NULL;
 
33
  NdbCondition_Destroy(m_cond);
 
34
  m_cond = NULL;
 
35
}
 
36
 
 
37
NdbApiSignal *
 
38
SignalQueue::pop() {
 
39
  NdbApiSignal *ret;
 
40
 
 
41
  if(m_signalQueueHead == NULL)
 
42
    return NULL;
 
43
 
 
44
  ret = m_signalQueueHead->signal;
 
45
 
 
46
  QueueEntry *old = m_signalQueueHead;
 
47
  m_signalQueueHead = m_signalQueueHead->next;
 
48
 
 
49
  delete old;
 
50
 
 
51
  return ret;
 
52
}
 
53
 
 
54
void
 
55
SignalQueue::receive(void *me, NdbApiSignal *signal) {
 
56
  SignalQueue *q = (SignalQueue *)me;
 
57
  q->receive(signal);
 
58
}
 
59
 
 
60
void
 
61
SignalQueue::receive(NdbApiSignal *signal) {
 
62
  QueueEntry *n = new QueueEntry();
 
63
  n->signal = signal;
 
64
  n->next = NULL;
 
65
 
 
66
  Guard guard(m_mutex);
 
67
 
 
68
  if(m_signalQueueHead == NULL) {
 
69
    m_signalQueueHead = n;
 
70
    NdbCondition_Broadcast(m_cond);
 
71
    return;
 
72
  }
 
73
 
 
74
  QueueEntry *cur = m_signalQueueHead;
 
75
 
 
76
  while(cur->next != NULL)
 
77
    cur = cur->next;
 
78
 
 
79
  cur->next = n;
 
80
 
 
81
  NdbCondition_Broadcast(m_cond);
 
82
}
 
83
 
 
84
NdbApiSignal *
 
85
SignalQueue::waitFor(int gsn, NodeId nodeid, Uint32 timeout) {
 
86
  Guard g(m_mutex);
 
87
 
 
88
  if(m_signalQueueHead == NULL)
 
89
    NdbCondition_WaitTimeout(m_cond, m_mutex, timeout);
 
90
 
 
91
  if(m_signalQueueHead == NULL)
 
92
    return NULL;
 
93
 
 
94
  if(gsn != 0 && 
 
95
     m_signalQueueHead->signal->readSignalNumber() != gsn)
 
96
    return NULL;
 
97
 
 
98
  if(nodeid != 0 &&
 
99
     refToNode(m_signalQueueHead->signal->theSendersBlockRef) != nodeid)
 
100
    return NULL;
 
101
 
 
102
  return pop();
 
103
}