このページを編集する際は、編集に関する方針に従ってください。

概要

引数

実装

postgresql-8.1.4/src/backend/port/win32/shmem.c

int
shmget(int memKey, int size, int flag)
{
	HANDLE		hmap;
	char		szShareMem[32];
	DWORD		dwRet;
	s_segsize = size;
	sprintf(szShareMem, "PostgreSQL.%d", memKey);
	if (flag & IPC_CREAT)
	{
		hmap = CreateFileMapping((HANDLE) 0xFFFFFFFF,	/* Use the swap file	*/
								 NULL,
								 PAGE_READWRITE,		/* Memory is Read/Write */
								 0L,	/* Size Upper 32 Bits	*/
								 (DWORD) s_segsize,		/* Size Lower 32 bits */
								 szShareMem);
	}
	else
	{
		hmap = OpenFileMapping(FILE_MAP_ALL_ACCESS,
							   FALSE,
							   szShareMem);
		if (!hmap)
		{
			errno = ENOENT;
			return -1;
		}
	}
	dwRet = GetLastError();
	if (dwRet == ERROR_ALREADY_EXISTS && hmap && (flag & (IPC_CREAT | IPC_EXCL)))
	{
		/* Caller wanted to create the segment -- error if already exists */
		CloseHandle(hmap);
		errno = EEXIST;
		return -1;
	}
	else if (!hmap)
	{
		/* Unable to get shared memory */
		_dosmaperr(GetLastError());
		return -1;
	}
	return (int) hmap;
}

postgresql-8.1.4/src/backend/port/qnx4/shm.c

int
shmget(key_t key, size_t size, int flags)
{
	char		name[NAME_MAX + 1];
	int			oflag = 0;
	struct shm_info info;
	if (flags & IPC_CREAT)
		oflag |= O_CREAT;
	if (flags & IPC_EXCL)
		oflag |= O_EXCL;
	if (flags & SHM_R)
	{
		if (flags & SHM_W)
			oflag |= O_RDWR;
		else
			oflag |= O_RDONLY;
	}
	info.shmid = shm_open(keytoname(key, name), oflag, MODE);
	/* store shared memory information */
	if (info.shmid != -1)
	{
		info.key = key;
		info.size = size;
		info.addr = NULL;
		if (shm_putinfo(&info) == -1)
		{
			close(info.shmid);
			if ((oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
				shm_unlink(name);
			return -1;
		}
	}
	/* The size may only be set once. Ignore errors. */
	ltrunc(info.shmid, size, SEEK_SET);
	return info.shmid;
}

postgresql-8.1.4/src/backend/port/beos/shm.c

int
shmget(int memKey, int size, int flag)
{
	char		nom[50];
	void	   *Address;
	area_id		parea;
	/* Area name */
	sprintf(nom, "SYSV_IPC_SHM : %d", memKey);
	/* Find area */
	parea = find_area(nom);
	/* area exist, just return its id */
	if (parea != B_NAME_NOT_FOUND)
		return parea;
	/* area does not exist and no creation is requested : error */
	if (flag == 0)
		return -1;
	/*
	 * area does not exist and its creation is requested, create it (be sure
	 * to have a 4ko multiple size
	 */
	return create_area(nom, &Address, B_ANY_ADDRESS, ((size / 4096) + 1) * 4096, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
}

呼出元

備考

履歴

コメント



トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS