Lucene++ - a full-featured, c++ search engine
API Documentation


Loading...
Searching...
No Matches
CloseableThreadLocal.h
Go to the documentation of this file.
1
2// Copyright (c) 2009-2014 Alan Wright. All rights reserved.
3// Distributable under the terms of either the Apache License (Version 2.0)
4// or the GNU Lesser General Public License.
6
7#ifndef CLOSEABLETHREADLOCAL_H
8#define CLOSEABLETHREADLOCAL_H
9
10#include "LuceneThread.h"
11
12namespace Lucene {
13
15template <typename TYPE>
17public:
18 typedef boost::shared_ptr<TYPE> localDataPtr;
20
24
25public:
27 SyncLock syncLock(this);
29 if (local != localData.end()) {
30 return local->second;
31 }
32 localDataPtr initial(initialValue());
33 if (initial) {
35 }
36 return initial;
37 }
38
39 void set(const localDataPtr& data) {
40 SyncLock syncLock(this);
42 }
43
44 void close() {
45 SyncLock syncLock(this);
47 }
48
49protected:
51
53 return localDataPtr(); // override
54 }
55};
56
57}
58
59#endif
General purpose thread-local map.
Definition CloseableThreadLocal.h:16
virtual localDataPtr initialValue()
Definition CloseableThreadLocal.h:52
Map< int64_t, localDataPtr > MapLocalData
Definition CloseableThreadLocal.h:19
MapLocalData localData
Definition CloseableThreadLocal.h:50
boost::shared_ptr< TYPE > localDataPtr
Definition CloseableThreadLocal.h:18
CloseableThreadLocal()
Definition CloseableThreadLocal.h:21
void close()
Definition CloseableThreadLocal.h:44
localDataPtr get()
Definition CloseableThreadLocal.h:26
void set(const localDataPtr &data)
Definition CloseableThreadLocal.h:39
Base class for all Lucene classes.
Definition LuceneObject.h:31
static int64_t currentId()
Return representation of current execution thread.
Utility template class to handle maps that can be safely copied and shared.
Definition Map.h:17
void remove(ITER pos)
Definition Map.h:97
iterator end()
Definition Map.h:60
void put(const KEY &key, const VALUE &value)
Definition Map.h:85
static this_type newInstance()
Definition Map.h:34
map_type::iterator iterator
Definition Map.h:22
iterator find(const KEY &key)
Definition Map.h:110
Utility class to support scope locking.
Definition Synchronize.h:46
Definition AbstractAllTermDocs.h:12

clucene.sourceforge.net