php extension use __destruct
parent
76b264f0b2
commit
cc235c0c63
|
|
@ -29,7 +29,7 @@ CMD="$PRG $CONF"
|
||||||
RETVAL=0
|
RETVAL=0
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
echo -n $"Starting FastDFS storage server: "
|
echo -n "Starting FastDFS storage server: "
|
||||||
$CMD &
|
$CMD &
|
||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
echo
|
echo
|
||||||
|
|
@ -64,7 +64,7 @@ case "$1" in
|
||||||
restart
|
restart
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
|
echo "Usage: $0 {start|stop|status|restart|condrestart}"
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,9 @@ typedef struct
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
FDFSConfigInfo *pConfigInfo;
|
zend_object zo;
|
||||||
|
FDFSConfigInfo *pConfigInfo;
|
||||||
FDFSPhpContext context;
|
FDFSPhpContext context;
|
||||||
zend_object zo;
|
|
||||||
} php_fdfs_t;
|
} php_fdfs_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
@ -171,6 +171,8 @@ static inline int fdfs_zend_get_configuration_directive(char *name, int len, zva
|
||||||
static int php_fdfs_download_callback(void *arg, const int64_t file_size, \
|
static int php_fdfs_download_callback(void *arg, const int64_t file_size, \
|
||||||
const char *data, const int current_size);
|
const char *data, const int current_size);
|
||||||
|
|
||||||
|
static void php_fdfs_free_storage(php_fdfs_t *i_obj);
|
||||||
|
|
||||||
static FDFSConfigInfo *config_list = NULL;
|
static FDFSConfigInfo *config_list = NULL;
|
||||||
static int config_count = 0;
|
static int config_count = 0;
|
||||||
|
|
||||||
|
|
@ -5504,7 +5506,7 @@ static PHP_METHOD(FastDFS, __construct)
|
||||||
long config_index;
|
long config_index;
|
||||||
bool bMultiThread;
|
bool bMultiThread;
|
||||||
zval *object = getThis();
|
zval *object = getThis();
|
||||||
php_fdfs_t *i_obj;
|
php_fdfs_t *i_obj = NULL;
|
||||||
|
|
||||||
config_index = 0;
|
config_index = 0;
|
||||||
bMultiThread = false;
|
bMultiThread = false;
|
||||||
|
|
@ -5527,6 +5529,8 @@ static PHP_METHOD(FastDFS, __construct)
|
||||||
}
|
}
|
||||||
|
|
||||||
i_obj = (php_fdfs_t *) fdfs_get_object(object);
|
i_obj = (php_fdfs_t *) fdfs_get_object(object);
|
||||||
|
fprintf(stderr, "i_obj in __construct: %p\n", i_obj);
|
||||||
|
|
||||||
i_obj->pConfigInfo = config_list + config_index;
|
i_obj->pConfigInfo = config_list + config_index;
|
||||||
i_obj->context.err_no = 0;
|
i_obj->context.err_no = 0;
|
||||||
if (bMultiThread)
|
if (bMultiThread)
|
||||||
|
|
@ -5557,7 +5561,12 @@ static PHP_METHOD(FastDFS, __construct)
|
||||||
|
|
||||||
static PHP_METHOD(FastDFS, __destruct)
|
static PHP_METHOD(FastDFS, __destruct)
|
||||||
{
|
{
|
||||||
logInfo("file: "__FILE__",line: %d, __destruct", __LINE__);
|
zval *object = getThis();
|
||||||
|
php_fdfs_t *i_obj;
|
||||||
|
|
||||||
|
i_obj = (php_fdfs_t *) fdfs_get_object(object);
|
||||||
|
php_fdfs_free_storage(i_obj);
|
||||||
|
fprintf(stderr, "file: "__FILE__",line: %d, __destruct: %p\n", __LINE__, i_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -6666,6 +6675,8 @@ PHP_METHOD(FastDFS, close)
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_INFO_EX(arginfo___construct, 0, 0, 0)
|
ZEND_BEGIN_ARG_INFO_EX(arginfo___construct, 0, 0, 0)
|
||||||
|
ZEND_ARG_INFO(0, config_index)
|
||||||
|
ZEND_ARG_INFO(0, bMultiThread)
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_INFO_EX(arginfo___destruct, 0, 0, 0)
|
ZEND_BEGIN_ARG_INFO_EX(arginfo___destruct, 0, 0, 0)
|
||||||
|
|
@ -7247,10 +7258,11 @@ static zend_function_entry fdfs_class_methods[] = {
|
||||||
#undef FDFS_ME
|
#undef FDFS_ME
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static void php_fdfs_free_storage(php_fdfs_t *i_obj TSRMLS_DC)
|
static void php_fdfs_free_storage(php_fdfs_t *i_obj)
|
||||||
{
|
{
|
||||||
zend_object_std_dtor(&i_obj->zo TSRMLS_CC);
|
zend_object_std_dtor(&i_obj->zo TSRMLS_CC);
|
||||||
php_fdfs_destroy(i_obj TSRMLS_CC);
|
php_fdfs_destroy(i_obj TSRMLS_CC);
|
||||||
|
fprintf(stderr, "destroy obj: %p\n", i_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PHP_MAJOR_VERSION < 7
|
#if PHP_MAJOR_VERSION < 7
|
||||||
|
|
@ -7264,10 +7276,10 @@ zend_object_value php_fdfs_new(zend_class_entry *ce TSRMLS_DC)
|
||||||
zend_object_std_init(&i_obj->zo, ce TSRMLS_CC);
|
zend_object_std_init(&i_obj->zo, ce TSRMLS_CC);
|
||||||
retval.handle = zend_objects_store_put(i_obj, \
|
retval.handle = zend_objects_store_put(i_obj, \
|
||||||
(zend_objects_store_dtor_t)zend_objects_destroy_object, \
|
(zend_objects_store_dtor_t)zend_objects_destroy_object, \
|
||||||
(zend_objects_free_object_storage_t)php_fdfs_free_storage, \
|
NULL, NULL TSRMLS_CC);
|
||||||
NULL TSRMLS_CC);
|
|
||||||
retval.handlers = zend_get_std_object_handlers();
|
retval.handlers = zend_get_std_object_handlers();
|
||||||
|
|
||||||
|
fprintf(stderr, "retval.handle: %d, i_obj: %p\n", retval.handle, i_obj);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -7276,11 +7288,13 @@ zend_object_value php_fdfs_new(zend_class_entry *ce TSRMLS_DC)
|
||||||
zend_object* php_fdfs_new(zend_class_entry *ce)
|
zend_object* php_fdfs_new(zend_class_entry *ce)
|
||||||
{
|
{
|
||||||
php_fdfs_t *i_obj;
|
php_fdfs_t *i_obj;
|
||||||
|
int handle;
|
||||||
|
|
||||||
i_obj = (php_fdfs_t *)ecalloc(1, sizeof(php_fdfs_t));
|
i_obj = (php_fdfs_t *)ecalloc(1, sizeof(php_fdfs_t));
|
||||||
|
|
||||||
zend_object_std_init(&i_obj->zo, ce TSRMLS_CC);
|
zend_object_std_init(&i_obj->zo, ce TSRMLS_CC);
|
||||||
zend_objects_store_put(&i_obj->zo);
|
handle = zend_objects_store_put(&i_obj->zo);
|
||||||
|
fprintf(stderr, "retval.handle: %d, i_obj: %p\n", handle, i_obj);
|
||||||
return &i_obj->zo;
|
return &i_obj->zo;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -7305,6 +7319,7 @@ PHP_FASTDFS_API zend_class_entry *php_fdfs_get_exception_base(int root TSRMLS_DC
|
||||||
zend_class_entry *pce;
|
zend_class_entry *pce;
|
||||||
zval *value;
|
zval *value;
|
||||||
|
|
||||||
|
fprintf(stderr, "file: "__FILE__", line: %d\n", __LINE__);
|
||||||
if (fdfs_zend_hash_find(CG(class_table), "runtimeexception",
|
if (fdfs_zend_hash_find(CG(class_table), "runtimeexception",
|
||||||
sizeof("RuntimeException"), &value) == SUCCESS)
|
sizeof("RuntimeException"), &value) == SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ static void sigSegvHandler(int signum, siginfo_t *info, void *ptr);
|
||||||
static void sigDumpHandler(int sig);
|
static void sigDumpHandler(int sig);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SCHEDULE_ENTRIES_COUNT 5
|
#define SCHEDULE_ENTRIES_COUNT 15
|
||||||
|
|
||||||
static void usage(const char *program)
|
static void usage(const char *program)
|
||||||
{
|
{
|
||||||
|
|
@ -82,6 +82,24 @@ static void usage(const char *program)
|
||||||
program);
|
program);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int counter = 0;
|
||||||
|
static int test_delay(void *args)
|
||||||
|
{
|
||||||
|
logInfo("free arg: %p, count: %d", args, --counter);
|
||||||
|
free(args);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int test_malloc(void *args)
|
||||||
|
{
|
||||||
|
int delay;
|
||||||
|
args = malloc(1024);
|
||||||
|
delay = (30L * rand()) / RAND_MAX;
|
||||||
|
logInfo("malloc arg: %p, delay: %d, count: %d", args, delay, ++counter);
|
||||||
|
sched_add_delay_task(test_delay, args, delay, true);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *conf_filename;
|
char *conf_filename;
|
||||||
|
|
@ -350,6 +368,35 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//sched_set_delay_params(0, 0);
|
||||||
|
sched_enable_delay_task();
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||||
|
scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE,
|
||||||
|
1, test_malloc, NULL);
|
||||||
|
scheduleArray.count++;
|
||||||
|
|
||||||
|
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||||
|
scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE,
|
||||||
|
1, test_malloc, NULL);
|
||||||
|
scheduleArray.count++;
|
||||||
|
|
||||||
|
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||||
|
scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE,
|
||||||
|
2, test_malloc, NULL);
|
||||||
|
scheduleArray.count++;
|
||||||
|
|
||||||
|
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||||
|
scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE,
|
||||||
|
5, test_malloc, NULL);
|
||||||
|
scheduleArray.count++;
|
||||||
|
|
||||||
|
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||||
|
scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE,
|
||||||
|
10, test_malloc, NULL);
|
||||||
|
scheduleArray.count++;
|
||||||
|
|
||||||
if ((result=sched_start(&scheduleArray, &schedule_tid, \
|
if ((result=sched_start(&scheduleArray, &schedule_tid, \
|
||||||
g_thread_stack_size, (bool * volatile)&g_continue_flag)) != 0)
|
g_thread_stack_size, (bool * volatile)&g_continue_flag)) != 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue