]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/crypto/CryptoContextPool.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "librbd/crypto/CryptoContextPool.h"
10 CryptoContextPool
<T
>::CryptoContextPool(DataCryptor
<T
>* data_cryptor
,
12 : m_data_cryptor(data_cryptor
), m_encrypt_contexts(pool_size
),
13 m_decrypt_contexts(pool_size
) {
17 CryptoContextPool
<T
>::~CryptoContextPool() {
19 while (m_encrypt_contexts
.pop(ctx
)) {
20 m_data_cryptor
->return_context(ctx
, CipherMode::CIPHER_MODE_ENC
);
22 while (m_decrypt_contexts
.pop(ctx
)) {
23 m_data_cryptor
->return_context(ctx
, CipherMode::CIPHER_MODE_DEC
);
28 T
* CryptoContextPool
<T
>::get_context(CipherMode mode
) {
30 if (!get_contexts(mode
).pop(ctx
)) {
31 ctx
= m_data_cryptor
->get_context(mode
);
37 void CryptoContextPool
<T
>::return_context(T
* ctx
, CipherMode mode
) {
38 if (!get_contexts(mode
).push(ctx
)) {
39 m_data_cryptor
->return_context(ctx
, mode
);