gboolean g_attrib_cancel(GAttrib *attrib, guint id) { GList *l = NULL; struct command *cmd; GQueue *queue; if (attrib == NULL) return FALSE; queue = attrib->requests; if (queue) l = g_queue_find_custom(queue, GUINT_TO_POINTER(id), command_cmp_by_id); if (l == NULL) { queue = attrib->responses; if (!queue) return FALSE; l = g_queue_find_custom(queue, GUINT_TO_POINTER(id), command_cmp_by_id); } if (l == NULL) return FALSE; cmd = l->data; if (cmd == g_queue_peek_head(queue) && cmd->sent) cmd->func = NULL; else { g_queue_remove(queue, cmd); command_destroy(cmd); } return TRUE; }
/* * Called from the compare thread on the primary * for compare packet with secondary list of the * specified connection when a new packet was * queued to it. */ static void colo_compare_connection(void *opaque, void *user_data) { CompareState *s = user_data; Connection *conn = opaque; Packet *pkt = NULL; GList *result = NULL; int ret; while (!g_queue_is_empty(&conn->primary_list) && !g_queue_is_empty(&conn->secondary_list)) { pkt = g_queue_pop_head(&conn->primary_list); switch (conn->ip_proto) { case IPPROTO_TCP: result = g_queue_find_custom(&conn->secondary_list, pkt, (GCompareFunc)colo_packet_compare_tcp); break; case IPPROTO_UDP: result = g_queue_find_custom(&conn->secondary_list, pkt, (GCompareFunc)colo_packet_compare_udp); break; case IPPROTO_ICMP: result = g_queue_find_custom(&conn->secondary_list, pkt, (GCompareFunc)colo_packet_compare_icmp); break; default: result = g_queue_find_custom(&conn->secondary_list, pkt, (GCompareFunc)colo_packet_compare_other); break; } if (result) { ret = compare_chr_send(s, pkt->data, pkt->size, pkt->vnet_hdr_len); if (ret < 0) { error_report("colo_send_primary_packet failed"); } trace_colo_compare_main("packet same and release packet"); g_queue_remove(&conn->secondary_list, result->data); packet_destroy(pkt, NULL); } else { /* * If one packet arrive late, the secondary_list or * primary_list will be empty, so we can't compare it * until next comparison. */ trace_colo_compare_main("packet different"); g_queue_push_head(&conn->primary_list, pkt); /* TODO: colo_notify_checkpoint();*/ break; } } }
/* * Initialize modules in a sync chain. Use modules that will check * the precision of time synchronization between a group of traces. * * Args: * traceSetContext: traceset */ void setupSyncChain(LttvTracesetContext* const traceSetContext) { struct TracesetChainState* tracesetChainState; SyncState* syncState; GList* result; tracesetChainState= g_hash_table_lookup(tracesetChainStates, traceSetContext); syncState= malloc(sizeof(SyncState)); tracesetChainState->syncState= syncState; syncState->traceNb= lttv_traceset_number(traceSetContext->ts); // Statistics are always on with eval syncState->stats= true; if (optionEvalGraphs) { // Create the graph directory right away in case the module initialization // functions have something to write in it. syncState->graphsDir= optionEvalGraphsDir; syncState->graphsStream= createGraphsDir(syncState->graphsDir); } else { syncState->graphsStream= NULL; syncState->graphsDir= NULL; } syncState->reductionData= NULL; syncState->reductionModule= NULL; syncState->analysisData= NULL; result= g_queue_find_custom(&analysisModules, "eval", &gcfCompareAnalysis); syncState->analysisModule= (AnalysisModule*) result->data; syncState->analysisModule->initAnalysis(syncState); syncState->matchingData= NULL; result= g_queue_find_custom(&matchingModules, "distributor", &gcfCompareMatching); syncState->matchingModule= (MatchingModule*) result->data; syncState->matchingModule->initMatching(syncState); syncState->processingData= NULL; result= g_queue_find_custom(&processingModules, "LTTV-standard", &gcfCompareProcessing); syncState->processingModule= (ProcessingModule*) result->data; syncState->processingModule->initProcessing(syncState, traceSetContext); }
static void ToolsCorePoolCancel(guint id) { GList *taskLnk; WorkerTask *task = NULL; WorkerTask search = { id, }; g_return_if_fail(id != 0); g_mutex_lock(gState.lock); if (!gState.active) { goto exit; } taskLnk = g_queue_find_custom(gState.workQueue, &search, ToolsCorePoolCompareTask); if (taskLnk != NULL) { task = taskLnk->data; g_queue_delete_link(gState.workQueue, taskLnk); } exit: g_mutex_unlock(gState.lock); if (task != NULL) { if (task->srcId > 0) { g_source_remove(task->srcId); } else { ToolsCorePoolDestroyTask(task); } } }
/** * Add a file to the download queue, or subscribe to a file that has already * been added to the download queue. The thread waits until the file has been * downloaded. * @param fileId [in] The ID of the file in the database. * @param owner [in] User who made the cache request. * @return Nothing. * Test: unit test (test-downloadqueue.c). */ void ReceiveDownload( sqlite3_int64 fileId, uid_t owner ) { GList *subscriptionEntry; struct DownloadSubscription *subscription; pthread_mutexattr_t mutexAttr; pthread_condattr_t condAttr; /* Find out if a subscription to the same file is already queued. */ pthread_mutex_lock( &mainLoop_mutex ); subscriptionEntry = g_queue_find_custom( &downloadQueue, &fileId, FindInDownloadQueue ); /* No other subscriptions, so create one. */ if( subscriptionEntry == NULL ) { /* Create a new subscription entry. */ subscription = malloc( sizeof( struct DownloadSubscription ) ); subscription->fileId = fileId; subscription->downloadActive = false; subscription->subscribers = 1; /* Prepare wait condition and acknowledgment mutexes. */ pthread_mutexattr_init( &mutexAttr ); pthread_mutex_init( &subscription->waitMutex, &mutexAttr ); pthread_mutex_init( &subscription->acknowledgeMutex, &mutexAttr ); pthread_mutexattr_destroy( &mutexAttr ); pthread_condattr_init( &condAttr ); pthread_cond_init( &subscription->waitCond, &condAttr ); pthread_cond_init( &subscription->acknowledgeCond, &condAttr ); pthread_condattr_destroy( &condAttr ); /* Add the entry to the transfers list. */ Query_AddDownload( fileId, owner ); /* Enqueue the entry. */ g_queue_push_tail( &downloadQueue, subscription ); } /* Another thread is subscribing to the same download, so use its wait condition. */ else { /* Subscribe to the download. */ subscription = subscriptionEntry->data; subscription->subscribers++; } /* Lock the download completion mutex before the download is clear to begin. */ pthread_mutex_lock( &subscription->waitMutex ); /* Tell the download manager that a new subscription has been entered. */ pthread_cond_signal( &mainLoop_cond ); pthread_mutex_unlock( &mainLoop_mutex ); /* Wait until the download is complete. */ pthread_cond_wait( &subscription->waitCond, &subscription->waitMutex ); pthread_mutex_unlock( &subscription->waitMutex ); /* Unsubscribe from the download. */ UnsubscribeFromDownload( subscription ); }
gate_t* find_gate_from_id (GQueue *gates, int id) { if (!gates) return NULL; GList *el = g_queue_find_custom (gates, &id, (GCompareFunc)navlcm_gate_comp); if (!el) return NULL; return (gate_t*)el->data; }
void compare_later(GtkAction* action, GtkWidget* window) { GList* files = g_list_first((GList*)g_object_get_data(G_OBJECT(action), "xdiff-ext::save")); while(files) { gchar* uri; gchar* path; GList* link; uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data); path = g_filename_from_uri(uri, NULL, NULL); g_free(uri); link = g_queue_find_custom(_saved, path, (GCompareFunc)strcmp); if(link == NULL) { g_queue_push_head(_saved, path); } else { g_queue_unlink(_saved, link); g_queue_push_head_link(_saved, link); } // g_free(path) ??? files = g_list_next(files); } }
static TrackedPart * tracked_part_find (TrackedTask *task, GCompareFunc func, gconstpointer user_data) { GList *part = g_queue_find_custom (task->parts, user_data, func); return part ? part->data : NULL; }
MemoryItem *find_card_in_tux_memory(MemoryItem *card) { GList *link; if ((link = g_queue_find_custom(tux_memory, card, compare_card)) != NULL) return link->data; else return NULL; }
account_t * account_list_get_by_state(account_state_t state) { GList * c = g_queue_find_custom(accountQueue, &state, get_state_struct); if (c) return (account_t *) c->data; else return NULL; }
account_t * account_list_get_by_id(const gchar * const accountID) { g_assert(accountID); GList * c = g_queue_find_custom(accountQueue, accountID, is_accountID_struct); if (c) return (account_t *) c->data; else return NULL; }
/* * Look for old packets that the secondary hasn't matched, * if we have some then we have to checkpoint to wake * the secondary up. */ static void colo_old_packet_check(void *opaque) { CompareState *s = opaque; /* * If we find one old packet, stop finding job and notify * COLO frame do checkpoint. */ g_queue_find_custom(&s->conn_list, NULL, (GCompareFunc)colo_old_packet_check_one_conn); }
static GSignondProcessData* gsignond_plugin_proxy_find_by_session_iface ( GSignondPluginProxy *self, GSignondAuthSession *session) { g_assert (GSIGNOND_IS_PLUGIN_PROXY (self)); return (GSignondProcessData*) g_queue_find_custom ( self->priv->session_queue, session, gsignond_plugin_proxy_compare_process_data); }
bool mgmt_cancel(struct mgmt *mgmt, unsigned int id) { struct mgmt_request *request; GList *list; if (!mgmt || !id) return false; list = g_queue_find_custom(mgmt->request_queue, GUINT_TO_POINTER(id), compare_request_id); if (list) { request = list->data; g_queue_delete_link(mgmt->request_queue, list); goto done; } list = g_queue_find_custom(mgmt->reply_queue, GUINT_TO_POINTER(id), compare_request_id); if (list) { request = list->data; g_queue_delete_link(mgmt->reply_queue, list); goto done; } list = g_list_find_custom(mgmt->pending_list, GUINT_TO_POINTER(id), compare_request_id); if (!list) return false; request = list->data; mgmt->pending_list = g_list_delete_link(mgmt->pending_list, list); done: destroy_request(request, NULL); wakeup_writer(mgmt); return true; }
TEST_F(GQueueTest, findCustom) { int testData1 = 42; int testData2 = 1337; int searchData1 = testData1; int searchData2 = testData2; int searchData3 = 27; GList *list = NULL; list = g_list_append(list, &testData1); list = g_list_append(list, &testData2); queue->head = list; queue->tail = list->next->next; queue->length = 2; GList *find = g_queue_find_custom(queue, &searchData1, test_compare_int); ASSERT_EQ(list, find) << "first element should be found"; find = g_queue_find_custom(queue, &searchData2, test_compare_int); ASSERT_EQ(list->next, find) << "second element should be found"; find = g_queue_find_custom(queue, &searchData3, test_compare_int); ASSERT_TRUE(find == NULL) << "unknown element should not be found"; }
MsnTransaction * msn_history_find (MsnHistory *history, guint trId) { GList *link; link = g_queue_find_custom (history->queue, GINT_TO_POINTER (trId), check_trid); if (link) return link->data; return NULL; }
void seaf_sync_manager_cancel_sync_task (SeafSyncManager *mgr, const char *repo_id) { SyncInfo *info; SyncTask *task; GList *link; /* Cancel any pending tasks for this repo on the queue. */ link = g_queue_find_custom (mgr->sync_tasks, repo_id, compare_sync_task); if (link) { task = link->data; sync_task_free (task); g_queue_delete_link (mgr->sync_tasks, link); } /* Cancel running task. */ info = g_hash_table_lookup (mgr->sync_infos, repo_id); if (!info || !info->in_sync) return; g_assert (info->current_task != NULL); task = info->current_task; switch (task->state) { case SYNC_STATE_FETCH: seaf_transfer_manager_cancel_task (seaf->transfer_mgr, task->tx_id, TASK_TYPE_DOWNLOAD); transition_sync_state (task, SYNC_STATE_CANCEL_PENDING); break; case SYNC_STATE_UPLOAD: seaf_transfer_manager_cancel_task (seaf->transfer_mgr, task->tx_id, TASK_TYPE_UPLOAD); transition_sync_state (task, SYNC_STATE_CANCEL_PENDING); break; case SYNC_STATE_COMMIT: case SYNC_STATE_INIT: case SYNC_STATE_MERGE: transition_sync_state (task, SYNC_STATE_CANCEL_PENDING); break; case SYNC_STATE_CANCEL_PENDING: break; default: g_assert (0); } }
/* Remove all elements with the given filename */ void navqueue_remove_file(const gchar *filename) { GList *match; if (filename == NULL) return; while ((match = g_queue_find_custom(navigation_queue, filename, find_by_filename))) { g_free(match->data); g_queue_delete_link(navigation_queue, match); } adjust_buttons(); }
void qq_tray_blinking_for(QQTray *tray, const gchar *uin) { if(tray == NULL || uin == NULL){ return; } QQTrayPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE(tray, qq_tray_get_type() , QQTrayPriv); if(NULL != g_queue_find_custom(priv -> blinking_queue, uin , (GCompareFunc)g_strcmp0)){ // already blinking return; } g_queue_push_head(priv -> blinking_queue, g_strdup(uin)); qq_tray_blinking(tray, g_queue_peek_tail(priv -> blinking_queue)); }
static void entry_added_cb (RhythmDB *db, RhythmDBEntry *entry, RhythmDBImportJob *job) { const char *uri; GList *link; uri = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION); g_mutex_lock (&job->priv->lock); link = g_queue_find_custom (job->priv->processing, uri, (GCompareFunc) g_strcmp0); if (link != NULL) { const char *details; RhythmDBEntryType *entry_type; entry_type = rhythmdb_entry_get_entry_type (entry); job->priv->processed++; if (entry_type == job->priv->entry_type) { job->priv->imported++; g_signal_emit (job, signals[ENTRY_ADDED], 0, entry); } rb_debug ("got entry %s; %d imported, %d processed", uri, job->priv->imported, job->priv->processed); /* if it's an import error with missing plugins, add it to the retry list */ details = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_COMMENT); if (entry_type == job->priv->error_type && (details != NULL && details[0] != '\0')) { rb_debug ("entry %s is an import error with missing plugin details: %s", uri, details); job->priv->retry_entries = g_slist_prepend (job->priv->retry_entries, rhythmdb_entry_ref (entry)); } if (job->priv->status_changed_id == 0) { job->priv->status_changed_id = g_idle_add ((GSourceFunc) emit_status_changed, job); } g_queue_delete_link (job->priv->processing, link); maybe_start_more (job); } g_mutex_unlock (&job->priv->lock); }
static void add_merge_task (const char *repo_id) { MergeTask *task = g_new0 (MergeTask, 1); seaf_debug ("Add merge task for repo %.8s.\n", repo_id); memcpy (task->repo_id, repo_id, 36); pthread_mutex_lock (&scheduler->q_lock); if (g_queue_find_custom (scheduler->queue, task, task_cmp) != NULL) { seaf_debug ("Task for repo %.8s is already queued.\n", repo_id); g_free (task); } else g_queue_push_tail (scheduler->queue, task); pthread_mutex_unlock (&scheduler->q_lock); }
static int colo_old_packet_check_one_conn(Connection *conn, void *user_data) { GList *result = NULL; int64_t check_time = REGULAR_PACKET_CHECK_MS; result = g_queue_find_custom(&conn->primary_list, &check_time, (GCompareFunc)colo_old_packet_check_one); if (result) { /* Do checkpoint will flush old packet */ /* * TODO: Notify colo frame to do checkpoint. * colo_compare_inconsistent_notify(); */ return 0; } return 1; }
int call_common_active_call_remove(int id) { struct CallActiveViewData *win = NULL; if (active_calls_list) { GList *link = g_queue_find_custom(active_calls_list, id, _queue_find_by_id); win = g_queue_peek_nth(active_calls_list, g_queue_link_index(active_calls_list, link)); g_queue_delete_link(active_calls_list, link); } /* if we haven't found abort */ if (!win) { g_debug("%s:%d no such id! was it active? (id=%d)", __FILE__, __LINE__, id); return 1; } g_debug("%s:%d removing a call from active list (id=%d)", __FILE__, __LINE__, win->parent.id); /* if was active, get a new active */ if (win->state == CALL_STATE_ACTIVE) { win = g_queue_peek_head(active_calls_list); if (win) { call_common_activate_call(win); } } if (g_queue_get_length(active_calls_list) == 0) { g_debug("Freed active calls list"); g_queue_free(active_calls_list); active_calls_list = NULL; call_common_set_sound_state(CALL_SOUND_STATE_CLEAR); } return 0; }
int __ofono_sms_txq_cancel(struct ofono_sms *sms, const struct ofono_uuid *uuid) { GList *l; struct tx_queue_entry *entry; l = g_queue_find_custom(sms->txq, uuid, entry_compare_by_uuid); if (l == NULL) return -ENOENT; entry = l->data; if (entry == g_queue_peek_head(sms->txq)) { /* * Fail if any pdu was already transmitted or if we are * waiting the answer from driver. */ if (entry->cur_pdu > 0) return -EPERM; if (sms->flags & MESSAGE_MANAGER_FLAG_TXQ_ACTIVE) return -EPERM; /* * Make sure we don't call tx_next() if there are no entries * and that next entry doesn't have to wait a 'retry time' * from this one. */ if (sms->tx_source) { g_source_remove(sms->tx_source); sms->tx_source = 0; if (g_queue_get_length(sms->txq) > 1) sms->tx_source = g_timeout_add(0, tx_next, sms); } } sms_tx_queue_remove_entry(sms, l, MESSAGE_STATE_CANCELLED); return 0; }
int __ofono_sms_txq_set_submit_notify(struct ofono_sms *sms, struct ofono_uuid *uuid, ofono_sms_txq_submit_cb_t cb, void *data, ofono_destroy_func destroy) { GList *l; struct tx_queue_entry *entry = g_queue_peek_tail(sms->txq); if (memcmp(&entry->uuid, uuid, sizeof(entry->uuid))) { l = g_queue_find_custom(sms->txq, uuid, entry_compare_by_uuid); if (l == NULL) return -ENOENT; entry = l->data; } tx_queue_entry_set_submit_notify(entry, cb, data, destroy); return 0; }
gboolean g_obex_cancel_req(GObex *obex, guint req_id, gboolean remove_callback) { GList *match; struct pending_pkt *p; if (obex->pending_req && obex->pending_req->id == req_id) { if (!g_obex_pending_req_abort(obex, NULL)) { p = obex->pending_req; obex->pending_req = NULL; goto immediate_completion; } if (remove_callback) obex->pending_req->rsp_func = NULL; return TRUE; } match = g_queue_find_custom(obex->tx_queue, GUINT_TO_POINTER(req_id), pending_pkt_cmp); if (match == NULL) return FALSE; p = match->data; g_queue_delete_link(obex->tx_queue, match); immediate_completion: p->cancelled = TRUE; p->obex = g_obex_ref(obex); if (remove_callback || p->rsp_func == NULL) pending_pkt_free(p); else g_idle_add(cancel_complete, p); return TRUE; }
/// Append a ResourceCmd to a ResourceQueue FSTATIC gboolean _resource_queue_cmd_append(ResourceQueue* self, ResourceCmd* cmd , ResourceCmdCallback cb, gpointer user_data) { GQueue* q; RscQElem* qelem; gint64 requestid; requestid = cmd->request->getint(cmd->request, REQIDENTIFIERNAMEFIELD); if (requestid <= 0) { g_warning("%s.%d: Request rejected - no request id for resource %s." , __FUNCTION__, __LINE__, cmd->resourcename); return FALSE; } q = g_hash_table_lookup(self->resources, cmd->resourcename); if (NULL == q) { q = g_queue_new(); g_hash_table_insert(self->resources, g_strdup(cmd->resourcename), q); } qelem = _resource_queue_qelem_new(cmd, self, cb, user_data, q); cmd->user_data = qelem; qelem->requestid = requestid; if (g_queue_find_custom(q, qelem, _queue_compare_requestid)) { // This can happen if the CMA crashes and restarts and for other reasons. // But we shouldn't obey it in any case... g_info("%s:%d: Duplicate request id ["FMT_64BIT"d] for resource %s - ignored." , __FUNCTION__, __LINE__, requestid, cmd->resourcename); _resource_queue_qelem_finalize(qelem); qelem = NULL; return FALSE; } g_queue_push_tail(q, qelem); if (self->timerid < 0) { self->timerid = g_timeout_add_seconds(1, _resource_queue_runqueue, self); } return TRUE; }
gboolean g_attrib_cancel(GAttrib *attrib, guint id) { GList *l; struct command *cmd; if (attrib == NULL || attrib->queue == NULL) return FALSE; l = g_queue_find_custom(attrib->queue, GUINT_TO_POINTER(id), command_cmp_by_id); if (l == NULL) return FALSE; cmd = l->data; if (cmd == g_queue_peek_head(attrib->queue) && cmd->sent) cmd->func = NULL; else { g_queue_remove(attrib->queue, cmd); command_destroy(cmd); } return TRUE; }
static ClosedTab * find_tab_with_notebook (GQueue *queue, EphyNotebook *notebook) { GList *item = g_queue_find_custom (queue, notebook, (GCompareFunc)compare_func); return item ? (ClosedTab*)item->data : NULL; }