Commits

Ruslan Osmanov committed 05ad243

Change: moved static methods of EvLoop to global scope functions
Del: redundant file
Add: test for watcher priorities

  • Participants
  • Parent commits baf84fa

Comments (0)

Files changed (9)

 Getting rid of need to call ::start() method we skip the function call overhead!.
 
 
+Remove $loop arg from watcher class constructors, assume the default loop used.
+Make EvLoop methods for creating watchers based on special loop.
+===============================================================================
+
+
 libevent buffer functionality?
 =============================
 
 # include "fork.c"
 #endif
 
+
+/* {{{ Global functions */
+
+#define PHP_EV_FUNC_INT_VOID(name)                      \
+    PHP_FUNCTION(ev_ ## name)                           \
+    {                                                   \
+        if (zend_parse_parameters_none() == FAILURE) {  \
+            return;                                     \
+        }                                               \
+                                                        \
+        RETURN_LONG((long)ev_ ## name());               \
+    }
+
+PHP_EV_FUNC_INT_VOID(supported_backends)
+PHP_EV_FUNC_INT_VOID(recommended_backends)
+PHP_EV_FUNC_INT_VOID(embeddable_backends)
+
+/* {{{ proto void ev_feed_signal(int signum) */
+PHP_FUNCTION(ev_feed_signal)
+{
+	long signum;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &signum) == FAILURE) {
+		return;
+	}
+
+	ev_feed_signal(signum);
+}
+/* }}} */
+
+/* {{{ proto void ev_sleep(double seconds) */
+PHP_FUNCTION(ev_sleep)
+{
+	double seconds;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &seconds) == FAILURE) {
+		return;
+	}
+
+	ev_sleep(seconds);
+}
+/* }}} */
+
+/* {{{ proto double ev_time(void) */
+PHP_FUNCTION(ev_time)
+{
+    if (zend_parse_parameters_none() == FAILURE) {
+        return;
+    }
+
+    RETURN_DOUBLE((double) ev_time());
+}
+/* }}} */
+
+
+/* }}} */
+
 #endif /* HAVE_EV */
 
 /*
 
 /* ARGINFO }}} */
 
+PHP_METHOD(EvLoop, supported_backends);
+PHP_METHOD(EvLoop, recommended_backends);
+PHP_METHOD(EvLoop, embeddable_backends);
+PHP_METHOD(EvLoop, feed_signal);
 
 /* {{{ ev_functions[] */
 const zend_function_entry ev_functions[] = {
+	PHP_FE(ev_supported_backends, arginfo_ev__void)
+	PHP_FE(ev_recommended_backends, arginfo_ev__void)
+	PHP_FE(ev_embeddable_backends, arginfo_ev__void)
+	PHP_FE(ev_sleep, arginfo_ev_sleep)
+	PHP_FE(ev_time, arginfo_ev__void)
+	PHP_FE(ev_feed_signal, arginfo_ev_feed_signal)
+
 	{NULL, NULL, NULL}
 };
 /* }}} */
 	PHP_ME(EvLoop, now_update,           arginfo_ev__void,             ZEND_ACC_PUBLIC)
 	PHP_ME(EvLoop, suspend,              arginfo_ev__void,             ZEND_ACC_PUBLIC)
 	PHP_ME(EvLoop, resume,               arginfo_ev__void,             ZEND_ACC_PUBLIC)
-
-	PHP_ME(EvLoop, supported_backends,   arginfo_ev__void,             ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
-	PHP_ME(EvLoop, recommended_backends, arginfo_ev__void,             ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
-	PHP_ME(EvLoop, embeddable_backends,  arginfo_ev__void,             ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
-
-	PHP_ME(EvLoop, sleep,                arginfo_ev_sleep,             ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
-	PHP_ME(EvLoop, time,                 arginfo_ev__void,             ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
 	PHP_ME(EvLoop, now,                  arginfo_ev__void,             ZEND_ACC_PUBLIC)
-
 	PHP_ME(EvLoop, run,                  arginfo_ev_run,               ZEND_ACC_PUBLIC)
 	PHP_ME(EvLoop, break,                arginfo_ev_break,             ZEND_ACC_PUBLIC)
-	PHP_ME(EvLoop, feed_signal,          arginfo_ev_feed_signal,       ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
-	PHP_ME(EvLoop, feed_signal_event,    arginfo_ev_feed_signal_event, ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
+	PHP_ME(EvLoop, feed_signal_event,    arginfo_ev_feed_signal_event, ZEND_ACC_PUBLIC)
 
 	{ NULL, NULL, NULL }
 };
 
 #include "embed.h"
 
+PHP_FUNCTION(ev_supported_backends);
+PHP_FUNCTION(ev_recommended_backends);
+PHP_FUNCTION(ev_embeddable_backends);
+PHP_FUNCTION(ev_feed_signal);
+PHP_FUNCTION(ev_sleep);
+PHP_FUNCTION(ev_time);
+
 /* {{{ EvLoop */
 PHP_METHOD(EvLoop, __construct);
 PHP_METHOD(EvLoop, default_loop);
 PHP_METHOD(EvLoop, now_update);
 PHP_METHOD(EvLoop, suspend);
 PHP_METHOD(EvLoop, resume);
-PHP_METHOD(EvLoop, supported_backends);
-PHP_METHOD(EvLoop, recommended_backends);
-PHP_METHOD(EvLoop, embeddable_backends);
-PHP_METHOD(EvLoop, sleep);
-PHP_METHOD(EvLoop, time);
 PHP_METHOD(EvLoop, now);
 PHP_METHOD(EvLoop, run);
 PHP_METHOD(EvLoop, break);
-PHP_METHOD(EvLoop, feed_signal);
 PHP_METHOD(EvLoop, feed_signal_event);
 /* }}} */
 
 }
 /* }}} */
 
-
 /* {{{ proto EvLoop EvLoop::default_loop([int flags = EVLAG_AUTO[, callable callback = NULL[, mixed data = NULL[, double io_collect_interval = 0.[, double timeout_collect_interval = 0.]]]]])
 */
 PHP_METHOD(EvLoop, default_loop)
 PHP_EV_LOOP_METHOD_VOID(suspend)
 PHP_EV_LOOP_METHOD_VOID(resume)
 
-PHP_EV_LOOP_METHOD_INT_VOID(supported_backends)
-PHP_EV_LOOP_METHOD_INT_VOID(recommended_backends)
-PHP_EV_LOOP_METHOD_INT_VOID(embeddable_backends)
-
-/* {{{ proto void sleep(double seconds) */
-PHP_METHOD(EvLoop, sleep) 
-{
-	double seconds;
-
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &seconds) == FAILURE) {
-		return;
-	}
-
-	ev_sleep(seconds);
-}
-/* }}} */
-
-PHP_EV_LOOP_METHOD_DOUBLE_VOID(time)
-
 /* {{{ proto double EvLoop::now(void) */
 PHP_METHOD(EvLoop, now)
 {
 }
 /* }}} */
 
-/* {{{ proto void EvLoop::feed_signal(int signum) */
-PHP_METHOD(EvLoop, feed_signal)
-{
-	long signum;
-
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &signum) == FAILURE) {
-		return;
-	}
-
-	ev_feed_signal(signum);
-}
-/* }}} */
-
 /* {{{ proto void EvLoop::feed_signal_event(int signum) */
 PHP_METHOD(EvLoop, feed_signal_event)
 {

File tests/08_priority.phpt

+--TEST--
+Check for priorities
+--FILE--
+<?php 
+error_reporting(0);
+
+$loop = EvLoop::default_loop();
+
+$t0 = new EvTimer(-1, 0, $loop, function ($w, $r) use ($loop) { echo "ok 4\n"; });
+$t_ = new EvTimer(-1, 0, $loop, function ($w, $r) use ($loop) { echo "ok 5\n"; });
+$t_->priority = -1;
+$t1 = new EvTimer(-1, 0, $loop, function ($w, $r) use ($loop) { echo "ok 3\n"; });
+$t1->priority = 1;
+
+$i2 = new EvIdle($loop, function ($w, $r) use ($loop) { echo $loop->iteration == 1 ? "" : "not ", "ok 2\n"; $w->stop(); });
+$i2->priority = 10;
+$i3 = new EvIdle($loop, function ($w, $r) use ($loop) { echo $loop->iteration == 3 ? "" : "not ", "ok 7\n"; $w->stop(); });
+$i1 = new EvIdle($loop, function ($w, $r) use ($loop) { echo $loop->iteration == 2 ? "" : "not ", "ok 6\n"; $w->stop(); });
+$i1->priority = 1;
+$i_ = new EvIdle($loop, function ($w, $r) use ($loop) { echo $loop->iteration == 4 ? "" : "not ", "ok 8\n"; $w->stop(); });
+$i_->priority = -1;
+
+$t0->start();
+$t_->start();
+$t1->start();
+$i2->start();
+$i3->start();
+$i1->start();
+$i_->start();
+
+echo "ok 1\n";
+$loop->run();
+echo "ok 9\n";
+?>
+--EXPECT--
+ok 1
+ok 2
+ok 3
+ok 4
+ok 5
+ok 6
+ok 7
+ok 8
+ok 9

File tests/ev_watcher_construct_variation.sh

-#!/bin/sh
-
-/usr/lib64/php5.4/bin/php  -n -c '/home/ruslan/projects/pecl/ev/tmp-php.ini'  -d "output_handler=" -d "open_basedir=" -d "safe_mode=0" -d "disable_functions=" -d "output_buffering=Off" -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0" -d "html_errors=0" -d "track_errors=1" -d "report_memleaks=1" -d "report_zend_debug=0" -d "docref_root=" -d "docref_ext=.html" -d "error_prepend_string=" -d "error_append_string=" -d "auto_prepend_file=" -d "auto_append_file=" -d "magic_quotes_runtime=0" -d "ignore_repeated_errors=0" -d "precision=14" -d "memory_limit=128M" -d "extension_dir=/home/ruslan/projects/pecl/ev/modules/" -d "extension=ev.so" -d "session.auto_start=0" -d "zlib.output_compression=Off" -d "mbstring.func_overload=0" -f "/home/ruslan/projects/pecl/ev/tests/ev_watcher_construct_variation.php"  2>&1
 /* }}} */
 
 /* {{{ php_ev_start_watcher() */
-static void php_ev_start_watcher(ev_watcher *watcher TSRMLS_DC)
+void php_ev_start_watcher(ev_watcher *watcher TSRMLS_DC)
 {
 	switch (watcher->type) {
 		case EV_IO:
 		const zend_fcall_info *pfci, const zend_fcall_info_cache *pfcc, zval *data, int priority TSRMLS_DC);
 void php_ev_stop_watcher(ev_watcher *watcher TSRMLS_DC);
 inline void php_ev_set_watcher_priority(ev_watcher *watcher, long priority TSRMLS_DC);
+void php_ev_start_watcher(ev_watcher *watcher TSRMLS_DC);
 
 #endif /* PHP_EV_WATCHER_H */