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.

74 lines
1.6 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. #include "xc_shm.h"
  11. typedef struct {
  12. const char *name;
  13. const xc_shm_handlers_t *handlers;
  14. } xc_shm_scheme_t;
  15. static xc_shm_scheme_t xc_shm_schemes[10];
  16. void xc_shm_init_modules() /* {{{ */
  17. {
  18. extern void xc_shm_mem_init();
  19. extern void xc_shm_malloc_register();
  20. extern void xc_shm_mmap_register();
  21. memset(xc_shm_schemes, 0, sizeof(xc_shm_schemes));
  22. xc_shm_mem_init();
  23. xc_shm_malloc_register();
  24. xc_shm_mmap_register();
  25. }
  26. /* }}} */
  27. int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers) /* {{{ */
  28. {
  29. int i;
  30. for (i = 0; i < 10; i ++) {
  31. if (!xc_shm_schemes[i].name) {
  32. xc_shm_schemes[i].name = name;
  33. xc_shm_schemes[i].handlers = handlers;
  34. return 1;
  35. }
  36. }
  37. return 0;
  38. }
  39. /* }}} */
  40. const xc_shm_handlers_t *xc_shm_scheme_find(const char *name) /* {{{ */
  41. {
  42. int i;
  43. for (i = 0; i < 10 && xc_shm_schemes[i].name; i ++) {
  44. if (strcmp(xc_shm_schemes[i].name, name) == 0) {
  45. return xc_shm_schemes[i].handlers;
  46. }
  47. }
  48. return NULL;
  49. }
  50. /* }}} */
  51. xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2) /* {{{ */
  52. {
  53. const xc_shm_handlers_t *handlers = xc_shm_scheme_find(type);
  54. if (handlers) {
  55. xc_shm_t *shm = handlers->init(size, readonly_protection, arg1, arg2);
  56. if (shm) {
  57. shm->handlers = handlers;
  58. }
  59. return shm;
  60. }
  61. return NULL;
  62. }
  63. /* }}} */
  64. void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
  65. {
  66. shm->handlers->destroy(shm);
  67. }
  68. /* }}} */