GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
delta_dht.cpp
1 /**
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 /**
25  * Also contains code that is Copyright 2011 Yahoo! Inc. All rights
26  * reserved.
27  *
28  * Contributed under the iCLA for:
29  * Joseph Gonzalez ([email protected])
30  *
31  */
32 
33 
34 #include <boost/unordered_map.hpp>
35 #include <graphlab/rpc/delta_dht.hpp>
36 
37 
38 #include <graphlab/macros_def.hpp>
39 namespace graphlab {
40  namespace delta_dht_impl {
41 
42  typedef boost::unordered_map<const void*, icache*> cache_map_type;
43 
44  void destroy_tls_data(void* ptr) {
45  cache_map_type* cache_map_ptr = static_cast<cache_map_type*>(ptr);
46  if(cache_map_ptr != NULL) {
47  cache_map_type& cache_map = *cache_map_ptr;
48  typedef cache_map_type::value_type pair_type;
49  foreach(pair_type& pair, cache_map) {
50  if(pair.second != NULL) {
51  delete pair.second;
52  pair.second = NULL;
53  }
54  }
55  delete cache_map_ptr;
56  }
57  }
58  struct tls_key_creator {
59  pthread_key_t TLS_KEY;
60  tls_key_creator() : TLS_KEY(0) {
61  pthread_key_create(&TLS_KEY, destroy_tls_data);
62  }
63  };
64  const tls_key_creator key;
65 
66  icache*& get_icache_ptr(const void* dht_ptr) {
67  cache_map_type* cache_map_ptr = static_cast<cache_map_type*>
68  (pthread_getspecific(key.TLS_KEY));
69  if(cache_map_ptr == NULL) {
70  cache_map_ptr = new cache_map_type();
71  pthread_setspecific(key.TLS_KEY, cache_map_ptr);
72  }
73  ASSERT_NE(cache_map_ptr, NULL);
74  ASSERT_NE(dht_ptr, NULL);
75  return (*cache_map_ptr)[dht_ptr];
76  }
77 
78 
79 
80 
81  }; // end of delta dht impl
82 }; // end of graphlab namespace
83 
84 
85 
86 
87 
88 
89 
90 
91