summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorXuefer <xuefer@gmail.com>2012-07-17 08:35:45 +0000
committerXuefer <xuefer@gmail.com>2012-07-17 08:35:45 +0000
commitef5a13d72a76a64ff62c8060dd87cc64e3c102dc (patch)
treef896e3b5b33fe6e6f50a0e46cda09744b3fed1c3 /util
parentf9f7ff5d278e9650098bf021566b6b2a6a521f9e (diff)
downloadxcache-ef5a13d72a76a64ff62c8060dd87cc64e3c102dc.tar.gz
xcache-ef5a13d72a76a64ff62c8060dd87cc64e3c102dc.zip
move files to subdirs
git-svn-id: svn://svn.lighttpd.net/xcache/trunk@982 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
Diffstat (limited to 'util')
-rw-r--r--util/README1
-rw-r--r--util/xc_align.h19
-rw-r--r--util/xc_foreachcoresig.h50
-rw-r--r--util/xc_stack.c62
-rw-r--r--util/xc_stack.h22
-rw-r--r--util/xc_vector.h56
6 files changed, 210 insertions, 0 deletions
diff --git a/util/README b/util/README
new file mode 100644
index 0000000..1801986
--- /dev/null
+++ b/util/README
@@ -0,0 +1 @@
+generic utility stuffs unrelatived to ZendEngine
diff --git a/util/xc_align.h b/util/xc_align.h
new file mode 100644
index 0000000..03db2c0
--- /dev/null
+++ b/util/xc_align.h
@@ -0,0 +1,19 @@
+#ifndef __ALIGN_H
+#define __ALIGN_H
+#ifndef ALIGN
+typedef union align_union {
+ double d;
+ void *v;
+ int (*func)(int);
+ long l;
+} align_union;
+
+#if (defined (__GNUC__) && __GNUC__ >= 2)
+#define XCACHE_PLATFORM_ALIGNMENT (__alignof__ (align_union))
+#else
+#define XCACHE_PLATFORM_ALIGNMENT (sizeof(align_union))
+#endif
+
+#define ALIGN(n) ((((size_t)(n)-1) & ~(XCACHE_PLATFORM_ALIGNMENT-1)) + XCACHE_PLATFORM_ALIGNMENT)
+#endif
+#endif /* __ALIGN_H */
diff --git a/util/xc_foreachcoresig.h b/util/xc_foreachcoresig.h
new file mode 100644
index 0000000..41cb798
--- /dev/null
+++ b/util/xc_foreachcoresig.h
@@ -0,0 +1,50 @@
+/* all signals generate coredump by default is list here */
+
+#ifdef SIGABRT
+FOREACH_SIG(SIGABRT);
+#endif
+
+#ifdef SIGBUS
+FOREACH_SIG(SIGBUS);
+#endif
+
+#ifdef SIGEMT
+FOREACH_SIG(SIGEMT);
+#endif
+
+#ifdef SIGFPE
+FOREACH_SIG(SIGFPE);
+#endif
+
+#ifdef SIGILL
+FOREACH_SIG(SIGILL);
+#endif
+
+#ifdef SIGIOT
+FOREACH_SIG(SIGIOT);
+#endif
+
+#ifdef SIGQUIT
+FOREACH_SIG(SIGQUIT);
+#endif
+
+#ifdef SIGSEGV
+FOREACH_SIG(SIGSEGV);
+#endif
+
+#ifdef SIGSYS
+FOREACH_SIG(SIGSYS);
+#endif
+
+#ifdef SIGTRAP
+FOREACH_SIG(SIGTRAP);
+#endif
+
+#ifdef SIGXCPU
+FOREACH_SIG(SIGXCPU);
+#endif
+
+#ifdef SIGXFSZ
+FOREACH_SIG(SIGXFSZ);
+#endif
+
diff --git a/util/xc_stack.c b/util/xc_stack.c
new file mode 100644
index 0000000..244339c
--- /dev/null
+++ b/util/xc_stack.c
@@ -0,0 +1,62 @@
+#include <stdlib.h>
+#include <assert.h>
+#include "xc_stack.h"
+typedef xc_stack_t* S;
+
+void xc_stack_init_ex(S stack, int initsize)
+{
+ stack->cnt = 0;
+ stack->size = initsize;
+ stack->data = malloc(sizeof(void *) * stack->size);
+}
+
+void xc_stack_destroy(S stack)
+{
+ free(stack->data);
+}
+
+void xc_stack_push(S stack, void *item)
+{
+ if (stack->cnt == stack->size) {
+ stack->size <<= 1;
+ stack->data = realloc(stack->data, sizeof(void *) * stack->size);
+ }
+ stack->data[stack->cnt++] = item;
+}
+
+void* xc_stack_pop(S stack)
+{
+ assert(stack != NULL && stack->size > 0);
+ return stack->data[--stack->cnt];
+}
+
+void* xc_stack_top(S stack)
+{
+ assert(stack != NULL && stack->cnt > 0);
+ return stack->data[stack->cnt-1];
+}
+
+void* xc_stack_get(S stack, int n)
+{
+ assert(stack != NULL && stack->cnt > 0);
+ return stack->data[n];
+}
+
+int xc_stack_count(S stack)
+{
+ assert(stack != NULL);
+ return stack->cnt;
+}
+
+void xc_stack_reverse(S stack)
+{
+ int i, j;
+ void *tmp;
+
+ assert(stack != NULL);
+ for (i = 0, j = stack->cnt - 1; i < j; i ++, j --) {
+ tmp = stack->data[i];
+ stack->data[i] = stack->data[j];
+ stack->data[j] = tmp;
+ }
+}
diff --git a/util/xc_stack.h b/util/xc_stack.h
new file mode 100644
index 0000000..8f82870
--- /dev/null
+++ b/util/xc_stack.h
@@ -0,0 +1,22 @@
+#ifndef __XC_UTIL_STACK
+#define __XC_UTIL_STACK
+
+typedef struct {
+ void **data;
+ int cnt;
+ int size;
+} xc_stack_t;
+
+#define S xc_stack_t*
+void xc_stack_init_ex(S stack, int initsize);
+#define xc_stack_init(stack) xc_stack_init_ex(stack, 8)
+void xc_stack_destroy(S stack);
+void xc_stack_push(S stack, void *item);
+void *xc_stack_pop(S stack);
+void *xc_stack_top(S stack);
+void *xc_stack_get(S stack, int n);
+int xc_stack_count(S stack);
+void xc_stack_reverse(S stack);
+#undef S
+
+#endif /* __XC_UTIL_STACK */
diff --git a/util/xc_vector.h b/util/xc_vector.h
new file mode 100644
index 0000000..ff53fac
--- /dev/null
+++ b/util/xc_vector.h
@@ -0,0 +1,56 @@
+#ifndef XC_VECTOR_H_0957AC4E1A44E838C7B8DBECFF9C4B3B
+#define XC_VECTOR_H_0957AC4E1A44E838C7B8DBECFF9C4B3B
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+
+typedef struct {
+ zend_uint size;
+ zend_uint cnt;
+ void *data;
+} xc_vector_t;
+
+#define xc_vector_init(type, vector) do { \
+ (vector)->cnt = 0; \
+ (vector)->size = 0; \
+ (vector)->data = NULL; \
+} while (0)
+
+#define xc_vector_add(type, vector, value) do { \
+ if ((vector)->cnt == (vector)->size) { \
+ if ((vector)->size) { \
+ (vector)->size <<= 1; \
+ (vector)->data = erealloc((vector)->data, sizeof(type) * (vector)->size); \
+ } \
+ else { \
+ (vector)->size = 8; \
+ (vector)->data = emalloc(sizeof(type) * (vector)->size); \
+ } \
+ } \
+ ((type *) (vector)->data)[(vector)->cnt++] = value; \
+} while (0)
+
+static inline void *xc_vector_detach_impl(xc_vector_t *vector)
+{
+ void *data = vector->data;
+ vector->data = NULL;
+ vector->size = 0;
+ vector->cnt = 0;
+ return data;
+}
+
+#define xc_vector_detach(type, vector) ((type *) xc_vector_detach_impl(vector))
+
+static inline void xc_vector_free_impl(xc_vector_t *vector TSRMLS_DC)
+{
+ if (vector->data) {
+ efree(vector->data);
+ }
+ vector->size = 0;
+ vector->cnt = 0;
+}
+
+#define xc_vector_free(type, vector) xc_vector_free_impl(vector TSRMLS_CC)
+
+#endif /* XC_VECTOR_H_0957AC4E1A44E838C7B8DBECFF9C4B3B */