Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/tscore/ink_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ static const ink_freelist_ops *default_ops = &freelist_ops;
static ink_freelist_list *freelists = nullptr;
static const ink_freelist_ops *freelist_global_ops = default_ops;

inline void
dummy_forced_read(void *mem)
{
static_cast<void>(*const_cast<int volatile *>(reinterpret_cast<int *>(mem)));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use [[maybe_unused]] instead of static_cast<void>()?

Also, you can static_cast to int * because it's a void *.

Finally, force_read might be a better name. There's no longer a dummy variable involved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer code that's less rather than more obscure. In any case, seems misleading to say something is maybe unused when it's definitely unused.

We should never miss a chance to use a static_cast apparently.

It's dummy in the sense that we are reading a memory location as some sort of fragile, ratchet, half-assed memory fence, rather than to read the value of a memory location. Instead of using the more portable code I wrote to replace this mess.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[[maybe_unused]] is the official replacement in C++17 for casting to void to avoid discarding computation due to optimization.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cppreference.com as much as I does not seem to have gotten the memo you got about [[maybe_unused]]: https://en.cppreference.com/w/cpp/language/attributes/maybe_unused

}

const InkFreeListOps *
ink_freelist_malloc_ops()
{
Expand Down Expand Up @@ -184,10 +190,6 @@ ink_freelist_create(const char *name, uint32_t type_size, uint32_t chunk_size, u

#define ADDRESS_OF_NEXT(x, offset) ((void **)((char *)x + offset))

#ifdef SANITY
int fake_global_for_ink_queue = 0;
#endif

void *
ink_freelist_new(InkFreeList *f)
{
Expand Down Expand Up @@ -260,7 +262,7 @@ freelist_new(InkFreeList *f)
ink_abort("ink_freelist_new: bad list");
}
if (TO_PTR(FREELIST_POINTER(next))) {
fake_global_for_ink_queue = *static_cast<int *>(TO_PTR(FREELIST_POINTER(next)));
dummy_forced_read(TO_PTR(FREELIST_POINTER(next)));
}
}
#endif /* SANITY */
Expand Down Expand Up @@ -326,7 +328,7 @@ freelist_free(InkFreeList *f, void *item)
ink_abort("ink_freelist_free: bad list");
}
if (TO_PTR(FREELIST_POINTER(h))) {
fake_global_for_ink_queue = *static_cast<int *>(TO_PTR(FREELIST_POINTER(h)));
dummy_forced_read(TO_PTR(FREELIST_POINTER(h)));
}
#endif /* SANITY */
*adr_of_next = FREELIST_POINTER(h);
Expand Down Expand Up @@ -391,7 +393,7 @@ freelist_bulkfree(InkFreeList *f, void *head, void *tail, size_t num_item)
ink_abort("ink_freelist_free: bad list");
}
if (TO_PTR(FREELIST_POINTER(h))) {
fake_global_for_ink_queue = *static_cast<int *>(TO_PTR(FREELIST_POINTER(h)));
dummy_forced_read(TO_PTR(FREELIST_POINTER(h)));
}
#endif /* SANITY */
*adr_of_next = FREELIST_POINTER(h);
Expand Down