Re: [PATCH v3 09/18] perf ui: Update use of pthread mutex

From: Adrian Hunter
Date: Sat Aug 27 2022 - 03:11:42 EST


On 26/08/22 23:52, Ian Rogers wrote:
> On Fri, Aug 26, 2022 at 1:40 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>>
>> On Fri, Aug 26, 2022 at 12:21 PM Adrian Hunter <adrian.hunter@xxxxxxxxx> wrote:
>>>
>>> On 26/08/22 22:00, Namhyung Kim wrote:
>>>> On Fri, Aug 26, 2022 at 11:53 AM Adrian Hunter <adrian.hunter@xxxxxxxxx> wrote:
>>>>> Below seems adequate for now, at least logically, but maybe it
>>>>> would confuse clang thread-safety analysis?
>>>>
>>>> I think it's not just about locks, the exit_browser should bail out early
>>>> if the setup code was not called.
>>>
>>> In those cases, use_browser is 0 or -1 unless someone has inserted
>>> an invalid perf config like "tui.script=on" or "gtk.script=on".
>>> So currently, in cases where exit_browser() is called without
>>> setup_browser(), it does nothing. Which means it is only the
>>> unconditional mutex_destroy() that needs to be conditional.
>>
>> Yeah there's a possibility that it can be called with > 0 use_browser
>> on some broken config or something. So I think it's safer and better
>> for future changes.
>
> I'd thought about a:
> static bool ui__lock_initialized;
> but the issue is shouldn't it be atomic?

No, it is only accessed from the main thread.