1 #include <graphlab/util/lock_free_pool.hpp>
2 #include <graphlab/rpc/dc_compile_parameters.hpp>
8 pthread_key_t thlocalkey;
9 typedef std::pair<oarchive, bool> thlocal_type;
10 static void pth_deleter(
void* p) {
12 thlocal_type* arc = (thlocal_type*)(p);
13 if (arc->first.buf) free(arc->first.buf);
18 pthread_key_create(&thlocalkey, &pth_deleter);
22 pthread_key_delete(thlocalkey);
26 static pool_manager pool;
28 oarchive* oarchive_from_pool() {
29 void* ptr = pthread_getspecific(pool.thlocalkey);
30 pool_manager::thlocal_type* p = (pool_manager::thlocal_type*)(ptr);
32 p =
new pool_manager::thlocal_type;
37 pthread_setspecific(pool.thlocalkey, (
void*)p);
39 if (p->second)
return new oarchive;
44 void release_oarchive_to_pool(oarchive* oarc) {
45 void* ptr = pthread_getspecific(pool.thlocalkey);
46 pool_manager::thlocal_type* p = (pool_manager::thlocal_type*)(ptr);
47 if ((p != NULL) && &(p->first) == oarc) {
51 if (oarc->buf) free(oarc->buf);