XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

100 lines
2.0 KiB

  1. #ifdef TEST
  2. #include <limits.h>
  3. #include <stdio.h>
  4. #else
  5. #include <php.h>
  6. #endif
  7. #include <assert.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #ifdef HAVE_CONFIG_H
  11. #include <config.h>
  12. #endif
  13. #include "xc_shm.h"
  14. struct _xc_shm_scheme_t {
  15. const char *name;
  16. const xc_shm_handlers_t *handlers;
  17. };
  18. static xc_shm_scheme_t xc_shm_schemes[10];
  19. void xc_shm_init_modules() /* {{{ */
  20. {
  21. extern void xc_shm_mem_init();
  22. #ifdef HAVE_XCACHE_TEST
  23. extern void xc_shm_malloc_register();
  24. #endif
  25. extern void xc_shm_mmap_register();
  26. memset(xc_shm_schemes, 0, sizeof(xc_shm_schemes));
  27. xc_shm_mem_init();
  28. #ifdef HAVE_XCACHE_TEST
  29. xc_shm_malloc_register();
  30. #endif
  31. xc_shm_mmap_register();
  32. }
  33. /* }}} */
  34. int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers) /* {{{ */
  35. {
  36. int i;
  37. for (i = 0; i < 10; i ++) {
  38. if (!xc_shm_schemes[i].name) {
  39. xc_shm_schemes[i].name = name;
  40. xc_shm_schemes[i].handlers = handlers;
  41. return 1;
  42. }
  43. }
  44. return 0;
  45. }
  46. /* }}} */
  47. const xc_shm_handlers_t *xc_shm_scheme_find(const char *name) /* {{{ */
  48. {
  49. int i;
  50. for (i = 0; i < 10 && xc_shm_schemes[i].name; i ++) {
  51. if (strcmp(xc_shm_schemes[i].name, name) == 0) {
  52. return xc_shm_schemes[i].handlers;
  53. }
  54. }
  55. return NULL;
  56. }
  57. /* }}} */
  58. xc_shm_scheme_t *xc_shm_scheme_first() /* {{{ */
  59. {
  60. return xc_shm_schemes;
  61. }
  62. /* }}} */
  63. xc_shm_scheme_t *xc_shm_scheme_next(xc_shm_scheme_t *scheme) /* {{{ */
  64. {
  65. scheme ++;
  66. return scheme->name ? scheme : NULL;
  67. }
  68. /* }}} */
  69. const char *xc_shm_scheme_name(xc_shm_scheme_t *scheme) /* {{{ */
  70. {
  71. assert(scheme);
  72. return scheme->name;
  73. }
  74. /* }}} */
  75. xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2) /* {{{ */
  76. {
  77. const xc_shm_handlers_t *handlers = xc_shm_scheme_find(type);
  78. if (handlers) {
  79. xc_shm_t *shm = handlers->init(size, readonly_protection, arg1, arg2);
  80. if (shm) {
  81. shm->handlers = handlers;
  82. }
  83. return shm;
  84. }
  85. return NULL;
  86. }
  87. /* }}} */
  88. void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
  89. {
  90. shm->handlers->destroy(shm);
  91. }
  92. /* }}} */