[PATCH v18 8/8] eal: implement functions for mutex management

Ananyev, Konstantin konstantin.ananyev at intel.com
Wed Feb 9 14:57:45 CET 2022


> > Actually, please scrap that comment.
> > Obviously it wouldn't work for static variables,
> > and doesn't make much sense.
> > Though few thoughts remain:
> > for posix we probably don't need an indirection and
> > rte_thread_mutex can be just typedef of pthread_mutex_t.
> > also for posix we don't need RTE_INIT constructor for each
> > static mutex initialization.
> > Something like:
> > #define RTE_STATIC_INITIALIZED_MUTEX(mx) \
> > 	rte_thread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER
> > should work, I think.
> > Konstantin
> 
> Thank you for reviewing, Konstantin!
> Some context for the current representation of mutex
> can be found in v9, patch 7/10 of this patchset.
> 
> Originally we've typedef'ed the pthread_mutex_t on POSIX, just
> like you are suggesting here.
> However, on Windows there's no static initializer similar to the pthread
> one. Still, we want ABI compatibility and same thread behavior between
> platforms. The most elegant solution we found was the current representation,
> as suggested by Dmitry K.

Yes, I agree it is a problem with Windows for static initializer.
But why we can't have different structs typedef for mutex 
for posix and windows platforms?
On posix it would be:

typedef pthread_mutex_t rte_thread_mutex_t;
#define RTE_STATIC_INITIALIZED_MUTEX(mx)   rte_thread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER 

On windows it could be what Dimitry suggested:
 
typedef struct rte_thread_mutex {
        void *mutex_id;  /**< mutex identifier */
} rte_thread_mutex_t;

#define RTE_STATIC_INITIALIZED_MUTEX(private_lock)   \
rte_thread_mutex_t private_lock; \
RTE_INIT(__rte_ ## private_lock ## _init)\
{\
        RTE_VERIFY(rte_thread_mutex_init(&private_lock) == 0);\
}

API would remain the same, though it would be different underneath.
Yes, on Windows rte_thread_mutex still wouldn't work for MP,
but that's the same as with current design.
 
> I will address your other comments on the other thread.
> 
> Link to v9: http://patchwork.dpdk.org/project/dpdk/patch/1622850274-6946-8-git-send-email-navasile@linux.microsoft.com/






More information about the dev mailing list