]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/cleanable.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
5 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style license that can be
7 // found in the LICENSE file. See the AUTHORS file for names of contributors.
9 // An iterator yields a sequence of key/value pairs from a source.
10 // The following class defines the interface. Multiple implementations
11 // are provided by this library. In particular, iterators are provided
12 // to access the contents of a Table or a DB.
14 // Multiple threads can invoke const methods on an Iterator without
15 // external synchronization, but if any of the threads may call a
16 // non-const method, all threads accessing the same Iterator must use
17 // external synchronization.
19 #ifndef INCLUDE_ROCKSDB_CLEANABLE_H_
20 #define INCLUDE_ROCKSDB_CLEANABLE_H_
28 // Clients are allowed to register function/arg1/arg2 triples that
29 // will be invoked when this iterator is destroyed.
31 // Note that unlike all of the preceding methods, this method is
32 // not abstract and therefore clients should not override it.
33 typedef void (*CleanupFunction
)(void* arg1
, void* arg2
);
34 void RegisterCleanup(CleanupFunction function
, void* arg1
, void* arg2
);
35 void DelegateCleanupsTo(Cleanable
* other
);
36 // DoCkeanup and also resets the pointers for reuse
39 cleanup_
.function
= nullptr;
40 cleanup_
.next
= nullptr;
45 CleanupFunction function
;
51 // It also becomes the owner of c
52 void RegisterCleanup(Cleanup
* c
);
55 // Performs all the cleanups. It does not reset the pointers. Making it
58 inline void DoCleanup() {
59 if (cleanup_
.function
!= nullptr) {
60 (*cleanup_
.function
)(cleanup_
.arg1
, cleanup_
.arg2
);
61 for (Cleanup
* c
= cleanup_
.next
; c
!= nullptr;) {
62 (*c
->function
)(c
->arg1
, c
->arg2
);
63 Cleanup
* next
= c
->next
;
71 } // namespace rocksdb
73 #endif // INCLUDE_ROCKSDB_CLEANABLE_H_