2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2008 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Daniel Cowgill <dcowgill@communityconnect.com> |
16 | Rasmus Lerdorf <rasmus@php.net> |
17 +----------------------------------------------------------------------+
19 This software was contributed to PHP by Community Connect Inc. in 2002
20 and revised in 2005 by Yahoo! Inc. to add support for PHP 5.1.
21 Future revisions and derivatives of this source code must acknowledge
22 Community Connect Inc. as the original contributor of this module by
23 leaving this note intact in the source code.
25 All other licensing and usage conditions are those of the PHP Group.
29 /* $Id: apc_shm.c,v 3.11.2.2 2008/05/11 18:57:00 rasmus Exp $ */
34 /* shm functions are available in TSRM */
35 #include <tsrm/tsrm_win32.h>
44 # define SHM_R 0444 /* read permission */
47 # define SHM_A 0222 /* write permission */
50 int apc_shm_create(const char* pathname, int proj, size_t size)
52 int shmid; /* shared memory id */
53 int oflag; /* permissions on shm */
54 key_t key; /* shm key returned by ftok */
58 /* no ftok yet for win32 */
59 if (pathname != NULL) {
60 if ((key = ftok(pathname, proj)) < 0) {
61 apc_eprint("apc_shm_create: ftok failed:");
66 oflag = IPC_CREAT | SHM_R | SHM_A;
67 if ((shmid = shmget(key, size, oflag)) < 0) {
68 apc_eprint("apc_shm_create: shmget(%d, %d, %d) failed: %s. It is possible that the chosen SHM segment size is higher than the operation system allows. Linux has usually a default limit of 32MB per segment.", key, size, oflag, strerror(errno));
74 void apc_shm_destroy(int shmid)
76 /* we expect this call to fail often, so we do not check */
77 shmctl(shmid, IPC_RMID, 0);
80 void* apc_shm_attach(int shmid)
82 void* shmaddr; /* the shared memory address */
84 if ((long)(shmaddr = shmat(shmid, 0, 0)) == -1) {
85 apc_eprint("apc_shm_attach: shmat failed:");
89 * We set the shmid for removal immediately after attaching to it. The
90 * segment won't disappear until all processes have detached from it.
92 apc_shm_destroy(shmid);
96 void apc_shm_detach(void* shmaddr)
98 if (shmdt(shmaddr) < 0) {
99 apc_eprint("apc_shm_detach: shmdt failed:");
108 * vim600: expandtab sw=4 ts=4 sts=4 fdm=marker
109 * vim<600: expandtab sw=4 ts=4 sts=4