]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/utilities/transactions/lock/range/range_tree/lib/portability/toku_external_pthread.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / utilities / transactions / lock / range / range_tree / lib / portability / toku_external_pthread.h
CommitLineData
1e59de90
TL
1/*
2 A wrapper around ROCKSDB_NAMESPACE::TransactionDBMutexFactory-provided
3 condition and mutex that provides toku_pthread_*-like interface. The functions
4 are named
5
6 toku_external_{mutex|cond}_XXX
7
8 Lock Tree uses this mutex and condition for interruptible (long) lock waits.
9
10 (It also still uses toku_pthread_XXX calls for mutexes/conditions for
11 shorter waits on internal objects)
12*/
13
14#pragma once
15
16#include <pthread.h>
17#include <stdint.h>
18#include <time.h>
19
20#include "rocksdb/utilities/transaction_db.h"
21#include "rocksdb/utilities/transaction_db_mutex.h"
22#include "toku_portability.h"
23
24using ROCKSDB_NAMESPACE::TransactionDBCondVar;
25using ROCKSDB_NAMESPACE::TransactionDBMutex;
26
27typedef std::shared_ptr<ROCKSDB_NAMESPACE::TransactionDBMutexFactory>
28 toku_external_mutex_factory_t;
29
30typedef std::shared_ptr<TransactionDBMutex> toku_external_mutex_t;
31typedef std::shared_ptr<TransactionDBCondVar> toku_external_cond_t;
32
33static inline void toku_external_cond_init(
34 toku_external_mutex_factory_t mutex_factory, toku_external_cond_t *cond) {
35 *cond = mutex_factory->AllocateCondVar();
36}
37
38inline void toku_external_cond_destroy(toku_external_cond_t *cond) {
39 cond->reset(); // this will destroy the managed object
40}
41
42inline void toku_external_cond_signal(toku_external_cond_t *cond) {
43 (*cond)->Notify();
44}
45
46inline void toku_external_cond_broadcast(toku_external_cond_t *cond) {
47 (*cond)->NotifyAll();
48}
49
50inline int toku_external_cond_timedwait(toku_external_cond_t *cond,
51 toku_external_mutex_t *mutex,
52 int64_t timeout_microsec) {
53 auto res = (*cond)->WaitFor(*mutex, timeout_microsec);
54 if (res.ok())
55 return 0;
56 else
57 return ETIMEDOUT;
58}
59
60inline void toku_external_mutex_init(toku_external_mutex_factory_t factory,
61 toku_external_mutex_t *mutex) {
62 // Use placement new: the memory has been allocated but constructor wasn't
63 // called
64 new (mutex) toku_external_mutex_t;
65 *mutex = factory->AllocateMutex();
66}
67
68inline void toku_external_mutex_lock(toku_external_mutex_t *mutex) {
69 (*mutex)->Lock();
70}
71
72inline int toku_external_mutex_trylock(toku_external_mutex_t *mutex) {
73 (*mutex)->Lock();
74 return 0;
75}
76
77inline void toku_external_mutex_unlock(toku_external_mutex_t *mutex) {
78 (*mutex)->UnLock();
79}
80
81inline void toku_external_mutex_destroy(toku_external_mutex_t *mutex) {
82 mutex->reset(); // this will destroy the managed object
83}