__export void hm_watch_ref(HmWatch *watch) { G_ASSERT(watch != NULL); g_source_ref((GSource*)watch); }
static void server_callback (SoupServer *server, SoupMessage *msg, const char *path, GHashTable *query, SoupClientContext *context, gpointer data) { SlowData *sd; if (msg->method != SOUP_METHOD_GET) { soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED); return; } soup_message_set_status (msg, SOUP_STATUS_OK); if (!strcmp (path, "/fast")) { soup_message_set_response (msg, "text/plain", SOUP_MEMORY_STATIC, "OK\r\n", 4); return; } soup_message_headers_set_encoding (msg->response_headers, SOUP_ENCODING_CHUNKED); g_object_ref (msg); soup_server_pause_message (server, msg); sd = g_new (SlowData, 1); sd->server = server; sd->msg = msg; sd->timeout = soup_add_timeout ( g_main_context_get_thread_default (), 200, add_body_chunk, sd); g_source_ref (sd->timeout); g_signal_connect (msg, "finished", G_CALLBACK (request_finished), sd); }
GdkMirWindowReference * _gdk_mir_event_source_get_window_reference (GdkWindow *window) { static GQuark win_ref_quark; GdkMirWindowReference *ref; if G_UNLIKELY (!win_ref_quark) win_ref_quark = g_quark_from_string ("GdkMirEventSource window reference"); ref = g_object_get_qdata (G_OBJECT (window), win_ref_quark); if (!ref) { GdkMirEventSource *source; source = _gdk_mir_display_get_event_source (gdk_window_get_display (window)); g_source_ref ((GSource *) source); ref = g_slice_new (GdkMirWindowReference); ref->window = window; ref->source = source; ref->ref_count = 0; g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &ref->window); g_object_set_qdata_full (G_OBJECT (window), win_ref_quark, ref, (GDestroyNotify) _gdk_mir_window_reference_unref); } g_atomic_int_inc (&ref->ref_count); return ref; }
static gboolean ik_source_check (GSource *source) { static int prev_pending = 0, pending_count = 0; /* We already disabled the PollFD or * nothing to be read from inotify */ if (!ik_poll_fd_enabled || !(ik_poll_fd.revents & G_IO_IN)) return FALSE; if (pending_count < MAX_PENDING_COUNT) { unsigned int pending; if (ioctl (inotify_instance_fd, FIONREAD, &pending) == -1) goto do_read; pending /= AVERAGE_EVENT_SIZE; /* Don't wait if the number of pending events is too close * to the maximum queue size. */ if (pending > PENDING_THRESHOLD (MAX_QUEUED_EVENTS)) goto do_read; /* With each successive iteration, the minimum rate for * further sleep doubles. */ if (pending-prev_pending < PENDING_MARGINAL_COST (pending_count)) goto do_read; prev_pending = pending; pending_count++; /* We are going to wait to read the events: */ /* Remove the PollFD from the source */ g_source_remove_poll (source, &ik_poll_fd); /* To avoid threading issues we need to flag that we've done that */ ik_poll_fd_enabled = FALSE; /* Set a timeout to re-add the PollFD to the source */ g_source_ref (source); g_timeout_add (TIMEOUT_MILLISECONDS, ik_source_timeout, source); return FALSE; } do_read: /* We are ready to read events from inotify */ prev_pending = 0; pending_count = 0; return TRUE; }
amglue_Source * amglue_source_new( GSource *gsrc, GSourceFunc callback) { amglue_Source *src = g_new0(amglue_Source, 1); g_source_ref(gsrc); src->src = gsrc; src->callback = callback; src->state = AMGLUE_SOURCE_NEW; src->refcount = 1; g_dataset_id_set_data(gsrc, AMGLUE_SOURCE_QUARK, (gpointer)src); return src; }
GSource *qio_channel_add_watch_source(QIOChannel *ioc, GIOCondition condition, QIOChannelFunc func, gpointer user_data, GDestroyNotify notify, GMainContext *context) { GSource *source; guint id; id = qio_channel_add_watch_full(ioc, condition, func, user_data, notify, context); source = g_main_context_find_source_by_id(context, id); g_source_ref(source); return source; }
/* {{{ proto void \Glib\Source->__construct() Creates a new source and implicitly calls start on it, so you don't have to call start */ PHP_METHOD(GlibSource, __construct) { if (zend_parse_parameters_none_throw() == FAILURE) { return; } // we put the zval in the php_glib_source and shake it all up glib_source_object * source_object = Z_GLIB_SOURCE_P(getThis()); source_object->source = g_source_new(&php_glib_source_funcs, sizeof(GPhpSource)); source_object->source = g_source_ref(source_object->source); source_object->is_php_source = TRUE; GPhpSource *gsource = (GPhpSource *)source_object->source; // copy our zval into our internal struct, return with getContext ZVAL_COPY(&gsource->source_zval, getThis()); zval_add_ref(&gsource->source_zval); zval_add_ref(&gsource->source_zval); }
static void g_fam_file_monitor_start (GLocalFileMonitor *local_monitor, const gchar *dirname, const gchar *basename, const gchar *filename, GFileMonitorSource *source) { GFamFileMonitor *gffm = G_FAM_FILE_MONITOR (local_monitor); g_mutex_lock (&fam_lock); g_assert (fam_initialised); g_source_ref ((GSource *) source); if (dirname) FAMMonitorDirectory (&fam_connection, dirname, &gffm->request, source); else FAMMonitorFile (&fam_connection, filename, &gffm->request, source); g_mutex_unlock (&fam_lock); }
static gboolean port_check(GSource *source) { PSource *pn = (PSource *)source; uint_t nget; if (pn->pending) { pn->pending = FALSE; g_source_add_poll(source, PGPFD(source)); g_source_unref(source); return FALSE; } if (!(PGPFD(pn)->revents & G_IO_IN)) return FALSE; if (port_getn(PGPFD(source)->fd, NULL, 0, &nget, 0) == 0) { if (nget - pn->pending_events > EXPECT_INC_EVENTS(pn)) { /* Sleep for a while. */ pn->pending_events = nget; pn->event_growing_factor ++; pn->pending = TRUE; g_source_ref(source); g_source_remove_poll(source, PGPFD(source)); g_timeout_add(SLEEP_BASE_TIME, (GSourceFunc)port_check, (gpointer)pn); return FALSE; } } pn->pending_events = 0; pn->event_growing_factor = 0; return TRUE; }
void main_loop_test() { GMainContext *default_context; int depth; int id; GTimeVal time ={0,}; int user_data = 0,fd_data = 0; GPollFD pollfd; GSource *source3; GSourceFuncs SourceFuncs = { prepare, check, dispatch, NULL }; GSourceFuncs fd_SourceFuncs = { fd_prepare, fd_check, fd_dispatch, NULL }; e1_complete = FALSE; e2_complete = FALSE; pipe(fd); pollfd.fd = fd[0]; pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR; pollfd.revents = 0; pthread_create(&thread1, NULL, thread_function, NULL); context = g_main_context_new(); //g_main_context_add_poll(context,&pollfd,0); source1 = g_source_new(&SourceFuncs,sizeof(GSource)); g_source_set_callback(source1,(GSourceFunc)my_callback,&user_data,NULL); id = g_source_attach(source1,context); g_assert(g_source_get_id(source1) == id); g_source_set_priority(source1,0); g_assert(g_source_get_priority(source1) == 0); loop = g_main_loop_new(context, FALSE); default_context = g_main_loop_get_context(loop); //checks g_main_loop_get_context g_assert(default_context == context); //checks g_main_loop_is_running g_assert(g_main_loop_is_running(loop) == FALSE); depth = g_main_depth(); //checks g_main_depth g_assert(depth == 0); g_source_get_current_time(source1,&time); g_assert(time.tv_usec > 0); g_source_set_can_recurse(source1,TRUE); g_assert(g_source_get_can_recurse(source1) == TRUE); source2 = g_source_new(&fd_SourceFuncs,sizeof(GSource)); g_source_set_callback(source2,(GSourceFunc)fd_callback,&fd_data,NULL); g_source_add_poll(source2,&pollfd); g_source_remove_poll(source2,&pollfd); // checks g_source_remove_poll g_assert(source2->poll_fds == NULL); g_source_add_poll(source2,&pollfd); // checks whether g_source_add_poll is successful. // one more check is done in fd_callback. // If that function is callled we are sure that add poll was successful g_assert(source2->poll_fds->data == &pollfd); source3 = g_source_ref(source2); g_assert(source3 == source2 && source2->ref_count == 2); g_source_unref(source3); id = g_source_attach(source2,context); //checks g_main_context_pending g_assert(g_main_context_pending(context)); g_main_loop_run(loop); // ref is called here. Thats why two unrefs are called. If the 2nd unref is // callled with the unref, code should crash g_main_loop_ref(loop); g_main_loop_unref(loop); g_main_loop_unref(loop); //checks the number of times the call back function is called g_assert(user_data == 100); // checks whether set poll was successful and call back for the same // was called g_assert(fd_data == 1); }
template <> GSource* refGPtr(GSource* ptr) { if (ptr) g_source_ref(ptr); return ptr; }
void aio_context_ref(AioContext *ctx) { g_source_ref(&ctx->source); }
GSource *aio_get_g_source(AioContext *ctx) { g_source_ref(&ctx->source); return &ctx->source; }
/** * _gcr_gnupg_process_run_async: * @self: The process * @argv: (array zero-terminated=1): The arguments for the process, not including executable, terminated with %NULL. * @envp: (allow-none) (array zero-terminated=1): The environment for new process, terminated with %NULL. * @flags: Flags for starting the process. * @cancellable: (allow-none): Cancellation object * @callback: Will be called when operation completes. * @user_data: (closure): Data passed to callback. * * Run the gpg process. Only one 'run' operation can run per GcrGnupgProcess * object. The GcrGnupgProcess:output_data and GcrGnupgProcess:error_line * signals will be emitted when data is received from the gpg process. * * Unless the %GCR_GNUPG_PROCESS_RESPECT_LOCALE flag is specified, the process * will be run in the 'C' locale. If the %GCR_GNUPG_PROCESS_WITH_STATUS or * %GCR_GNUPG_PROCESS_WITH_ATTRIBUTES flags are set, then the gpg process * will be status and attribute output respectively. The * GcrGnupgProcess:status_record and GcrGnupgProcess:attribute_data signals * will provide this data. */ void _gcr_gnupg_process_run_async (GcrGnupgProcess *self, const gchar **argv, const gchar **envp, GcrGnupgProcessFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GError *error = NULL; GPtrArray *args; GPtrArray *envs; int child_fds[NUM_FDS]; int status_fds[2] = { -1, -1 }; int attribute_fds[2] = { -1, -1 }; int output_fd = -1; int error_fd = -1; int input_fd = -1; GnupgSource *gnupg_source; GSource *source; GPid pid; guint i; g_return_if_fail (GCR_IS_GNUPG_PROCESS (self)); g_return_if_fail (argv); g_return_if_fail (callback); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); g_return_if_fail (self->pv->running == FALSE); g_return_if_fail (self->pv->complete == FALSE); g_return_if_fail (self->pv->executable); self->pv->async_callback = callback; self->pv->user_data = user_data; for (i = 0; i < NUM_FDS; i++) child_fds[i] = -1; /* The command needs to be updated with these status and attribute fds */ args = g_ptr_array_new_with_free_func (g_free); g_ptr_array_add (args, g_strdup (self->pv->executable)); /* Spawn/child will close all other attributes, besides thesthose in child_fds */ child_fds[FD_INPUT] = 0; child_fds[FD_OUTPUT] = 1; child_fds[FD_ERROR] = 2; if (flags & GCR_GNUPG_PROCESS_WITH_STATUS) { if (pipe (status_fds) < 0) g_return_if_reached (); child_fds[FD_STATUS] = status_fds[1]; g_ptr_array_add (args, g_strdup ("--status-fd")); g_ptr_array_add (args, g_strdup_printf ("%d", child_fds[FD_STATUS])); } if (flags & GCR_GNUPG_PROCESS_WITH_ATTRIBUTES) { if (pipe (attribute_fds) < 0) g_return_if_reached (); child_fds[FD_ATTRIBUTE] = attribute_fds[1]; g_ptr_array_add (args, g_strdup ("--attribute-fd")); g_ptr_array_add (args, g_strdup_printf ("%d", child_fds[FD_ATTRIBUTE])); } if (self->pv->directory) { g_ptr_array_add (args, g_strdup ("--homedir")); g_ptr_array_add (args, g_strdup (self->pv->directory)); } /* All the remaining arguments */ for (i = 0; argv[i] != NULL; i++) g_ptr_array_add (args, g_strdup (argv[i])); g_ptr_array_add (args, NULL); envs = g_ptr_array_new (); for (i = 0; envp && envp[i] != NULL; i++) { if (flags & GCR_GNUPG_PROCESS_RESPECT_LOCALE || !g_str_has_prefix (envp[i], "LOCALE=")) g_ptr_array_add (envs, (gpointer)envp[i]); } if (!(flags & GCR_GNUPG_PROCESS_RESPECT_LOCALE)) g_ptr_array_add (envs, (gpointer)"LOCALE=C"); g_ptr_array_add (envs, NULL); gchar *command = g_strjoinv (" ", (gchar**)args->pdata); gchar *environ = g_strjoinv (", ", (gchar**)envs->pdata); g_debug ("running command: %s", command); g_debug ("process environment: %s", environ); g_free (command); g_free (environ); g_spawn_async_with_pipes (self->pv->directory, (gchar**)args->pdata, (gchar**)envs->pdata, G_SPAWN_DO_NOT_REAP_CHILD, on_gnupg_process_child_setup, child_fds, &pid, &input_fd, &output_fd, &error_fd, &error); g_ptr_array_free (args, TRUE); g_ptr_array_free (envs, TRUE); /* Close 'wrong' ends of extra file descriptors */ close_fd (&(status_fds[1])); close_fd (&(attribute_fds[1])); self->pv->complete = FALSE; self->pv->running = TRUE; if (error) { close_fd (&(status_fds[0])); close_fd (&(attribute_fds[0])); g_assert (!self->pv->error); self->pv->error = error; complete_run_process (self); run_async_ready_callback_later (self); return; } g_debug ("process started: %d", (int)pid); source = g_source_new (&gnupg_source_funcs, sizeof (GnupgSource)); /* Initialize the source */ gnupg_source = (GnupgSource*)source; for (i = 0; i < NUM_FDS; i++) gnupg_source->polls[i].fd = -1; gnupg_source->error_buf = g_string_sized_new (128); gnupg_source->status_buf = g_string_sized_new (128); gnupg_source->process = g_object_ref (self); gnupg_source->child_pid = pid; gnupg_source->polls[FD_INPUT].fd = input_fd; if (input_fd >= 0) { gnupg_source->polls[FD_INPUT].events = G_IO_HUP | G_IO_OUT; g_source_add_poll (source, &gnupg_source->polls[FD_INPUT]); } gnupg_source->polls[FD_OUTPUT].fd = output_fd; if (output_fd >= 0) { gnupg_source->polls[FD_OUTPUT].events = G_IO_HUP | G_IO_IN; g_source_add_poll (source, &gnupg_source->polls[FD_OUTPUT]); } gnupg_source->polls[FD_ERROR].fd = error_fd; if (error_fd >= 0) { gnupg_source->polls[FD_ERROR].events = G_IO_HUP | G_IO_IN; g_source_add_poll (source, &gnupg_source->polls[FD_ERROR]); } gnupg_source->polls[FD_STATUS].fd = status_fds[0]; if (status_fds[0] >= 0) { gnupg_source->polls[FD_STATUS].events = G_IO_HUP | G_IO_IN; g_source_add_poll (source, &gnupg_source->polls[FD_STATUS]); } gnupg_source->polls[FD_ATTRIBUTE].fd = attribute_fds[0]; if (attribute_fds[0] >= 0) { gnupg_source->polls[FD_ATTRIBUTE].events = G_IO_HUP | G_IO_IN; g_source_add_poll (source, &gnupg_source->polls[FD_ATTRIBUTE]); } if (cancellable) { gnupg_source->cancellable = g_object_ref (cancellable); gnupg_source->cancel_sig = g_cancellable_connect (cancellable, G_CALLBACK (on_cancellable_cancelled), g_source_ref (source), (GDestroyNotify)g_source_unref); } g_assert (self->pv->source_sig == 0); g_source_set_callback (source, unused_callback, NULL, NULL); self->pv->source_sig = g_source_attach (source, g_main_context_default ()); /* This assumes the outstanding reference to source */ g_assert (gnupg_source->child_sig == 0); gnupg_source->child_sig = g_child_watch_add_full (G_PRIORITY_DEFAULT, pid, on_gnupg_process_child_exited, g_source_ref (source), (GDestroyNotify)g_source_unref); /* source is unreffed in complete_if_source_is_done() */ }