> On Wed, 3 Jul 2019 23:35:42 +0800
> Ziyang Xuan <xuanziya...@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.
  • ... Ziyang Xuan
    • ... Stephen Hemminger
    • ... Xuanziyang (William, Chip Application Design Logic and Hardware Development Dept IT_Products & Solutions)

Reply via email to