From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 109209 invoked by alias); 7 Jun 2018 18:28:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 109149 invoked by uid 89); 7 Jun 2018 18:28:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Related, wondered, handy X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.188.18) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Jun 2018 18:28:17 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 12379400C7828 for ; Thu, 7 Jun 2018 13:28:16 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id Qzdwfe4ujkBj6Qzdwf7RrV; Thu, 07 Jun 2018 13:28:16 -0500 X-Authority-Reason: nr=8 Received: from 75-166-19-45.hlrn.qwest.net ([75.166.19.45]:40396 helo=pokyo) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fQzdv-000phU-Qw; Thu, 07 Jun 2018 13:28:15 -0500 From: Tom Tromey To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Use thread_info and inferior pointers more throughout References: <20180607180704.3991-1-palves@redhat.com> Date: Thu, 07 Jun 2018 18:28:00 -0000 In-Reply-To: <20180607180704.3991-1-palves@redhat.com> (Pedro Alves's message of "Thu, 7 Jun 2018 19:07:04 +0100") Message-ID: <87tvqeladc.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fQzdv-000phU-Qw X-Source-Sender: 75-166-19-45.hlrn.qwest.net (pokyo) [75.166.19.45]:40396 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2018-06/txt/msg00180.txt.bz2 >>>>> "Pedro" == Pedro Alves writes: Pedro> In many cases though, we already have the thread_info or inferior Pedro> pointer handy, but we "lose" it somewhere along the call stack, only Pedro> to look it up again by ptid_t/pid. Since thread_info or inferior Pedro> objects know their parent target, if we pass around thread_info or Pedro> inferior pointers when possible, we avoid having to add extra Pedro> target_ops parameters to many functions, and also, we eliminate a Pedro> number of by ptid_t/int lookups. This seems like a good idea. I've sometimes wondered why ptid was used rather than object pointers; but now it seems that there was no deep reason :) Pedro> - Related, there's a spot where using a RAII object to handle the Pedro> refcount would be handy, so a new scoped_inc_dec_ref class is added Pedro> to common/refcounted-object.h. It seems to me that this could be done via gdb::ref_ptr plus a simple policy class that interfaces it to refcounted_object. Pedro> +/* A RAII type that increments/decrements the refcount of an object on Pedro> + enter/exit of a scope. */ Pedro> + Pedro> +class scoped_inc_dec_ref Pedro> +{ Pedro> +public: Pedro> + explicit scoped_inc_dec_ref (refcounted_object *obj) Pedro> + : m_obj (obj) Pedro> + { Pedro> + m_obj->incref (); Pedro> + } Pedro> + Pedro> + ~scoped_inc_dec_ref () Pedro> + { Pedro> + m_obj->decref (); Pedro> + } ... if you do keep this it probably needs DISABLE_COPY_AND_ASSIGN. Tom