From: Ammar Nofan Faizi <[email protected]>
To: Alviro Iskandar Setiawan <[email protected]>
Cc: Ammar Faizi <[email protected]>,
Muhammad Rizki <[email protected]>,
Kanna Scarlet <[email protected]>,
GNU/Weeb Mailing List <[email protected]>
Subject: Re: [RFC PATCH v1 2/2] chnet: Implement `get_thread()` and `put_thread()` function
Date: Mon, 29 Aug 2022 12:48:31 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAOG64qOCpyGwGv2TwV5yTnsPk7Hvv-O_mh+1bnu2VPAoPAZsVg@mail.gmail.com>
On 8/29/22 12:38 PM, Alviro Iskandar Setiawan wrote:
> On Mon, Aug 29, 2022 at 12:29 PM Ammar Nofan Faizi wrote:
>> On 8/29/22 12:24 PM, Alviro Iskandar Setiawan wrote:
>>> On Mon, Aug 29, 2022 at 12:17 PM Alviro Iskandar Setiawan wrote:
>>>> On Mon, Aug 29, 2022 at 11:54 AM Ammar Nofan Faizi wrote:
>>>>> On 8/29/22 11:41 AM, Alviro Iskandar Setiawan wrote:
>>>>>> On Mon, Aug 29, 2022 at 8:11 AM Ammar Faizi wrote:
>>>>>>> +static base::Thread *get_thread(void)
>>>>>>> +{
>>>>>>> + const uint32_t max_ch_thpool = g_max_ch_thpool;
>>>>>>> + const uint32_t nr_ref_split = 2048;
>>>>>>> + struct ch_thpool **thp;
>>>>>>> + struct ch_thpool *ret = nullptr;
>>>>>>> + struct ch_thpool *tmp;
>>>>>>> + uint32_t min_ref_idx;
>>>>>>> + uint32_t min_ref;
>>>>>>> + uint32_t i;
>>>>>>> +
>>>>>>> + g_thpool_lock_.lock();
>>>>>>> + thp = g_thpool;
>>>>>>> + if (!thp) {
>>>>>>> + g_thpool_lock_.unlock();
>>>>>>> + return nullptr;
>>>>>>> + }
>>>>>>
>>>>>> in what situation @thp can be nullptr?
>>>>>
>>>>> When the chnet_global_destroy() is called.
>>>
>>> btw, i missed a case on the chnet construction, you do
>>>
>>> thread_(*get_thread()),
>>>
>>> if get_thread() returns a nullptr, the @thread_ will become a
>>> reference to a nullptr, it will definitely break, how do you handle
>>> this?
>>
>> I don't think we need to handle that. If @thp ever be a nullptr in a
>> get_thread() call, then it's a misuse of the API. We must never call
>> get_thread() after chnet_global_destroy() is called. It doesn't make
>> much sense to have this situation.
>
> if this should never happen, then why do you do a null check there?
> your null check doesn't make much sense too! why are we returning
> nullptr if we exactly know that the caller will randomly fault if that
> happens, i can't accept your reasoning
OK.
Fine, let's omit that nullptr return. To assert that path, we perform a
CHECK() assertion, so it will just crash the whole program with a full
call traces if the contract is violated. This way also makes debugging
process easier. Are you happy with this change?
Incremental is:
diff --git a/chnet/chnet.cc b/chnet/chnet.cc
index 782e4fe..fc536d2 100644
--- a/chnet/chnet.cc
+++ b/chnet/chnet.cc
@@ -647,10 +647,7 @@ static base::Thread *get_thread(void)
g_thpool_lock_.lock();
thp = g_thpool;
- if (!thp) {
- g_thpool_lock_.unlock();
- return nullptr;
- }
+ CHECK(thp);
tmp = thp[0];
if (!tmp) {
--
Ammar Faizi
next prev parent reply other threads:[~2022-08-29 5:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-29 1:11 [RFC PATCH v1 0/2] Fixed number of chromium workers Ammar Faizi
2022-08-29 1:11 ` [RFC PATCH v1 1/2] chnet: Prepare global struct ch_thpool array Ammar Faizi
2022-08-29 4:21 ` Alviro Iskandar Setiawan
2022-08-29 4:47 ` Ammar Nofan Faizi
2022-08-29 1:11 ` [RFC PATCH v1 2/2] chnet: Implement `get_thread()` and `put_thread()` function Ammar Faizi
2022-08-29 4:41 ` Alviro Iskandar Setiawan
2022-08-29 4:54 ` Ammar Nofan Faizi
2022-08-29 5:17 ` Alviro Iskandar Setiawan
2022-08-29 5:24 ` Alviro Iskandar Setiawan
2022-08-29 5:29 ` Ammar Nofan Faizi
2022-08-29 5:38 ` Alviro Iskandar Setiawan
2022-08-29 5:48 ` Ammar Nofan Faizi [this message]
2022-08-29 6:01 ` Alviro Iskandar Setiawan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox