static void throttle_unregister(liThrottlePoolWorkerState *pwstate, liThrottlePoolState *pstate) { if (NULL != pstate->pool_link.data) { g_queue_unlink(&pwstate->waiting, &pstate->pool_link); pstate->pool_link.data = NULL; g_atomic_int_add((gint*) &pwstate->connections, -1); } }
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); } }
void nautilus_thumbnail_prioritize (const char *file_uri) { GList *node; #ifdef DEBUG_THUMBNAILS g_message ("(Prioritize) Locking mutex\n"); #endif pthread_mutex_lock (&thumbnails_mutex); /********************************* * MUTEX LOCKED *********************************/ if (thumbnails_to_make_hash) { node = g_hash_table_lookup (thumbnails_to_make_hash, file_uri); if (node && node->data != currently_thumbnailing) { g_queue_unlink ((GQueue *)&thumbnails_to_make, node); g_queue_push_head_link ((GQueue *)&thumbnails_to_make, node); } } /********************************* * MUTEX UNLOCKED *********************************/ #ifdef DEBUG_THUMBNAILS g_message ("(Prioritize) Unlocking mutex\n"); #endif pthread_mutex_unlock (&thumbnails_mutex); }
/* not every context has srv ready, extract from context instead */ static void mc_ctx_release(liServer *_srv, gpointer param) { memcached_ctx *ctx = param; liServer *srv; guint i; UNUSED(_srv); if (NULL == ctx) return; srv = ctx->srv; assert(g_atomic_int_get(&ctx->refcount) > 0); if (!g_atomic_int_dec_and_test(&ctx->refcount)) return; if (ctx->worker_client_ctx) { for (i = 0; i < srv->worker_count; i++) { li_memcached_con_release(ctx->worker_client_ctx[i]); } g_slice_free1(sizeof(liMemcachedCon*) * srv->worker_count, ctx->worker_client_ctx); } li_sockaddr_clear(&ctx->addr); li_pattern_free(ctx->pattern); li_action_release(srv, ctx->act_found); li_action_release(srv, ctx->act_miss); if (ctx->mconf_link.data) { /* still in LI_SERVER_INIT */ memcached_config *mconf = ctx->p->data; g_queue_unlink(&mconf->prepare_ctx, &ctx->mconf_link); ctx->mconf_link.data = NULL; } ctx->srv = NULL; g_slice_free(memcached_ctx, ctx); }
void sql_reserved_query_move_to_tail(sql_reserved_query *srq, reserved_query_item *rqi) { GList *to_tail = rqi->list_pos; GQueue *gq = NULL; reserved_query_item *rm_rqi = NULL; int ret = 0; if (srq == NULL || to_tail == NULL) return; ret = g_queue_link_index(srq->gq_reserved_long_query, to_tail); gq = (ret != -1) ? (srq->gq_reserved_long_query) : (srq->gq_reserved_short_query); if (g_queue_get_length(gq) == 0) return ; if (to_tail != gq->tail) { g_queue_unlink(gq, to_tail); g_queue_push_tail_link(gq, to_tail); rqi->list_pos = g_queue_peek_tail_link(gq); } #ifdef FILTER_DEBUG g_queue_travel(srq->gq_reserved_long_query); g_queue_travel(srq->gq_reserved_short_query); #endif return ; }
TEST_F(GQueueTest, unlink) { int testData1 = 42; int testData2 = 1337; int testData3 = 27; g_queue_push_tail(queue, &testData1); g_queue_push_tail(queue, &testData2); g_queue_push_tail(queue, &testData3); GList *middle = queue->head->next; g_queue_unlink(queue, middle); ASSERT_EQ(&testData2, middle->data) << "unlinked queue head should have correct value"; ASSERT_TRUE(middle->next == NULL) << "unlinked queue head should not have a next element"; ASSERT_TRUE(middle->prev == NULL) << "unlinked queue head should not have a next element"; ASSERT_TRUE(queue->head != NULL) << "queue head should not be NULL after removing one element"; ASSERT_NE(queue->head, queue->tail) << "queue tail should not be equal to head after removing one element"; ASSERT_EQ(&testData1, queue->head->data) << "queue head data should be set correctly"; ASSERT_EQ(queue->tail, queue->head->next) << "queue head element next should be tail"; ASSERT_TRUE(queue->head->prev == NULL) << "queue head should not have a previous element"; ASSERT_EQ(&testData3, queue->tail->data) << "queue tail data should be set correctly"; ASSERT_EQ(queue->head, queue->tail->prev) << "queue tail element previous should be head"; ASSERT_TRUE(queue->tail->next == NULL) << "queue tail should not have a next element"; ASSERT_EQ(2, queue->length) << "queue should have one element left after unlinking one"; }
static void destroy_frame_callback (struct wl_resource *callback_resource) { CoglandFrameCallback *callback = callback_resource->data; g_queue_unlink (&callback->compositor->frame_callbacks, &callback->node); g_slice_free (CoglandFrameCallback, callback); }
/** * g_queue_delete_link: * @queue: a #GQueue * @link_: a #GList link that <emphasis>must</emphasis> be part of @queue * * Removes @link_ from @queue and frees it. * * @link_ must be part of @queue. * * Since: 2.4 **/ void g_queue_delete_link (GQueue *queue, GList *link_) { g_return_if_fail (queue != NULL); g_return_if_fail (link_ != NULL); g_queue_unlink (queue, link_); g_list_free (link_); }
void li_job_stop(liJob *job) { if (NULL != job->link.data) { liJobQueue *jq = job->link.data; g_queue_unlink(&jq->queue, &job->link); job->link.data = NULL; } if (NULL != job->ref) { job->ref->job = NULL; li_job_ref_release(job->ref); job->ref = NULL; } }
// retrieve file buffer from local storage // if success == TRUE then "buf" contains "size" bytes of data void cache_mng_retrieve_file_buf (CacheMng *cmng, fuse_ino_t ino, size_t size, off_t off, cache_mng_on_retrieve_file_buf_cb on_retrieve_file_buf_cb, void *ctx) { struct _CacheContext *context; struct _CacheEntry *entry; context = cache_context_create (size, ctx); context->cb.retrieve_cb = on_retrieve_file_buf_cb; entry = g_hash_table_lookup (cmng->h_entries, GUINT_TO_POINTER (ino)); if (entry && range_contain (entry->avail_range, off, off + size)) { int fd; ssize_t res; char path[PATH_MAX]; if (ino != entry->ino) { LOG_err (CMNG_LOG, "Requested inode doesn't match hashed key!"); if (context->cb.retrieve_cb) context->cb.retrieve_cb (NULL, 0, FALSE, context->user_ctx); cache_context_destroy (context); return; } cache_mng_file_name (cmng, path, sizeof (path), ino); fd = open (path, O_RDONLY); context->buf = g_malloc (size); res = pread (fd, context->buf, size, off); close (fd); context->success = (res == (ssize_t) size); if (!context->success) { g_free (context->buf); context->buf = NULL; } // move entry to the front of q_lru g_queue_unlink (cmng->q_lru, entry->ll_lru); g_queue_push_head_link (cmng->q_lru, entry->ll_lru); } else { LOG_debug (CMNG_LOG, "Entry isn't found or doesn't contain requested range: %"INO_FMT, INO ino); } context->ev = event_new (application_get_evbase (cmng->app), -1, 0, cache_read_cb, context); // fire this event at once event_active (context->ev, 0, 0); event_add (context->ev, NULL); }
/** * g_queue_pop_nth_link: * @queue: a #GQueue * @n: the link's position * * Removes and returns the link at the given position. * * Return value: The @n'th link, or %NULL if @n is off the end of @queue. * * Since: 2.4 **/ GList* g_queue_pop_nth_link (GQueue *queue, guint n) { GList *link; g_return_val_if_fail (queue != NULL, NULL); if (n >= queue->length) return NULL; link = g_queue_peek_nth_link (queue, n); g_queue_unlink (queue, link); return link; }
void li_job_now(liJobQueue *jq, liJob *job) { if (job->generation != jq->generation) { job->generation = jq->generation; /* unqueue if queued */ if (NULL != job->link.data) { assert(jq == job->link.data); g_queue_unlink(&jq->queue, &job->link); job->link.data = NULL; } job->callback(job); } else { li_job_later(jq, job); } }
void li_job_clear(liJob *job) { if (NULL != job->link.data) { liJobQueue *jq = job->link.data; g_queue_unlink(&jq->queue, &job->link); job->link.data = NULL; } job->generation = 0; if (NULL != job->ref) { job->ref->job = NULL; li_job_ref_release(job->ref); job->ref = NULL; } job->callback = NULL; }
int pgm_rxw_pkt_state_unlink ( pgm_rxw_t* r, pgm_rxw_packet_t* rp ) { ASSERT_RXW_BASE_INVARIANT(r); g_assert ( rp != NULL ); /* remove from state queues */ GQueue* queue = NULL; switch (rp->state) { case PGM_PKT_BACK_OFF_STATE: queue = r->backoff_queue; break; case PGM_PKT_WAIT_NCF_STATE: queue = r->wait_ncf_queue; break; case PGM_PKT_WAIT_DATA_STATE: queue = r->wait_data_queue; break; case PGM_PKT_HAVE_DATA_STATE: case PGM_PKT_HAVE_PARITY_STATE: case PGM_PKT_COMMIT_DATA_STATE: case PGM_PKT_PARITY_DATA_STATE: case PGM_PKT_LOST_DATA_STATE: break; default: g_critical ("rp->state = %i", rp->state); g_assert_not_reached(); break; } if (queue) { #ifdef RXW_DEBUG guint original_length = queue->length; #endif g_queue_unlink (queue, &rp->link_); rp->link_.prev = rp->link_.next = NULL; #ifdef RXW_DEBUG g_assert (queue->length == original_length - 1); #endif } rp->state = PGM_PKT_ERROR_STATE; ASSERT_RXW_BASE_INVARIANT(r); return PGM_RXW_OK; }
void li_job_reset(liJob *job) { if (NULL != job->link.data) { liJobQueue *jq = job->link.data; g_queue_unlink(&jq->queue, &job->link); job->link.data = NULL; } job->generation = 0; if (NULL != job->ref) { /* keep it if refcount == 1, as we are the only reference then */ if (1 < g_atomic_int_get(&job->ref->refcount)) { li_job_ref_release(job->ref); job->ref = NULL; } } }
int main(int argc, char** argv) { GQueue* q = g_queue_new(); g_queue_push_tail(q, "Alice "); g_queue_push_tail(q, "Bob "); g_queue_push_tail(q, "Fred "); g_queue_push_tail(q, "Jim "); printf("Starting out, the queue is: "); g_queue_foreach(q, (GFunc)printf, NULL); GList* fred_link = g_queue_peek_nth_link(q, 2); printf("\nThe link at index 2 contains %s\n", fred_link->data); g_queue_unlink(q, fred_link); g_list_free(fred_link); GList* jim_link = g_queue_peek_nth_link(q, 2); printf("Now index 2 contains %s\n", jim_link->data); g_queue_delete_link(q, jim_link); printf("Now the queue is: "); g_queue_foreach(q, (GFunc)printf, NULL); g_queue_free(q); return 0; }
// entry must be unreffed when the caller is done with the data void *_openslide_cache_get(struct _openslide_cache *cache, void *plane, int64_t x, int64_t y, struct _openslide_cache_entry **_entry) { // lock g_mutex_lock(cache->mutex); // create key struct _openslide_cache_key key = { .plane = plane, .x = x, .y = y }; // lookup key, maybe return NULL struct _openslide_cache_value *value = g_hash_table_lookup(cache->hashtable, &key); if (value == NULL) { g_mutex_unlock(cache->mutex); *_entry = NULL; return NULL; } // if found, move to front of list GList *link = value->link; g_queue_unlink(cache->list, link); g_queue_push_head_link(cache->list, link); // acquire entry reference for the caller struct _openslide_cache_entry *entry = value->entry; g_atomic_int_inc(&entry->refcount); //g_debug("cache hit! %p %p %"PRId64" %"PRId64, (void *) entry, (void *) plane, x, y); // unlock g_mutex_unlock(cache->mutex); // return data *_entry = entry; return entry->data; }
static void lua_config_free(liServer *srv, gpointer param) { lua_config *conf = (lua_config*) param; UNUSED(srv); if (conf->worker_config) { lua_worker_config *wc = conf->worker_config; guint i; for (i = 0; i < srv->worker_count; i++) { li_action_release(srv, wc[i].act); } g_slice_free1(sizeof(lua_worker_config) * srv->worker_count, wc); } g_string_free(conf->filename, TRUE); li_value_free(conf->args); if (conf->mconf_link.data) { /* still in LI_SERVER_INIT */ module_config *mc = conf->p->data; g_queue_unlink(&mc->lua_configs, &conf->mconf_link); conf->mconf_link.data = NULL; } g_slice_free(lua_config, conf); }
static void chunk_free(liChunkQueue *cq, liChunk *c) { if (!c) return; if (cq) { g_queue_unlink(&cq->queue, &c->cq_link); } switch (c->type) { case UNUSED_CHUNK: break; case STRING_CHUNK: g_string_free(c->data.str, TRUE); c->data.str = NULL; break; case MEM_CHUNK: /* mem is handled extra below */ break; case FILE_CHUNK: if (c->data.file.file) { li_chunkfile_release(c->data.file.file); c->data.file.file = NULL; } if (c->data.file.mmap.data != MAP_FAILED) { munmap(c->data.file.mmap.data, c->data.file.mmap.length); c->data.file.mmap.data = MAP_FAILED; } break; case BUFFER_CHUNK: li_buffer_release(c->data.buffer.buffer); break; } c->type = UNUSED_CHUNK; if (c->mem) { g_byte_array_free(c->mem, TRUE); c->mem = NULL; } g_slice_free(liChunk, c); }
static void free_request(liMemcachedCon *con, int_request *req) { if (!req) return; li_memcached_con_release(con); if (NULL != req->iter.data) { req->iter.data = NULL; g_queue_unlink(&con->req_queue, &req->iter); } switch (req->type) { case REQ_GET: break; case REQ_SET: li_buffer_release(req->data); req->data = NULL; break; } g_string_free(req->key, TRUE); req->key = NULL; g_slice_free(int_request, req); }
static void move_queue_member_to_head (GQueue *queue, GList *link) { g_queue_unlink (queue, link); g_queue_push_head_link (queue, link); }
static void close_socket_now(closing_socket *cs) { close(cs->fd); cs->fd = -1; g_queue_unlink(&cs->loop->closing_sockets, &cs->sockets_link); }