1
/* Copyright (C) 2009 Sun Microsystems
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
#include "information_share.h"
23
typedef map<const char *, InformationShare* > mapType;
24
static mapType open_tables;
26
pthread_mutex_t share_mutex = PTHREAD_MUTEX_INITIALIZER;
28
InformationShare *InformationShare::get(const char *table_name)
30
InformationShare *share;
31
mapType::iterator iter;
34
length= (uint) strlen(table_name);
35
pthread_mutex_lock(&share_mutex);
37
iter= open_tables.find(table_name);
39
if (iter!= open_tables.end())
41
share= (*iter).second;
46
share= new (nothrow) InformationShare(table_name);
48
pthread_mutex_unlock(&share_mutex);
53
void InformationShare::start(void)
58
void InformationShare::stop(void)
60
pthread_mutex_destroy(&share_mutex);
64
void InformationShare::free(InformationShare *share)
66
pthread_mutex_lock(&share_mutex);
68
if (share->dec() == 0)
69
open_tables.erase(share->name.c_str());
70
pthread_mutex_unlock(&share_mutex);