From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Gerd_M=C3=B6llmann?= Newsgroups: gmane.emacs.devel Subject: Re: igc, macOS avoiding signals Date: Tue, 31 Dec 2024 10:51:57 +0100 Message-ID: References: <799DDBC5-2C14-4476-B1E0-7BA2FE9E7901@toadstyle.org> <87h66loc17.fsf@gmail.com> <878qrxoayj.fsf@gmail.com> <8734i5o6wc.fsf@gmail.com> <87cyh9mpn5.fsf@gmail.com> <874j2l1hei.fsf@protonmail.com> <874j2lmd37.fsf@gmail.com> <87msgdkt29.fsf@gmail.com> <86h66lnjrt.fsf@gnu.org> <868qrxnfrw.fsf@gnu.org> <87a5ccl2zx.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38256"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , pipcet@protonmail.com, spd@toadstyle.org, emacs-devel@gnu.org To: Helmut Eller Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Dec 31 10:52:15 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tSYv7-0009mJ-W2 for ged-emacs-devel@m.gmane-mx.org; Tue, 31 Dec 2024 10:52:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tSYv1-0002lK-Of; Tue, 31 Dec 2024 04:52:07 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tSYuz-0002j6-Rc for emacs-devel@gnu.org; Tue, 31 Dec 2024 04:52:05 -0500 Original-Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tSYuw-0002GZ-Uu; Tue, 31 Dec 2024 04:52:05 -0500 Original-Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-aa68b513abcso1858972766b.0; Tue, 31 Dec 2024 01:52:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735638719; x=1736243519; darn=gnu.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=25R4KIpa5jErlE5HEpSqlEJLdZIfyqUjrzdzE2ewD9k=; b=LfSxVydjXZBykdffcyrurOXcynS1pzaVxFkB5itLRcnCScg1MlEc183NzWNzocV3Gq kqP84n2OvDjGma/YFLW+oUZ6/yuD/ZW2qWD3at0kiP3ZL01o3nM0EyRlAOttVCAEvUFv RTjBAqU4ZBgeTluVl1jEPxZAYdRIzHuDMwOaoNIqZ6RQ89qo2ySektWB2v9oknls/64b XToZwda3tRlWv4XNYAaIlqM1kmqF8r7aFI+CuGkCfGJGf8AojS472nlHniADXw7ZPgsB 2lvdZgtOnBpS3AT4xbUZQpo5ICvUYGmMDfQ+4EK/Os08OHtop4ab7XutA6p87uIwbavz SE0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735638719; x=1736243519; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=25R4KIpa5jErlE5HEpSqlEJLdZIfyqUjrzdzE2ewD9k=; b=kJedAONdNuT/l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:b0:aa6:94c0:f753 with SMTP id a640c23a62f3a-aac2d467fd1mr3122188866b.33.1735638718984; Tue, 31 Dec 2024 01:51:58 -0800 (PST) Original-Received: from pro2 (p200300e0b7216c0021e5e367c6afc189.dip0.t-ipconnect.de. [2003:e0:b721:6c00:21e5:e367:c6af:c189]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0f015ae1sm1561020466b.147.2024.12.31.01.51.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2024 01:51:58 -0800 (PST) In-Reply-To: ("Gerd =?utf-8?Q?M=C3=B6llmann=22'?= =?utf-8?Q?s?= message of "Tue, 31 Dec 2024 10:19:15 +0100") Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=gerd.moellmann@gmail.com; helo=mail-ej1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:327486 Archived-At: Gerd M=C3=B6llmann writes: > Hm. Have you perhaps looked at a pthread implementation, what such a > mutex actually is on Linux? Unless I got lost in Apple's sources, trylock on macOS is the below. I find it hard to tell if a signal here while being called from a signal would do damage. int pthread_mutex_trylock(pthread_mutex_t *mutex) { return _pthread_mutex_lock(mutex, true); } static inline int _pthread_mutex_lock(pthread_mutex_t *mutex, bool trylock) { if (os_unlikely(!_pthread_mutex_check_signature_fast(mutex))) { return _pthread_mutex_lock_init_slow(mutex, trylock); } if (os_unlikely(_pthread_mutex_is_fairshare(mutex))) { return _pthread_mutex_fairshare_lock(mutex, trylock); } if (os_unlikely(_pthread_mutex_uses_ulock(mutex))) { return _pthread_mutex_ulock_lock(mutex, trylock); } #if ENABLE_USERSPACE_TRACE return _pthread_mutex_firstfit_lock_slow(mutex, trylock); #elif PLOCKSTAT if (PLOCKSTAT_MUTEX_ACQUIRE_ENABLED() || PLOCKSTAT_MUTEX_ERROR_ENABLED()) { return _pthread_mutex_firstfit_lock_slow(mutex, trylock); } #endif return _pthread_mutex_firstfit_lock(mutex, trylock); } static inline int _pthread_mutex_firstfit_lock(pthread_mutex_t *mutex, bool trylock) { /* * This is the first-fit fast path. The fairshare fast-ish path is in * _pthread_mutex_fairshare_lock() */ uint64_t *tidaddr; MUTEX_GETTID_ADDR(mutex, &tidaddr); uint64_t selfid =3D _pthread_threadid_self_np_direct(); mutex_seq *seqaddr; MUTEX_GETSEQ_ADDR(mutex, &seqaddr); mutex_seq oldseq, newseq; mutex_seq_load(seqaddr, &oldseq); if (os_unlikely(!trylock && (oldseq.lgenval & PTH_RWL_EBIT))) { return _pthread_mutex_firstfit_lock_slow(mutex, trylock); } bool gotlock; do { newseq =3D oldseq; gotlock =3D is_rwl_ebit_clear(oldseq.lgenval); if (trylock && !gotlock) { #if __LP64__ // The sequence load is atomic, so we can bail here without writing // it and avoid some unnecessary coherence traffic - rdar://57259033 os_atomic_thread_fence(acquire); return EBUSY; #else // A trylock on a held lock will fail immediately. But since // we did not load the sequence words atomically, perform a // no-op CAS64 to ensure that nobody has unlocked concurrently. #endif } else if (os_likely(gotlock)) { // In first-fit, getting the lock simply adds the E-bit newseq.lgenval |=3D PTH_RWL_EBIT; } else { return _pthread_mutex_firstfit_lock_slow(mutex, trylock); } } while (os_unlikely(!mutex_seq_atomic_cmpxchgv(seqaddr, &oldseq, &newseq, acquire))); if (os_likely(gotlock)) { os_atomic_store_wide(tidaddr, selfid, relaxed); return 0; } else if (trylock) { return EBUSY; } else { __builtin_trap(); } }