From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751937AbdBAJZc (ORCPT ); Wed, 1 Feb 2017 04:25:32 -0500 Received: from merlin.infradead.org ([205.233.59.134]:48110 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751639AbdBAJZb (ORCPT ); Wed, 1 Feb 2017 04:25:31 -0500 Date: Wed, 1 Feb 2017 10:25:21 +0100 From: Peter Zijlstra To: Fabian Frederick Cc: Andrew Morton , Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [PATCH 01/14] locking/atomic: import atomic_dec_not_zero() Message-ID: <20170201092521.GS6515@twins.programming.kicks-ass.net> References: <20170130183938.12702-1-fabf@skynet.be> <20170131104154.GO6515@twins.programming.kicks-ass.net> <320001703.34628.1485884488784.open-xchange@webmail.nmp.proximus.be> <20170131191722.GR6515@twins.programming.kicks-ass.net> <457832747.1616728.1485896108161.open-xchange@webmail.nmp.proximus.be> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <457832747.1616728.1485896108161.open-xchange@webmail.nmp.proximus.be> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 31, 2017 at 09:55:08PM +0100, Fabian Frederick wrote: > Once again it's just about readability: I feel APIs should be about common use-cases, not about sporadic weird cases. > "add -1 unless value is zero" looks more complex in code than "dec not zero" > but maybe it's just a matter of taste :) It it's not the case why would there be > more sense about having > atomic_inc_not_zero() globally ? inc_not_zero() has a very strong use-case, its for lockless refcount increment. Incrementing a 0 reference count is bad because the object will be freed and you'll have a use-after-free. Arguably, once we move reference counting over to its own type, it would make sense to remove it from atomic, specifically to discourage that use case.