src/dpdk/lib/librte_eal/windows/eal.c
enum rte_proc_type_t
eal_proc_type_detect(void)
{
	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
	const char *pathname = eal_runtime_config_path();
	const struct rte_config *config = rte_eal_get_configuration();

	/* if we can open the file but not get a write-lock we are a secondary
	 * process. NOTE: if we get a file handle back, we keep that open
	 * and don't close it to prevent a race condition between multiple opens
	 */
	errno_t err = _sopen_s(&mem_cfg_fd, pathname,
		_O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
	if (err == 0) {
		OVERLAPPED soverlapped = { 0 };
		soverlapped.Offset = sizeof(*config->mem_config);
		soverlapped.OffsetHigh = 0;

		HANDLE hwinfilehandle = (HANDLE)_get_osfhandle(mem_cfg_fd);

		if (!LockFileEx(hwinfilehandle,
			LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
			sizeof(*config->mem_config), 0, &soverlapped))
			ptype = RTE_PROC_SECONDARY;
	}

	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
		ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");

	return ptype;
}
/* Detect if we are a primary or a secondary process */
Detect if we are a primary or a secondary process
Detect if we are a primary or a secondary process
enum rte_proc_type_t
eal_proc_type_detect(void)
{
	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
	const char *pathname = eal_runtime_config_path();
	const struct rte_config *config = rte_eal_get_configuration();
	errno_t err = _sopen_s(&mem_cfg_fd, pathname,
		_O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
	if (err == 0) {
		OVERLAPPED soverlapped = { 0 };
		soverlapped.Offset = sizeof(*config->mem_config);
		soverlapped.OffsetHigh = 0;
		HANDLE hwinfilehandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
		if (!LockFileEx(hwinfilehandle,
			LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
			sizeof(*config->mem_config), 0, &soverlapped))
			ptype = RTE_PROC_SECONDARY;
	}
	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
		ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
	return ptype;
}
enum rte_proc_type_t eal_proc_type_detect ( void ) { enum rte_proc_type_t ptype = RTE_PROC_PRIMARY ; const char * pathname = eal_runtime_config_path ( ) ; const struct rte_config * config = rte_eal_get_configuration ( ) ; errno_t err = _sopen_s ( & mem_cfg_fd , pathname , _O_RDWR , _SH_DENYNO , _S_IREAD | _S_IWRITE ) ; if ( err == 0 ) { OVERLAPPED soverlapped = { 0 } ; soverlapped . Offset = sizeof ( * config -> mem_config ) ; soverlapped . OffsetHigh = 0 ; HANDLE hwinfilehandle = ( HANDLE ) _get_osfhandle ( mem_cfg_fd ) ; if ( ! LockFileEx ( hwinfilehandle , LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY , 0 , sizeof ( * config -> mem_config ) , 0 , & soverlapped ) ) ptype = RTE_PROC_SECONDARY ; } RTE_LOG ( INFO , EAL , " \n " , ptype == RTE_PROC_PRIMARY ? " " : " " ) ; return ptype ; }
Detect if we are a primary or a secondary process
Detect if we are a primary or a secondary process
/* if we can open the file but not get a write-lock we are a secondary
	 * process. NOTE: if we get a file handle back, we keep that open
	 * and don't close it to prevent a race condition between multiple opens
	 */