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


Synchronize.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 SYNCHRONIZE_H
8#define SYNCHRONIZE_H
9
10#include <boost/thread/recursive_mutex.hpp>
11#include "Lucene.h"
12
13namespace Lucene {
14
16class LPPAPI Synchronize {
17public:
19 virtual ~Synchronize();
20
21protected:
22 boost::recursive_timed_mutex mutexSynchronize;
23 int64_t lockThread;
25
26public:
28 static void createSync(SynchronizePtr& sync);
29
31 void lock(int32_t timeout = 0);
32
34 void unlock();
35
37 int32_t unlockAll();
38
40 bool holdsLock();
41};
42
44class LPPAPI SyncLock {
45public:
46 SyncLock(const SynchronizePtr& sync, int32_t timeout = 0);
47
48 template <class OBJECT>
49 SyncLock(OBJECT object, int32_t timeout = 0) {
50 this->sync = object->getSync();
51 lock(timeout);
52 }
53
54 virtual ~SyncLock();
55
56protected:
58
59protected:
60 void lock(int32_t timeout);
61};
62
63}
64
65#endif
Utility class to support scope locking.
Definition: Synchronize.h:44
SyncLock(OBJECT object, int32_t timeout=0)
Definition: Synchronize.h:49
virtual ~SyncLock()
SyncLock(const SynchronizePtr &sync, int32_t timeout=0)
SynchronizePtr sync
Definition: Synchronize.h:57
void lock(int32_t timeout)
Utility class to support locking via a mutex.
Definition: Synchronize.h:16
void unlock()
Unlock mutex.
int64_t lockThread
Definition: Synchronize.h:23
static void createSync(SynchronizePtr &sync)
create a new Synchronize instance atomically.
boost::recursive_timed_mutex mutexSynchronize
Definition: Synchronize.h:22
int32_t recursionCount
Definition: Synchronize.h:24
bool holdsLock()
Returns true if mutex is currently locked by current thread.
void lock(int32_t timeout=0)
Lock mutex using an optional timeout.
virtual ~Synchronize()
int32_t unlockAll()
Unlock all recursive mutex.
Definition: AbstractAllTermDocs.h:12
boost::shared_ptr< Synchronize > SynchronizePtr
Definition: LuceneTypes.h:552

clucene.sourceforge.net