trafficserver
trafficserver copied to clipboard
Use std::unique_ptr to replace "scoped" classes like ats_scope_fd and the MutexLock classes
Now that we have committed to c++11, we can replace our own scoped logic with std::unique_ptr.
This can be done by overriding / supplying a deleter for std::unique_ptr. I think we will probably want to keep our classes for this but change the underlying implementation to be based on std::unique_ptr with just a shim to set the deleter appropriately.
I’m considering working on this.
I noticed ats_scoped_str is almost like std::string.
What is the intention for this class?
Hello, I would like to work on this and replace the scoped logic with std::unique_ptr. Can this be assigned to me?
@Mouray-Hutchinson are you still interested in working on this? What's your background in software development?
@shinrich is this issue resolved? If not, I would like to contribute to it!!
As I remember, I did some work to clean this up. But there were still some custom guard classes that seemed to make sense to keep.
As I remember, I did some work to clean this up. But there were still some custom guard classes that seemed to make sense to keep.
Sure, I can help you with that. Can you show me the code with the custom guard classes that you want to keep?
@ShaiviAgarwal2 I suggest you don' t assume the custom scoped classes are useless. You can first evaluate whether there is any advantage to having/using them.
I did this quick search in the code:
wkaras ~/REPOS/TS
O$ grep -i -e 'class.*scope' -e 'struct.*scope' $(findsrc)
./include/tscore/ink_mutex.h:class ink_scoped_mutex_lock
./include/tscore/ink_memory.h: An instance of this class is used to hold a contingent resource. When this object goes out of scope
./include/tscore/ink_memory.h:class ats_scoped_resource
./include/tscore/ink_memory.h:struct SCOPED_FD_TRAITS {
./include/tscore/ink_memory.h:class ats_scoped_fd : public ats_scoped_resource<detail::SCOPED_FD_TRAITS>
./include/tscore/ink_memory.h:struct SCOPED_MALLOC_TRAITS {
./include/tscore/ink_memory.h:struct SCOPED_OBJECT_TRAITS {
./include/tscore/ink_memory.h:class ats_scoped_str : public ats_scoped_resource<detail::SCOPED_MALLOC_TRAITS<char>>
./include/tscore/ink_memory.h:class ats_scoped_mem : public ats_scoped_resource<detail::SCOPED_MALLOC_TRAITS<T>>
./include/api/InkAPIInternal.h: struct Scope {
./include/iocore/eventsystem/ConfigProcessor.h: template <typename ClassType, typename ConfigType> struct scoped_config {
./include/proxy/hdrs/HdrHeap.h: while the instance of this class exists. When it goes out of scope
./lib/yamlcpp/src/emitterstate.h:struct FmtScope {
./lib/swoc/include/swoc/MemSpan.h: * invalid in class scope and this needs to be specialized for @c void.
./lib/catch2/catch.hpp: class ScopedMessage {
./lib/catch2/catch.hpp: class ScopedElement {
./plugins/experimental/access_control/config.h: Classifier _uriPathScope; /**< @brief denylist (exclude) and allow-list (include) which path should have the access control */
./plugins/experimental/stream_editor/stream_editor.cc:class scope_t
./plugins/experimental/stream_editor/stream_editor.cc:class rxscope : public scope_t
./plugins/experimental/stream_editor/stream_editor.cc:class strscope : public scope_t
./src/records/RecYAMLDecoder.cc:struct scoped_cond_lock {
./src/iocore/cache/P_CacheHosting.h: class ScopedReader
./src/iocore/cache/P_CacheHosting.h: class ScopedWriter
./src/iocore/cache/P_CacheHosting.h: friend class ReplaceablePtr::ScopedReader;
./src/mgmt/rpc/server/unit_tests/test_rpcserver.cc:struct ScopedLocalSocket : shared::rpc::IPCSocketClient {
./src/proxy/logging/Log.cc: class scope and static members provide a protected namespace for all of
wkaras ~/REPOS/TS
O$
@ywkaras Upon researching, I found that there are several custom-scoped classes that are being used in the code you provided.
Here are a few of them:
ink_scoped_mutex_lock in ink_mutex.h
ats_scoped_resource in ink_memory.h
ats_scoped_fd in ink_memory.h
ats_scoped_str in ink_memory.h
ats_scoped_mem in ink_memory.h
These classes are used to manage resources and provide automatic cleanup when they go out of scope. You can evaluate whether these classes are useful for your specific use case or if you can replace them with std::unique_ptr.
OK I'll try to evaluate those, but I'm not sure when I'll have time.
OK I'll try to evaluate those, but I'm not sure when I'll have time.
Of course, take your time. Let me know if you have any questions or if there's anything else I can assist you with.
@shinrich I would like to contribute to this project, could you please assign this task to me?
@shinrich Any update on the development of the issue?
@shinrich Any update on the development of the issue?
Susan will busy for a while with personal matters. You can submit a PR related to this issue without it being assigned to you. It would probably be best for you to describe, with as much detail as possible, your design, before you write any code. In order not to risk doing any wasted work. You should send the design in a e-mail in the dev mailing list.