From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 98989 invoked by alias); 18 Aug 2017 00:09:53 -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 98959 invoked by uid 89); 18 Aug 2017 00:09:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Aug 2017 00:09:50 +0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v7I09lKQ022596 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Aug 2017 00:09:48 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v7I09lGQ027519 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Aug 2017 00:09:47 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v7I09lFh003806; Fri, 18 Aug 2017 00:09:47 GMT Received: from [10.159.252.19] (/10.159.252.19) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Aug 2017 17:09:47 -0700 Subject: Re: [PATCH v6] gdb: ADI support To: Yao Qi Cc: gdb-patches@sourceware.org References: <1501885950-125523-1-git-send-email-weimin.pan@oracle.com> <86efsn1vne.fsf@gmail.com> From: Wei-min Pan Message-ID: Date: Fri, 18 Aug 2017 00:09:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <86efsn1vne.fsf@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2017-08/txt/msg00353.txt.bz2 Please review the revised patch (hopefully the final one) which has incorporated your comments in this email and was submitted on Aug 7. Thanks. On 8/7/2017 4:09 AM, Yao Qi wrote: > Weimin Pan writes: > >> +/* ADI stat settings. */ >> +typedef struct >> +{ >> + /* The ADI block size. */ >> + unsigned long blksize; >> + >> + /* Number of bits used for an ADI version tag which can be >> + * used together with the shift value for an ADI version tag >> + * to encode or extract the ADI version value in a pointer. */ >> + unsigned long nbits; >> + >> + /* The maximum ADI version tag value supported. */ >> + int max_version; >> + >> + /* ADI version tag file. */ >> + int tag_fd; > You can do in-class initialization for these fields, > > int tag_fd = 0; > >> + >> + /* ADI availability check has been done. */ >> + bool checked_avail; >> + > bool checked_avail = false; > >> + /* ADI is available. */ >> + bool is_avail; >> + >> +} adi_stat_t; > >> + >> +/* Per-process ADI stat info. */ >> + >> +typedef struct >> +{ > and add constructor, > > sparc64_adi_info (pid_t pid_) > : pid (pid_) > {} > >> + /* The process identifier. */ >> + pid_t pid; >> + >> + /* The ADI stat. */ >> + adi_stat_t stat; >> + > and in-class initialization, > > adi_stat_t state = {}; > >> +} sparc64_adi_info; >> + >> +static std::forward_list adi_proc_list; >> + >> +/* Find ADI info for process PID. */ >> + >> +static sparc64_adi_info * >> +find_adi_info (pid_t pid) >> +{ >> + for (auto &it : adi_proc_list) >> + if (it.pid == pid) >> + return &(it); >> + >> + return NULL; >> +} >> + >> +/* Add ADI info for process PID. Returns newly allocated info >> + object. */ >> + >> +static sparc64_adi_info * >> +add_adi_info (pid_t pid) >> +{ >> + sparc64_adi_info proc; >> + >> + proc.pid = pid; >> + proc.stat.is_avail = false; >> + proc.stat.checked_avail = false; >> + proc.stat.tag_fd = 0; >> + adi_proc_list.push_front (proc); >> + auto it = adi_proc_list.begin (); >> + return &(*it); >> +} >> + >> +/* Get ADI info for process PID, creating one if it doesn't exist. */ >> + >> +static sparc64_adi_info * >> +get_adi_info_proc (pid_t pid) >> +{ >> + sparc64_adi_info *proc; >> + >> + proc = find_adi_info (pid); >> + if (proc == NULL) >> + proc = add_adi_info (pid); >> + >> + return proc; > then, we can rewrite it in a simple way, > > auto found = std::find_if (adi_proc_list.begin (), adi_proc_list.end (), > [&pid] (const sparc64_adi_info &info) > { > return info.pid == pid; > }); > > if (found == adi_proc_list.end ()) > { > adi_proc_list.emplace_front (pid); > return &adi_proc_list.front (); > } > else > { > return &(*found); > } > >> +} >> + >> +static adi_stat_t >> +get_adi_info (pid_t pid) >> +{ >> + sparc64_adi_info *proc; >> + >> + proc = get_adi_info_proc (pid); >> + return proc->stat; >> +} >> +