MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
userInterface.cpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB
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 /***************************************************************
20 * I N C L U D E D F I L E S *
21 ***************************************************************/
22 
23 #include <ndb_global.h>
24 #include <time.h>
25 
26 #include "ndb_schema.hpp"
27 #include "ndb_error.hpp"
28 #include "userInterface.h"
29 #include <NdbMutex.h>
30 #include <NdbThread.h>
31 #include <NdbTick.h>
32 #include <NdbApi.hpp>
33 #include <NdbOut.hpp>
34 
35 /***************************************************************
36 * L O C A L C O N S T A N T S *
37 ***************************************************************/
38 
39 /***************************************************************
40 * L O C A L D A T A S T R U C T U R E S *
41 ***************************************************************/
42 
43 /***************************************************************
44 * L O C A L F U N C T I O N S *
45 ***************************************************************/
46 
47 #ifndef NDB_WIN32
48 #include <unistd.h>
49 #endif
50 
51 
52 static NdbMutex* startupMutex = NdbMutex_Create();
53 
54 Ndb*
55 asyncDbConnect(int parallellism){
56  NdbMutex_Lock(startupMutex);
57  Ndb * pNDB = new Ndb("");
58 
59  pNDB->init(parallellism + 1);
60 
61  while(pNDB->waitUntilReady() != 0){
62  }
63 
64  NdbMutex_Unlock(startupMutex);
65 
66  return pNDB;
67 }
68 
69 void
70 asyncDbDisconnect(Ndb* pNDB)
71 {
72  delete pNDB;
73 }
74 
75 double
76 userGetTime(void)
77 {
78  static bool initialized = false;
79  static NDB_TICKS initSecs = 0;
80  static Uint32 initMicros = 0;
81  double timeValue = 0;
82 
83  if ( !initialized ) {
84  initialized = true;
85  NdbTick_CurrentMicrosecond(&initSecs, &initMicros);
86  timeValue = 0.0;
87  } else {
88  NDB_TICKS secs = 0;
89  Uint32 micros = 0;
90 
91  NdbTick_CurrentMicrosecond(&secs, &micros);
92  double s = (double)secs - (double)initSecs;
93  double us = (double)micros - (double)initMicros;
94 
95  timeValue = s + (us / 1000000.0);
96  }
97  return timeValue;
98 }
99 
100 void showTime()
101 {
102  char buf[128];
103  struct tm* tm_now;
104  time_t now;
105  now = ::time((time_t*)NULL);
106  tm_now = ::gmtime(&now);
107 
108  BaseString::snprintf(buf, 128,
109  "%d-%.2d-%.2d %.2d:%.2d:%.2d",
110  tm_now->tm_year + 1900,
111  tm_now->tm_mon,
112  tm_now->tm_mday,
113  tm_now->tm_hour,
114  tm_now->tm_min,
115  tm_now->tm_sec);
116 
117  ndbout_c("Time: %s", buf);
118 }
119