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

Ananyev, Konstantin konstantin.ananyev at intel.com
Tue Feb 8 03:21:49 CET 2022



> > +
> > +/**
> > + * Thread mutex representation.
> > + */
> > +typedef struct rte_thread_mutex_tag {
> > +	void *mutex_id;  /**< mutex identifier */
> > +} rte_thread_mutex;
> 
> I wonder can't we have something like that instead:
> 
> for posix:
> typedef pthread_mutex_t rte_thread_mutex_t;
> for windows:
> typedef struct rte_thread_mutex {
> 	int initialized;
> 	CRITICAL_SECTION cs;
> }  rte_thread_mutex_t;
> 
> Then for posix:
> #define RTE_INIT_MUTEX(mx) do {\
> 	*(mx) = PTHREAD_MUTEX_INITIALIZER; \
> } while(0)
> 
> #define RTE_DESTROY_MUTEX(mx)	do {} while (0); /*empty */
> 
> For windows:
> #define RTE_INIT_MUTEX(mx) do {\
> 	If ((mx)->initialized == 0) {
> 		InitializeCriticalSection((mx)->cs);
> 		(mx)->initialized = 1;
> 	}
> } while (0)
> 
> #define RTE_DESTROY_MUTEX(mx)	do {
> 	if ((mx)->initialized != 0) { \
> 		DeleteCriticalSection((mx)->cs);
> 	}
> } while (0)
> 

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





More information about the dev mailing list