static gboolean add_tree (TreeNode **ptop, guint v) { TreeNode *node = gsk_mem_pool_fixed_alloc (&tree_node_pool); TreeNode *extant; node->value = v; GSK_RBTREE_INSERT (TREE(ptop), node, extant); if (extant == NULL) return FALSE; gsk_mem_pool_fixed_free (&tree_node_pool, node); return TRUE; }
ProtobufCDispatchTimer * protobuf_c_dispatch_add_timer(ProtobufCDispatch *dispatch, unsigned timeout_secs, unsigned timeout_usecs, ProtobufCDispatchTimerFunc func, void *func_data) { RealDispatch *d = (RealDispatch *) dispatch; ProtobufCDispatchTimer *rv; ProtobufCDispatchTimer *at; ProtobufCDispatchTimer *conflict; protobuf_c_assert (func != NULL); if (d->recycled_timeouts != NULL) { rv = d->recycled_timeouts; d->recycled_timeouts = rv->right; } else { rv = d->allocator->alloc (d->allocator, sizeof (ProtobufCDispatchTimer)); } rv->timeout_secs = timeout_secs; rv->timeout_usecs = timeout_usecs; rv->func = func; rv->func_data = func_data; rv->dispatch = d; GSK_RBTREE_INSERT (GET_TIMER_TREE (d), rv, conflict); /* is this the first element in the tree */ for (at = rv; at != NULL; at = at->parent) if (at->parent && at->parent->right == at) break; if (at == NULL) /* yes, so set the public members */ { dispatch->has_timeout = 1; dispatch->timeout_secs = rv->timeout_secs; dispatch->timeout_usecs = rv->timeout_usecs; } return rv; }
static inline FDMap * force_fd_map (RealDispatch *d, ProtobufC_FD fd) { #if HAVE_SMALL_FDS ensure_fd_map_big_enough (d, fd); return d->fd_map + fd; #else { FDMap *fm = get_fd_map (d, fd); ProtobufCAllocator *allocator = d->allocator; if (fm == NULL) { FDMapNode *node = ALLOC (sizeof (FDMapNode)); FDMapNode *conflict; node->fd = fd; memset (&node->map, 255, sizeof (FDMap)); GSK_RBTREE_INSERT (GET_FD_MAP_TREE (d), node, conflict); assert (conflict == NULL); fm = &node->map; } return fm; } #endif }