~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/information_engine/information_share.cc

  • Committer: Brian Aker
  • Date: 2009-10-30 15:58:06 UTC
  • mfrom: (1183.1.30 merge)
  • Revision ID: brian@gaz-20091030155806-bq7mu2f5ljtodn0h
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2009 Sun Microsystems
 
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 "information_share.h"
 
17
 
 
18
#include <map>
 
19
#include <utility>
 
20
 
 
21
using namespace std;
 
22
 
 
23
typedef map<const char *, InformationShare* > mapType;
 
24
static mapType open_tables;
 
25
 
 
26
pthread_mutex_t share_mutex = PTHREAD_MUTEX_INITIALIZER;
 
27
 
 
28
InformationShare *InformationShare::get(const char *table_name)
 
29
{
 
30
  InformationShare *share;
 
31
  mapType::iterator iter;
 
32
  uint32_t length;
 
33
 
 
34
  length= (uint) strlen(table_name);
 
35
  pthread_mutex_lock(&share_mutex);
 
36
 
 
37
  iter= open_tables.find(table_name);
 
38
 
 
39
  if (iter!= open_tables.end())
 
40
  {
 
41
    share= (*iter).second;
 
42
    share->inc();
 
43
    return share;
 
44
  }
 
45
 
 
46
  share= new (nothrow) InformationShare(table_name);
 
47
 
 
48
  pthread_mutex_unlock(&share_mutex);
 
49
 
 
50
  return share;
 
51
}
 
52
 
 
53
void InformationShare::start(void)
 
54
{
 
55
  /* NULL */
 
56
}
 
57
 
 
58
void InformationShare::stop(void)
 
59
{
 
60
  pthread_mutex_destroy(&share_mutex);
 
61
  open_tables.clear();
 
62
}
 
63
 
 
64
void InformationShare::free(InformationShare *share)
 
65
{
 
66
  pthread_mutex_lock(&share_mutex);
 
67
 
 
68
  if (share->dec() == 0)
 
69
    open_tables.erase(share->name.c_str());
 
70
  pthread_mutex_unlock(&share_mutex);
 
71
}
 
72