From: Ian Jackson Subject: Re: [PATCH 15/15] libxl: New event generation API Date: Mon, 12 Dec 2011 16:04:25 +0000 Message-ID: <20198.9737.680162.103418@mariner.uk.xensource.com> References: <1323108621-22654-1-git-send-email-ian.jackson@eu.citrix.com> <1323108621-22654-16-git-send-email-ian.jackson@eu.citrix.com> <20194.22539.574524.956955@mariner.uk.xensource.com> <1323463293.20936.11.camel@dagon.hellion.org.uk> <20197.59428.699013.507183@mariner.uk.xensource.com> <1323692225.20077.183.camel@zakaz.uk.xensource.com> <20197.62462.189827.239656@mariner.uk.xensource.com> <1323697723.20077.212.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Stefano Stabellini Cc: "xen-devel@lists.xensource.com" , Ian Campbell List-Id: xen-devel@lists.xenproject.org Stefano Stabellini writes ("Re: [Xen-devel] [PATCH 15/15] libxl: New event generation API"): > On Mon, 12 Dec 2011, Ian Campbell wrote: > > On Mon, 2011-12-12 at 12:30 +0000, Ian Jackson wrote: > > > In general this means that functions which lock the ctx must not > > > allocate an inner gc. > > this is quite an important limitation and change in behaviour! Luckily I have only introduced the ctx lock in this series so there is no existing code which violates this rule. > > It's probably not so important for memory allocation cleanup but it > > would be a semantically useful change for the callbacks if we could > > arrange for them to happen only on final exit of the library -- exactly > > because of the difficulty of reasoning about things otherwise. Alas I > > can't think of a good way to do this since the ctx can be shared, thread > > local storage would be one or libxl__gc_owner could return a special > > "nested ctx" instead of the real outer ctx, but, ick. > > I think that using TLS to increase/decrease a nesting counter would OK > in this case. We could have a libxl__enter and a libxl__exit function > that take care it this. > > Modifying libxl__gc_owner could lead to errors because it doesn't handle > the case in which an externally visible function calls another > externally visible function: libxl__gc_owner wouldn't even be called in > this case. I suggested to Ian the moral equivalent of: #define CTX_LOCK \ \ ctx->recursive_lock_counter++ #define GC_INIT \ CTX_LOCK; \ assert(ctx->recursive_lock_counter==1); \ CTX_UNLOCK but I don't think this is really very nice. I think the answer is to write a comment saying that it is forbidden to allocate a new gc with the ctx locked. Ian.