1
/* Copyright (C) 2003 MySQL AB
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.
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.
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 */
16
#ifndef __SIGNALQUEUE_HPP_INCLUDED__
17
#define __SIGNALQUEUE_HPP_INCLUDED__
19
#include <NdbApiSignal.hpp>
21
#include <NdbCondition.h>
24
/* XXX Look for an already existing definition */
25
#define DEFAULT_TIMEOUT 5000
29
typedef void (* SignalHandler)(void *obj, int gsn, NdbApiSignal *signal);
35
* Static wrapper making it possible to call receive without knowing the
36
* type of the receiver
38
static void receive(void *me, NdbApiSignal *signal);
41
* Enqueues a signal, and notifies any thread waiting for signals.
43
void receive(NdbApiSignal *signal);
45
NdbApiSignal *waitFor(int gsn,
47
Uint32 timeout = DEFAULT_TIMEOUT);
48
template<class T> bool waitFor(Vector<T> &t,
50
NdbApiSignal **signal,
51
Uint32 timeout = DEFAULT_TIMEOUT);
53
NdbMutex *m_mutex; /* Locks all data in SignalQueue */
54
NdbCondition *m_cond; /* Notifies about new signal in the queue */
57
* Returns the last recently received signal. Must be called with
59
* The caller takes responsibility for deleting the returned object.
61
* @returns NULL if failed, or a received signal
70
QueueEntry *m_signalQueueHead; /** Head of the queue.
71
* New entries added on the tail
75
template<class T> bool
76
SignalQueue::waitFor(Vector<T> &t,
78
NdbApiSignal **signal,
82
if(m_signalQueueHead == NULL)
83
NdbCondition_WaitTimeout(m_cond, m_mutex, timeout);
85
if(m_signalQueueHead == NULL)
88
for(size_t i = 0; i < t.size(); i++) {
89
if(t[i].check(m_signalQueueHead->signal)) {
99
#endif /* !__SIGNALQUEUE_HPP_INCLUDED__ */