mirror of https://github.com/trapexit/mergerfs.git
14 changed files with 376 additions and 307 deletions
-
2libfuse/include/fuse.h
-
18libfuse/include/fuse_common.h
-
12libfuse/include/fuse_conn_info.hpp
-
4libfuse/include/fuse_lowlevel.h
-
2libfuse/include/fuse_pollhandle.h
-
7libfuse/include/fuse_req.hpp
-
136libfuse/include/objpool.hpp
-
31libfuse/lib/fuse.cpp
-
18libfuse/lib/fuse_i.h
-
1libfuse/lib/fuse_loop.cpp
-
420libfuse/lib/fuse_lowlevel.cpp
-
18libfuse/lib/fuse_req.cpp
-
12src/fuse_init.cpp
-
2src/fuse_init.hpp
@ -0,0 +1,12 @@ |
|||||
|
#pragma once
|
||||
|
|
||||
|
#include "base_types.h"
|
||||
|
|
||||
|
typedef struct fuse_conn_info_t fuse_conn_info_t; |
||||
|
struct fuse_conn_info_t |
||||
|
{ |
||||
|
u32 proto_major; |
||||
|
u32 proto_minor; |
||||
|
u64 capable; |
||||
|
u64 want; |
||||
|
}; |
||||
@ -1,15 +1,18 @@ |
|||||
#pragma once
|
#pragma once
|
||||
|
|
||||
#include "fuse_req_ctx.h"
|
#include "fuse_req_ctx.h"
|
||||
|
#include "fuse_conn_info.hpp"
|
||||
|
|
||||
struct fuse_ll; |
|
||||
struct fuse_chan; |
struct fuse_chan; |
||||
|
|
||||
typedef struct fuse_req_t fuse_req_t; |
typedef struct fuse_req_t fuse_req_t; |
||||
struct fuse_req_t |
struct fuse_req_t |
||||
{ |
{ |
||||
fuse_req_ctx_t ctx; |
fuse_req_ctx_t ctx; |
||||
struct fuse_ll *f; |
|
||||
struct fuse_chan *ch; |
struct fuse_chan *ch; |
||||
|
fuse_conn_info_t conn; |
||||
unsigned int ioctl_64bit : 1; |
unsigned int ioctl_64bit : 1; |
||||
}; |
}; |
||||
|
|
||||
|
fuse_req_t* fuse_req_alloc(); |
||||
|
void fuse_req_free(fuse_req_t*); |
||||
@ -0,0 +1,136 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Permission to use, copy, modify, and/or distribute this software for any |
||||
|
purpose with or without fee is hereby granted, provided that the above |
||||
|
copyright notice and this permission notice appear in all copies. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
||||
|
*/ |
||||
|
|
||||
|
#pragma once
|
||||
|
|
||||
|
#include <mutex>
|
||||
|
#include <new>
|
||||
|
#include <utility>
|
||||
|
#include <type_traits>
|
||||
|
|
||||
|
template<typename T> |
||||
|
class ObjPool |
||||
|
{ |
||||
|
private: |
||||
|
struct alignas(alignof(T)) Node |
||||
|
{ |
||||
|
Node *next; |
||||
|
}; |
||||
|
|
||||
|
private: |
||||
|
static_assert(sizeof(T) >= sizeof(Node), "T must be at least pointer-sized"); |
||||
|
static_assert(std::is_nothrow_destructible_v<T>, "T must be nothrow destructible"); |
||||
|
|
||||
|
private: |
||||
|
static |
||||
|
Node* |
||||
|
to_node(T *obj_) |
||||
|
{ |
||||
|
return reinterpret_cast<Node*>(obj_); |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
std::mutex _mtx; |
||||
|
Node *_head = nullptr; |
||||
|
|
||||
|
public: |
||||
|
ObjPool() = default; |
||||
|
ObjPool(const ObjPool&) = delete; |
||||
|
ObjPool& operator=(const ObjPool&) = delete; |
||||
|
ObjPool(ObjPool&&) = delete; |
||||
|
ObjPool& operator=(ObjPool&&) = delete; |
||||
|
|
||||
|
~ObjPool() |
||||
|
{ |
||||
|
clear(); |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
Node* |
||||
|
_pop_node() |
||||
|
{ |
||||
|
std::lock_guard<std::mutex> lock(_mtx); |
||||
|
|
||||
|
Node *node = _head; |
||||
|
if(node) |
||||
|
_head = node->next; |
||||
|
|
||||
|
return node; |
||||
|
} |
||||
|
|
||||
|
void |
||||
|
_push_node(Node *node_) |
||||
|
{ |
||||
|
std::lock_guard<std::mutex> lock(_mtx); |
||||
|
|
||||
|
node_->next = _head; |
||||
|
_head = node_; |
||||
|
} |
||||
|
|
||||
|
public: |
||||
|
void |
||||
|
clear() noexcept |
||||
|
{ |
||||
|
Node *head; |
||||
|
|
||||
|
{ |
||||
|
std::lock_guard<std::mutex> lock(_mtx); |
||||
|
head = _head; |
||||
|
_head = nullptr; |
||||
|
} |
||||
|
|
||||
|
while(head) |
||||
|
{ |
||||
|
Node *next = head->next; |
||||
|
::operator delete(head, std::align_val_t{alignof(T)}); |
||||
|
head = next; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
template<typename... Args> |
||||
|
T* |
||||
|
alloc(Args&&... args_) |
||||
|
{ |
||||
|
void *mem; |
||||
|
Node *node; |
||||
|
|
||||
|
node = _pop_node(); |
||||
|
mem = (node ? |
||||
|
static_cast<void*>(node) : |
||||
|
::operator new(sizeof(T), std::align_val_t{alignof(T)})); |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
return new(mem) T(std::forward<Args>(args_)...); |
||||
|
} |
||||
|
catch(...) |
||||
|
{ |
||||
|
_push_node(static_cast<Node*>(mem)); |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void |
||||
|
free(T *obj_) noexcept |
||||
|
{ |
||||
|
if(not obj_) |
||||
|
return; |
||||
|
|
||||
|
obj_->~T(); |
||||
|
|
||||
|
_push_node(to_node(obj_)); |
||||
|
} |
||||
|
}; |
||||
420
libfuse/lib/fuse_lowlevel.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,18 @@ |
|||||
|
#include "fuse_req.hpp"
|
||||
|
|
||||
|
#include "objpool.hpp"
|
||||
|
|
||||
|
|
||||
|
static ObjPool<fuse_req_t> g_pool; |
||||
|
|
||||
|
fuse_req_t* |
||||
|
fuse_req_alloc() |
||||
|
{ |
||||
|
return g_pool.alloc(); |
||||
|
} |
||||
|
|
||||
|
void |
||||
|
fuse_req_free(fuse_req_t *req_) |
||||
|
{ |
||||
|
return g_pool.free(req_); |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue