cvs: pecl /apc apc_fcntl.c apc_fcntl.h apc_lock.h
| From: | George Schlossnagle | Date: | Fri, 27 Jun 2003 15:52:21 +0000 |
| Subject: | cvs: pecl /apc apc_fcntl.c apc_fcntl.h apc_lock.h | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-336@lists.php.net to get a copy of this message | ||
gschlossnagle Fri Jun 27 11:52:21 2003 EDT
Added files:
/pecl/apc apc_lock.h
Modified files:
/pecl/apc apc_fcntl.c apc_fcntl.h
Log:
initial import. Lock abstraction code and alternative locking mechanism based on
fcntl locks
Index: pecl/apc/apc_fcntl.c
diff -u /dev/null pecl/apc/apc_fcntl.c:3.11
--- /dev/null Fri Jun 27 11:52:21 2003
+++ pecl/apc/apc_fcntl.c Fri Jun 27 11:52:21 2003
@@ -0,0 +1,73 @@
+/*
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2002 by Community Connect Inc. All rights reserved. |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt.
|
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Daniel Cowgill <dcowgill@communityconnect.com> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id: apc_fcntl.c,v 3.11 2003/06/27 15:52:21 gschlossnagle Exp $ */
+
+#include "apc_fcntl.h"
+#include "apc.h"
+#include <unistd.h>
+#include <fcntl.h>
+
+
+int apc_fcntl_create(const char* pathname)
+{
+ int fd;
+ fd = open(pathname, O_RDWR|O_CREAT, 0666);
+ if(fd > 0 ) {
+ unlink(pathname);
+ return fd;
+ } else {
+ fprintf(stderr, "failed to open %s\n", pathname);
+ assert(0);
+ return -1;
+ }
+}
+
+void apc_fcntl_destroy(int fd)
+{
+ close(fd);
+}
+
+int lock_reg(int fd, int cmd, int type, off_t offset, int whence, off_t len)
+{
+ struct flock lock;
+
+ lock.l_type = type;
+ lock.l_start = offset;
+ lock.l_whence = whence;
+ lock.l_len = len;
+
+ return( fcntl(fd, cmd, &lock) );
+}
+
+void apc_fcntl_lock(int fd)
+{
+ lock_reg(fd, F_SETLKW, F_WRLCK, 0, SEEK_SET, 1);
+}
+
+void apc_fcntl_unlock(int fd)
+{
+ lock_reg(fd, F_SETLK, F_UNLCK, 0, SEEK_SET, 1);
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: expandtab sw=4 ts=4 sts=4 fdm=marker
+ * vim<600: expandtab sw=4 ts=4 sts=4
+ */
Index: pecl/apc/apc_fcntl.h
diff -u /dev/null pecl/apc/apc_fcntl.h:3.7
--- /dev/null Fri Jun 27 11:52:21 2003
+++ pecl/apc/apc_fcntl.h Fri Jun 27 11:52:21 2003
@@ -0,0 +1,37 @@
+/*
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2002 by Community Connect Inc. All rights reserved. |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt.
|
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Daniel Cowgill <dcowgill@communityconnect.com> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id: apc_fcntl.h,v 3.7 2003/06/27 15:52:21 gschlossnagle Exp $ */
+
+#ifndef APC_FCNTL_H
+#define APC_FCNTL_H
+
+
+extern int apc_fcntl_create(const char* pathname);
+extern void apc_fcntl_destroy(int semid);
+extern void apc_fcntl_lock(int semid);
+extern void apc_fcntl_unlock(int semid);
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: expandtab sw=4 ts=4 sts=4 fdm=marker
+ * vim<600: expandtab sw=4 ts=4 sts=4
+ */
Index: pecl/apc/apc_lock.h
+++ pecl/apc/apc_lock.h