[dpdk-dev] [PATCH v1 1/1] net/hinic: use mutex replace spin lock

Xuanziyang (William, Chip Application Design Logic and Hardware Development Dept IT_Products & Solutions) xuanziyang2 at huawei.com
Tue Jul 9 14:14:02 CEST 2019


> On Wed, 3 Jul 2019 23:35:42 +0800
> Ziyang Xuan <xuanziyang2 at huawei.com> wrote:
> 
> >
> > +static inline int hinic_mutex_init(pthread_mutex_t *pthreadmutex,
> > +					const pthread_mutexattr_t *mattr) {
> > +	int err;
> > +
> > +	err = pthread_mutex_init(pthreadmutex, mattr);
> > +	if (unlikely(err))
> > +		PMD_DRV_LOG(ERR, "Fail to initialize mutex, error: %d", err);
> > +
> > +	return err;
> > +}
> > +
> > +static inline int hinic_mutex_destroy(pthread_mutex_t *pthreadmutex)
> > +{
> > +	int err;
> > +
> > +	err = pthread_mutex_destroy(pthreadmutex);
> > +	if (unlikely(err))
> > +		PMD_DRV_LOG(ERR, "Fail to destroy mutex, error: %d", err);
> > +
> > +	return err;
> > +}
> > +
> 
> I don't think the wrapper functions add much.
> pthread_mutex_init just sets internals of data structure and won't fail ever if
> mutexattr_t is NULL.
> 
> Just use pthread_mutex_init/pthread_mutex_destroy directly and ignore
> errors.

I think pthread_mutex_init/pthread_mutex_destroy may fail under some situations.
https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_mutex_init.html

I want some logs when they failed to position problems conveniently and I would also
detect their failures. So I encapsulate the functions. And I think it is better.


More information about the dev mailing list