return true;
}
+struct immediate_perf_state {
+ pthread_mutex_t mutex;
+ struct timeval start;
+ uint64_t count;
+ bool done;
+};
+
+static void immediate_perf_handler(struct tevent_context *ev,
+ struct tevent_immediate *im,
+ void *private_data)
+{
+ struct immediate_perf_state *state = private_data;
+ int ret;
+
+#if 1
+ ret = pthread_mutex_lock(&state->mutex);
+ if (ret != 0) {
+ abort();
+ }
+
+ state->count += 1;
+
+ ret = pthread_mutex_unlock(&state->mutex);
+ if (ret != 0) {
+ abort();
+ }
+#else
+ state->count += 1;
+#endif
+ if ((state->count % 1000) == 0) {
+ struct timeval now = tevent_timeval_current();
+ struct timeval diff;
+ diff = tevent_timeval_until(&state->start, &now);
+
+ if (diff.tv_sec > 9) {
+ state->done = true;
+ return;
+ }
+ }
+
+ tevent_schedule_immediate(im, ev, immediate_perf_handler, state);
+}
+
+static bool test_event_context_immediate_perf(struct torture_context *test,
+ const void *test_data)
+{
+ const char *backend = test_data;
+ struct tevent_context *ev;
+ struct tevent_immediate *im;
+ struct immediate_perf_state state = {
+ .start = tevent_timeval_current()
+ };
+ int ret;
+
+ ret = pthread_mutex_init(&state.mutex, NULL);
+ torture_assert(test, ret == 0, "pthread_mutex_init failed");
+
+ ev = tevent_context_init_byname(test, backend);
+ if (ev == NULL) {
+ torture_comment(test, "event backend '%s' not supported\n",
+ backend);
+ return true;
+ }
+
+ torture_comment(test, "backend '%s' - %s\n", backend, __FUNCTION__);
+
+ im = tevent_create_immediate(ev);
+ torture_assert(test, im != NULL, "tevent_create_immediate failed");
+
+ tevent_schedule_immediate(im, ev, immediate_perf_handler, &state);
+
+ while (!state.done) {
+ ret = tevent_loop_once(ev);
+ torture_assert(test, ret == 0, "tevent_loop_once failed");
+ }
+
+ torture_comment(test, "count=%"PRIu64"\n", state.count);
+
+ TALLOC_FREE(ev);
+ return true;
+}
+
#ifdef HAVE_PTHREAD
static pthread_mutex_t threaded_mutex = PTHREAD_MUTEX_INITIALIZER;
return suite;
}
+
+struct torture_suite *torture_local_event_perf(TALLOC_CTX *mem_ctx)
+{
+ struct torture_suite *suite = torture_suite_create(
+ mem_ctx, "event_perf");
+
+ torture_suite_add_simple_tcase_const(suite, "immediate_perf",
+ test_event_context_immediate_perf,
+ NULL);
+
+ return suite;
+}