From 6fde6b0fe90abde84011202edd40fe46eb06af44 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 21 Nov 2010 16:20:55 +0000 Subject: --- src/maps/hashmap.h | 3 +-- src/maps/hashmap.tmpl | 5 ++--- src/maps/mtools.h | 3 +-- src/maps/mtools.tmpl | 3 +-- src/maps/nhashmap.h | 3 +-- src/maps/nhashmap.tmpl | 3 +-- src/maps/shashmap.h | 5 +++-- src/maps/shashmap.tmpl | 41 +++++++++++++++++++++++++++++++++-------- 8 files changed, 43 insertions(+), 23 deletions(-) (limited to 'src/maps') diff --git a/src/maps/hashmap.h b/src/maps/hashmap.h index 913b274..0a0535a 100644 --- a/src/maps/hashmap.h +++ b/src/maps/hashmap.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/maps/hashmap.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT *: *: Copyright (C) 2003 Paul C. Buetow, Volker Richter *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR - *: Copyright (C) 2006, 2007 Paul C. Buetow *: *: This program is free software; you can redistribute it and/or *: modify it under the terms of the GNU General Public License diff --git a/src/maps/hashmap.tmpl b/src/maps/hashmap.tmpl index cea2131..b3524b9 100644 --- a/src/maps/hashmap.tmpl +++ b/src/maps/hashmap.tmpl @@ -1,12 +1,11 @@ /*:* *: File: ./src/maps/hashmap.tmpl *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT *: *: Copyright (C) 2003 Paul C. Buetow, Volker Richter *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR - *: Copyright (C) 2006, 2007 Paul C. Buetow *: *: This program is free software; you can redistribute it and/or *: modify it under the terms of the GNU General Public License @@ -44,7 +43,7 @@ size_hash::operator()(key_type_ t_key) const int i_hash = 0; int i_size = t_key.size(); - for ( size_t i = 0; i < i_size; ++i ) + for( size_t i = 0; i < i_size; ++i ) i_hash = ( i_hash << 5 ) ^ t_key.at(i) ^ i_hash; return i_hash; diff --git a/src/maps/mtools.h b/src/maps/mtools.h index dadcdc8..5a2b6bb 100644 --- a/src/maps/mtools.h +++ b/src/maps/mtools.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/maps/mtools.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT *: *: Copyright (C) 2003 Paul C. Buetow, Volker Richter *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR - *: Copyright (C) 2006, 2007 Paul C. Buetow *: *: This program is free software; you can redistribute it and/or *: modify it under the terms of the GNU General Public License diff --git a/src/maps/mtools.tmpl b/src/maps/mtools.tmpl index 0c6b409..dff950f 100644 --- a/src/maps/mtools.tmpl +++ b/src/maps/mtools.tmpl @@ -1,12 +1,11 @@ /*:* *: File: ./src/maps/mtools.tmpl *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT *: *: Copyright (C) 2003 Paul C. Buetow, Volker Richter *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR - *: Copyright (C) 2006, 2007 Paul C. Buetow *: *: This program is free software; you can redistribute it and/or *: modify it under the terms of the GNU General Public License diff --git a/src/maps/nhashmap.h b/src/maps/nhashmap.h index fcfaf36..6443219 100644 --- a/src/maps/nhashmap.h +++ b/src/maps/nhashmap.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/maps/nhashmap.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT *: *: Copyright (C) 2003 Paul C. Buetow, Volker Richter *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR - *: Copyright (C) 2006, 2007 Paul C. Buetow *: *: This program is free software; you can redistribute it and/or *: modify it under the terms of the GNU General Public License diff --git a/src/maps/nhashmap.tmpl b/src/maps/nhashmap.tmpl index 45a40aa..c1f02ce 100644 --- a/src/maps/nhashmap.tmpl +++ b/src/maps/nhashmap.tmpl @@ -1,12 +1,11 @@ /*:* *: File: ./src/maps/nhashmap.tmpl *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT *: *: Copyright (C) 2003 Paul C. Buetow, Volker Richter *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR - *: Copyright (C) 2006, 2007 Paul C. Buetow *: *: This program is free software; you can redistribute it and/or *: modify it under the terms of the GNU General Public License diff --git a/src/maps/shashmap.h b/src/maps/shashmap.h index 8c94331..445ea77 100644 --- a/src/maps/shashmap.h +++ b/src/maps/shashmap.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/maps/shashmap.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT *: *: Copyright (C) 2003 Paul C. Buetow, Volker Richter *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR - *: Copyright (C) 2006, 2007 Paul C. Buetow *: *: This program is free software; you can redistribute it and/or *: modify it under the terms of the GNU General Public License @@ -26,6 +25,7 @@ #ifndef SHASHMAP_H #define SHASHMAP_H +#include #include "hashmap.h" #include "../monitor/dump.h" @@ -43,6 +43,7 @@ class shashmap : protected hashmap, public dumpable { private: + pthread_mutex_t mut_shashmap; protected: virtual void dumpit(); diff --git a/src/maps/shashmap.tmpl b/src/maps/shashmap.tmpl index 1613049..4e91d33 100644 --- a/src/maps/shashmap.tmpl +++ b/src/maps/shashmap.tmpl @@ -1,12 +1,11 @@ /*:* *: File: ./src/maps/shashmap.tmpl *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT *: *: Copyright (C) 2003 Paul C. Buetow, Volker Richter *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR - *: Copyright (C) 2006, 2007 Paul C. Buetow *: *: This program is free software; you can redistribute it and/or *: modify it under the terms of the GNU General Public License @@ -25,17 +24,23 @@ template shashmap::shashmap() -{} +{ + pthread_mutex_init( &mut_shashmap, NULL ); +} template shashmap::~shashmap() -{} +{ + pthread_mutex_destroy( &mut_shashmap ); +} template void shashmap::add_elem(obj_type t_obj, key_type_ t_key) { + pthread_mutex_lock( &mut_shashmap ); (*this)[t_key] = t_obj; + pthread_mutex_unlock( &mut_shashmap ); } template @@ -49,7 +54,9 @@ template obj_type shashmap::get_set_elem(obj_type t_obj, key_type_ t_key) { + pthread_mutex_lock( &mut_shashmap ); obj_type t_ret = hashmap::get_set_elem(t_obj, t_key); + pthread_mutex_unlock( &mut_shashmap ); return t_ret; } @@ -58,8 +65,10 @@ obj_type shashmap::get_or_callback_set (obj_type (*func)(void*), void* p_void, key_type_ t_key) { + pthread_mutex_lock( &mut_shashmap ); obj_type t_ret = hashmap::get_or_callback_set (func, p_void, t_key); + pthread_mutex_unlock( &mut_shashmap ); return t_ret; } @@ -67,14 +76,18 @@ template void shashmap::set_elem(obj_type t_obj, key_type_ t_key) { + pthread_mutex_lock( &mut_shashmap ); (*this)[t_key] = t_obj; + pthread_mutex_unlock( &mut_shashmap ); } template obj_type shashmap::get_elem(key_type_ t_key) { + pthread_mutex_lock( &mut_shashmap ); obj_type t_ret = hashmap::get_elem(t_key); + pthread_mutex_unlock( &mut_shashmap ); return t_ret; } @@ -82,7 +95,9 @@ template void shashmap::del_elem(key_type_ t_key) { + pthread_mutex_lock( &mut_shashmap ); hashmap::erase(t_key); + pthread_mutex_unlock( &mut_shashmap ); } template @@ -96,7 +111,9 @@ template vector* shashmap::get_key_vector() { + pthread_mutex_lock( &mut_shashmap ); vector* p_vec = hashmap::get_key_vector(); + pthread_mutex_unlock( &mut_shashmap ); return p_vec; } @@ -104,14 +121,18 @@ template void shashmap::clear() { + pthread_mutex_lock( &mut_shashmap ); hashmap::clear(); + pthread_mutex_unlock( &mut_shashmap ); } template int shashmap::size() { + pthread_mutex_lock( &mut_shashmap ); int i_size = hashmap::size(); + pthread_mutex_unlock( &mut_shashmap ); return i_size; } @@ -119,7 +140,9 @@ template bool shashmap::exists(key_type_ t_key) { + pthread_mutex_lock( &mut_shashmap ); bool b_ret = hashmap::exists(t_key); + pthread_mutex_unlock( &mut_shashmap ); return b_ret; } @@ -127,28 +150,30 @@ template void shashmap::run_func( void (*func)(obj_type) ) { + pthread_mutex_lock( &mut_shashmap ); hashmap::run_func(func); + pthread_mutex_unlock( &mut_shashmap ); } template void shashmap::run_func( void (*func)(obj_type, void*), void* v_arg ) { + pthread_mutex_lock( &mut_shashmap ); hashmap::run_func(func, v_arg); + pthread_mutex_unlock( &mut_shashmap ); } template void shashmap::dumpit() { - dumpable::add - ("[shashmap]"); + dumpable::add("[shashmap]"); vector* p_vec = get_key_vector(); typename vector::iterator iter; for (iter = p_vec->begin(); iter != p_vec->end(); ++iter) - dumpable::add - (*iter); + dumpable::add(*iter); delete p_vec; } -- cgit v1.2.3