00001
00002
00003
00004
00005
00006
00007
00008
00014 #ifndef __GEARMAN_SERVER_COMMON_H__
00015 #define __GEARMAN_SERVER_COMMON_H__
00016
00017 #include "config.h"
00018
00019 #define GEARMAN_CORE
00020 #include "gearmand.h"
00021
00022 #ifdef HAVE_ASSERT_H
00023 #include <assert.h>
00024 #endif
00025 #ifdef HAVE_ERRNO_H
00026 #include <errno.h>
00027 #endif
00028 #ifdef HAVE_FCNTL_H
00029 #include <fcntl.h>
00030 #endif
00031 #ifdef HAVE_GETOPT_H
00032 #include <getopt.h>
00033 #endif
00034 #ifdef HAVE_PTHREAD
00035 #include <pthread.h>
00036 #endif
00037 #ifdef HAVE_STDARG_H
00038 #include <stdarg.h>
00039 #endif
00040 #ifdef HAVE_STDDEF_H
00041 #include <stddef.h>
00042 #endif
00043 #ifdef HAVE_STDIO_H
00044 #include <stdio.h>
00045 #endif
00046 #ifdef HAVE_STDLIB_H
00047 #include <stdlib.h>
00048 #endif
00049 #ifdef HAVE_STRING_H
00050 #include <string.h>
00051 #endif
00052 #ifdef HAVE_STRINGS_H
00053 #include <strings.h>
00054 #endif
00055 #ifdef HAVE_SYS_UTSNAME_H
00056 #include <sys/utsname.h>
00057 #endif
00058 #ifdef HAVE_NETINET_TCP_H
00059 #include <netinet/tcp.h>
00060 #endif
00061 #ifdef HAVE_UNISTD_H
00062 #include <unistd.h>
00063 #endif
00064 #ifdef HAVE_UUID_UUID_H
00065 #include <uuid/uuid.h>
00066 #endif
00067
00068 #ifdef TIME_WITH_SYS_TIME
00069 # include <sys/time.h>
00070 # include <time.h>
00071 #else
00072 # ifdef HAVE_SYS_TIME_H
00073 # include <sys/time.h>
00074 # else
00075 # include <time.h>
00076 # endif
00077 #endif
00078
00079 #ifdef __cplusplus
00080 extern "C" {
00081 #endif
00082
00083 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
00084 #define likely(__x) if((__x))
00085 #define unlikely(__x) if((__x))
00086 #else
00087 #define likely(__x) if(__builtin_expect((__x), 1))
00088 #define unlikely(__x) if(__builtin_expect((__x), 0))
00089 #endif
00090
00095 #define GEARMAN_LIST_ADD(__list, __obj, __prefix) { \
00096 if (__list ## _list != NULL) \
00097 __list ## _list->__prefix ## prev= __obj; \
00098 __obj->__prefix ## next= __list ## _list; \
00099 __obj->__prefix ## prev= NULL; \
00100 __list ## _list= __obj; \
00101 __list ## _count++; \
00102 }
00103
00108 #define GEARMAN_LIST_DEL(__list, __obj, __prefix) { \
00109 if (__list ## _list == __obj) \
00110 __list ## _list= __obj->__prefix ## next; \
00111 if (__obj->__prefix ## prev != NULL) \
00112 __obj->__prefix ## prev->__prefix ## next= __obj->__prefix ## next; \
00113 if (__obj->__prefix ## next != NULL) \
00114 __obj->__prefix ## next->__prefix ## prev= __obj->__prefix ## prev; \
00115 __list ## _count--; \
00116 }
00117
00122 #define GEARMAN_FIFO_ADD(__list, __obj, __prefix) { \
00123 if (__list ## _end == NULL) \
00124 __list ## _list= __obj; \
00125 else \
00126 __list ## _end->__prefix ## next= __obj; \
00127 __list ## _end= __obj; \
00128 __list ## _count++; \
00129 }
00130
00135 #define GEARMAN_FIFO_DEL(__list, __obj, __prefix) { \
00136 __list ## _list= __obj->__prefix ## next; \
00137 if (__list ## _list == NULL) \
00138 __list ## _end= NULL; \
00139 __list ## _count--; \
00140 }
00141
00146 #define GEARMAN_HASH_ADD(__hash, __key, __obj, __prefix) { \
00147 if (__hash ## _hash[__key] != NULL) \
00148 __hash ## _hash[__key]->__prefix ## prev= __obj; \
00149 __obj->__prefix ## next= __hash ## _hash[__key]; \
00150 __obj->__prefix ## prev= NULL; \
00151 __hash ## _hash[__key]= __obj; \
00152 __hash ## _count++; \
00153 }
00154
00159 #define GEARMAN_HASH_DEL(__hash, __key, __obj, __prefix) { \
00160 if (__hash ## _hash[__key] == __obj) \
00161 __hash ## _hash[__key]= __obj->__prefix ## next; \
00162 if (__obj->__prefix ## prev != NULL) \
00163 __obj->__prefix ## prev->__prefix ## next= __obj->__prefix ## next; \
00164 if (__obj->__prefix ## next != NULL) \
00165 __obj->__prefix ## next->__prefix ## prev= __obj->__prefix ## prev; \
00166 __hash ## _count--; \
00167 }
00168
00169
00170
00171 #ifndef HAVE_EVENT_BASE_NEW
00172 #define event_base_new event_init
00173 #endif
00174
00175 #ifndef HAVE_EVENT_BASE_FREE
00176 #define event_base_free (void)
00177 #endif
00178
00179 #ifndef HAVE_EVENT_BASE_GET_METHOD
00180 #define event_base_get_method(__base) event_get_method()
00181 #endif
00182
00183 #ifdef __cplusplus
00184 }
00185 #endif
00186
00187 #endif