It's OK to do that. Also since it's implementation, you can exploit the fact that shm_free catches SHM_INVALID and returns -1 (== defined behavior).
It would be cleaner/faster to save handles and use those, but not that important since termination is not performance critical. -Petri > -----Original Message----- > From: ext Robbie King (robking) [mailto:[email protected]] > Sent: Wednesday, February 18, 2015 6:50 PM > To: Taras Kondratiuk > Cc: Mike Holmes; [email protected]; Petri Savolainen > ([email protected]) > Subject: RE: [lng-odp] [PATCH v2 00/10] add global and local termination > > While I'm not a big fan of the "lookup" APIs myself, if > they exist implementations should be able to use them I think. > > Does the nesting violate any coding style restrictions? > > ret = odp_shm_free(odp_shm_lookup("shm_odp_cos_tbl")); > > > -----Original Message----- > From: Taras Kondratiuk [mailto:[email protected]] > Sent: Wednesday, February 18, 2015 11:01 AM > To: Robbie King (robking) > Cc: Mike Holmes; [email protected]; Petri Savolainen > ([email protected]) > Subject: Re: [lng-odp] [PATCH v2 00/10] add global and local termination > > On 02/18/2015 05:53 PM, Robbie King (robking) wrote: > > Hey Mike (and everyone else), > > > > I noticed this code is replicated throughout the patch: > > > > cos_shm = odp_shm_lookup("shm_odp_cos_tbl"); > > if (cos_shm == ODP_SHM_INVALID) > > return -1; > > ret = odp_shm_free(cos_shm); > > > > As I was looking to make the changes we discussed (continue > > on versus returning -1) it seemed instead of replicating > > even more code it would be better to have some cleaner way > > of doing this. > > > > One possibility is to simply nest the calls (shm_free just > > returns -1 if passed SHM_INVALID). > > > > ret = odp_shm_free(odp_shm_lookup("shm_odp_cos_tbl")); > > > > Another option is to create a helper function, something like: > > > > ret = odp_shm_free_by_name("shm_odp_cos_tbl"); > > > > If the helper is the way to go, then it could either be internal > > or published API. Any thoughts on the "correct solution"? > > > > 1) nested calls > > 2) internal API > > 3) published API > > I prefer a forth option :) > Save allocated odp_shm_t handle and don't lookup it. _______________________________________________ lng-odp mailing list [email protected] http://lists.linaro.org/mailman/listinfo/lng-odp
