MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Monitor.cpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB, 2009 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <ndb_global.h>
20 
21 #include <NdbThread.h>
22 #include <NdbOut.hpp>
23 #include <NdbSleep.h>
24 
25 #include "CPCD.hpp"
26 #include "common.hpp"
27 
28 static void *
29 monitor_thread_create_wrapper(void * arg) {
30  CPCD::Monitor *mon = (CPCD::Monitor *)arg;
31  mon->run();
32  return NULL;
33 }
34 
35 CPCD::Monitor::Monitor(CPCD *cpcd, int poll) {
36  m_cpcd = cpcd;
37  m_pollingInterval = poll;
38  m_changeCondition = NdbCondition_Create();
39  m_changeMutex = NdbMutex_Create();
40  m_monitorThread = NdbThread_Create(monitor_thread_create_wrapper,
41  (NDB_THREAD_ARG*) this,
42  0, // default stack size
43  "ndb_cpcd_monitor",
44  NDB_THREAD_PRIO_MEAN);
45  m_monitorThreadQuitFlag = false;
46 }
47 
49  NdbThread_Destroy(&m_monitorThread);
50  NdbCondition_Destroy(m_changeCondition);
51  NdbMutex_Destroy(m_changeMutex);
52 }
53 
54 void
56  while(1) {
57  NdbMutex_Lock(m_changeMutex);
58  NdbCondition_WaitTimeout(m_changeCondition,
59  m_changeMutex,
60  m_pollingInterval * 1000);
61 
62  MutexVector<CPCD::Process *> &proc = *m_cpcd->getProcessList();
63 
64  proc.lock();
65 
66  for(size_t i = 0; i < proc.size(); i++) {
67  proc[i]->monitor();
68  }
69 
70  proc.unlock();
71 
72  NdbMutex_Unlock(m_changeMutex);
73  }
74 }
75 
76 void
78  NdbCondition_Signal(m_changeCondition);
79 }
80 
81 template class MutexVector<CPCD::Process*>;