~ubuntu-branches/ubuntu/precise/mysql-5.5/precise-201203300109

« back to all changes in this revision

Viewing changes to storage/ndb/test/ndbapi/userInterface.cpp

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-11-08 11:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20111108113113-3ulw01fvi4vn8m25
Tags: upstream-5.5.17
ImportĀ upstreamĀ versionĀ 5.5.17

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