source: trunk/xcache/xc_extension.c @ 1047

Last change on this file since 1047 was 1047, checked in by moo, 2 years ago

refactor: fall back to more simpler trick

  • Property svn:eol-style set to native
File size: 1.8 KB
RevLine 
[1026]1
2#include "xc_extension.h"
3#include "xcache.h"
4#include "util/xc_trace.h"
5
6
[1047]7int xcache_zend_extension_add(zend_extension *new_extension, zend_bool prepend) /* {{{ */
[1026]8{
9    zend_extension extension;
10
11    extension = *new_extension;
12    extension.handle = 0;
13
14    zend_extension_dispatch_message(ZEND_EXTMSG_NEW_EXTENSION, &extension);
15
[1047]16    if (prepend) {
17        zend_llist_prepend_element(&zend_extensions, &extension);
18    }
19    else {
20        zend_llist_add_element(&zend_extensions, &extension);
21    }
22    TRACE("%s", "registered");
[1026]23    return SUCCESS;
24}
25/* }}} */
26static int xc_ptr_compare_func(void *p1, void *p2) /* {{{ */
27{
28    return p1 == p2;
29}
30/* }}} */
31static int xc_zend_extension_remove(zend_extension *extension) /* {{{ */
32{
33    llist_dtor_func_t dtor;
34
35    assert(extension);
36    dtor = zend_extensions.dtor; /* avoid dtor */
37    zend_extensions.dtor = NULL;
38    zend_llist_del_element(&zend_extensions, extension, xc_ptr_compare_func);
39    zend_extensions.dtor = dtor;
40    return SUCCESS;
41}
42/* }}} */
[1045]43int xcache_zend_extension_remove(zend_extension *extension) /* {{{ */
[1026]44{
45    zend_extension *ext = zend_get_extension(extension->name);
46    if (!ext) {
47        return FAILURE;
48    }
49
50    if (ext->shutdown) {
51        ext->shutdown(ext);
52    }
53    xc_zend_extension_remove(ext);
54    return SUCCESS;
55}
56/* }}} */
57
58void xcache_llist_prepend(zend_llist *l, zend_llist_element *element) /* {{{ */
59{
60    element->next = l->head;
61    element->prev = NULL;
62    if (l->head) {
63        l->head->prev = element;
64    }
65    else {
66        l->tail = element;
67    }
68    l->head = element;
69    ++l->count;
70}
71/* }}} */
72void xcache_llist_unlink(zend_llist *l, zend_llist_element *element) /* {{{ */
73{
74    if ((element)->prev) {
75        (element)->prev->next = (element)->next;
76    }
77    else {
78        (l)->head = (element)->next;
79    }
80
81    if ((element)->next) {
82        (element)->next->prev = (element)->prev;
83    }
84    else {
85        (l)->tail = (element)->prev;
86    }
87
88    --l->count;
89}
90/* }}} */
Note: See TracBrowser for help on using the repository browser.