Esempio n. 1
0
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#include <assert.h>
#include <signal.h>

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"

RB_HEAD(uv_signal_tree_s, uv_signal_s);

static struct uv_signal_tree_s uv__signal_tree =
    RB_INITIALIZER(uv__signal_tree);
static ssize_t volatile uv__signal_control_handler_refs = 0;
static CRITICAL_SECTION uv__signal_lock;

void uv_signals_init() { InitializeCriticalSection(&uv__signal_lock); }

static int uv__signal_compare(uv_signal_t* w1, uv_signal_t* w2) {
  /* Compare signums first so all watchers with the same signnum end up */
  /* adjacent. */
  if (w1->signum < w2->signum) return -1;
  if (w1->signum > w2->signum) return 1;

  /* Sort by loop pointer, so we can easily look up the first item after */
  /* { .signum = x, .loop = NULL } */
  if ((uintptr_t)w1->loop < (uintptr_t)w2->loop) return -1;
  if ((uintptr_t)w1->loop > (uintptr_t)w2->loop) return 1;
Esempio n. 2
0
	} else if (ct_verbose) {
		printf("%s deleted\n", trans->tr_ctfile_name);
	}
}

struct ct_login_cache {
	RB_ENTRY(ct_login_cache)	 lc_next;
	uid_t				 lc_uid;
	char				*lc_name;
};


int ct_cmp_logincache(struct ct_login_cache *, struct ct_login_cache *);

RB_HEAD(ct_login_cache_tree, ct_login_cache) ct_login_cache =
     RB_INITIALIZER(&login_cache);

#define MAX_LC_CACHE_SIZE 100
int ct_login_cache_size;

RB_PROTOTYPE(ct_login_cache_tree, ct_login_cache, lc_next, ct_cmp_logincache);
RB_GENERATE(ct_login_cache_tree, ct_login_cache, lc_next, ct_cmp_logincache);

void
ct_cleanup_login_cache(void)
{
	struct ct_login_cache *tmp;

	while ((tmp = RB_ROOT(&ct_login_cache)) != NULL) {
		RB_REMOVE(ct_login_cache_tree, &ct_login_cache, tmp);
		/* may cache negative entries, uid not found, avoid NULL free */
Esempio n. 3
0
static char *quick_cache_filename = NULL;
static SDL_Surface *quick_cache = NULL;

struct image_cache {
    /* reference to the surface object returned from loading a surface through SDL_image */
    SDL_Surface *surface;

    /* a copy of a string representing the alias of this image */
    char *alias;

    /* the structure used to include this in an rb
     * tree for easy retreival */
    RB_ENTRY(image_cache) _rb_tree_entry;
};

static RB_HEAD(image_cache_tree, image_cache) image_cache = RB_INITIALIZER(image_cache);

static int __cmp(struct image_cache *a, struct image_cache *b) {
    return strcmp(a->alias, b->alias);
}

RB_GENERATE_STATIC(image_cache_tree, image_cache, _rb_tree_entry, __cmp);

int
image_loader_load(char *alias,
                  char *filename,
                  int x,
                  int y,
                  int width,
                  int height)
{
Esempio n. 4
0
#include "black.h"

static unsigned long global_id_counter = 0;

static RB_HEAD(game_object_tree, game_object) game_objects = RB_INITIALIZER(game_objects);

static int game_object_cmp(struct game_object *a, struct game_object *b) {
    return a->id - b->id;
}

RB_GENERATE_STATIC(game_object_tree, game_object, _rb_tree_entry, game_object_cmp);

game_object *
make_game_object(unsigned int type, void *data)
{
    struct game_object *obj = malloc(sizeof(*obj));
    obj->id = global_id_counter++;
    obj->type = type;
    obj->data = data;
	obj->image = NULL;
	obj->screenx = 0;
	obj->screeny = 0;
    SLL_INIT(&obj->update_callbacks);
    SLL_INIT(&obj->render_callbacks);
    SLL_INIT(&obj->message_list);

    /* store in rb tree for easier retrieval */
    game_object_tree_RB_INSERT(&game_objects, obj);

    return obj;
}
Esempio n. 5
0
            int is_reachable: 1;
#endif
        } val;
    } kv;
};

static inline int FccEntryPointNode_compare(
    FccEntryPointNode *a, FccEntryPointNode *b)
{
#define MAP(x) &((x)->kv.key.key)
    return compare_enc_states(MAP(a), MAP(b));
}

RB_HEAD(FccEntryPointList, FccEntryPointNode);
const FccEntryPointList FccEntryPointList_init =
    RB_INITIALIZER(&(instance->fcc_entry_points));

typedef struct
{
    fcs_dbm_collection_by_depth_t coll;
    fcs_lock_t global_lock;
    const char *offload_dir_path;
    int curr_depth;
    fcs_dbm_instance_common_elems_t common;
    fcs_meta_compact_allocator_t fcc_meta_alloc;
    FccEntryPointList fcc_entry_points;
    fcs_compact_allocator_t fcc_entry_points_allocator;
    fcs_lock_t fcc_entry_points_lock;
    FccEntryPointNode *start_key_ptr;
#if 0
    fcs_bool_t was_start_key_reachable;
Esempio n. 6
0
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <bsd/sys/tree.h>

typedef const char* pcch;

typedef struct data data;
struct data {
	RB_ENTRY(data) n;
	pcch s;
};

int cmp(const data *x, const data *y) { return strcmp(x->s, y->s); }

RB_HEAD(tree, data) head = RB_INITIALIZER(&head);
RB_PROTOTYPE(tree, data, n, cmp);
RB_GENERATE(tree, data, n, cmp);

pcch ustr(pcch s) {
	data *d = malloc(sizeof(data));
	d->s = strdup(s);
	RB_INSERT(tree, &head, d);
	return d->s;
}

void strings_test() {
	ustr("hello");
	ustr("world");
	ustr("world");
	data *d;
Esempio n. 7
0
File: tud.c Progetto: stetre/luajack
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/****************************************************************************
 * Ports database               											*
 ****************************************************************************/

#include "internal.h"

static int cmp(tud_t *tud1, tud_t *tud2) /* the compare function */
	{ return (tud1->key < tud2->key ? -1 : tud1->key > tud2->key); } 

static RB_HEAD(tudtree_s, tud_s) Head = RB_INITIALIZER(&Head);

RB_PROTOTYPE_STATIC(tudtree_s, tud_s, entry, cmp) 
RB_GENERATE_STATIC(tudtree_s, tud_s, entry, cmp) 
 
static tud_t *tud_remove(tud_t *tud) 
	{ return RB_REMOVE(tudtree_s, &Head, tud); }
static tud_t *tud_insert(tud_t *tud) 
	{ return RB_INSERT(tudtree_s, &Head, tud); }
static tud_t *tud_search(uintptr_t key) 
	{ tud_t tmp; tmp.key = key; return RB_FIND(tudtree_s, &Head, &tmp); }
tud_t *tud_first(uintptr_t key) 
	{ tud_t tmp; tmp.key = key; return RB_NFIND(tudtree_s, &Head, &tmp); }
tud_t *tud_next(tud_t *tud)
	{ return RB_NEXT(tudtree_s, &Head, tud); }
#if 0
Esempio n. 8
0
  void                                   *args;

#if NAS_BUILT_IN_EPC
                                          RB_ENTRY (
  emm_common_data_s)                      entries;
#endif
} emm_common_data_t;

#if NAS_BUILT_IN_EPC
typedef struct emm_common_data_head_s {
  RB_HEAD (
  emm_common_data_map,
  emm_common_data_s) emm_common_data_root;
} emm_common_data_head_t;

emm_common_data_head_t                  emm_common_data_head = { RB_INITIALIZER () };

static inline int                       emm_common_data_compare_ueid (
  struct emm_common_data_s *p1,
  struct emm_common_data_s *p2);
struct emm_common_data_s               *emm_common_data_context_get (
  struct emm_common_data_head_s *root,
  unsigned int _ueid);

RB_PROTOTYPE (emm_common_data_map, emm_common_data_s, entries, emm_common_data_compare_ueid);

/* Generate functions used for the MAP */
RB_GENERATE (emm_common_data_map, emm_common_data_s, entries, emm_common_data_compare_ueid);

static inline int
emm_common_data_compare_ueid (
Esempio n. 9
0
static char              *strip(char *, size_t);
static void              unloadtags(void);

#define DEFAULTFN "tags"

char *tagsfn = NULL;
int  loaded  = FALSE;

/* ctags(1) entries are parsed and maintained in a tree. */
struct ctag {
	RB_ENTRY(ctag) entry;
	char *tag;
	char *fname;
	char *pat;
};
RB_HEAD(tagtree, ctag) tags = RB_INITIALIZER(&tags);
RB_GENERATE(tagtree, ctag, entry, ctagcmp);

struct tagpos {
	SLIST_ENTRY(tagpos) entry;
	int    doto;
	int    dotline;
	char   *bname;
};
SLIST_HEAD(tagstack, tagpos) shead = SLIST_HEAD_INITIALIZER(shead);

int
ctagcmp(struct ctag *s, struct ctag *t)
{
	return strcmp(s->tag, t->tag);
}
Esempio n. 10
0
	     rbnode, h2span_relay_cmp);

RB_GENERATE_STATIC(h2span_cluster_tree, h2span_cluster,
	     rbnode, h2span_cluster_cmp);
RB_GENERATE_STATIC(h2span_node_tree, h2span_node,
	     rbnode, h2span_node_cmp);
RB_GENERATE_STATIC(h2span_link_tree, h2span_link,
	     rbnode, h2span_link_cmp);
RB_GENERATE_STATIC(h2span_relay_tree, h2span_relay,
	     rbnode, h2span_relay_cmp);

/*
 * Global mutex protects cluster_tree lookups, connq, mediaq.
 */
static pthread_mutex_t cluster_mtx;
static struct h2span_cluster_tree cluster_tree = RB_INITIALIZER(cluster_tree);
static struct h2span_conn_queue connq = TAILQ_HEAD_INITIALIZER(connq);
static struct h2span_media_queue mediaq = TAILQ_HEAD_INITIALIZER(mediaq);

static void dmsg_lnk_span(dmsg_msg_t *msg);
static void dmsg_lnk_conn(dmsg_msg_t *msg);
static void dmsg_lnk_circ(dmsg_msg_t *msg);
static void dmsg_lnk_relay(dmsg_msg_t *msg);
static void dmsg_relay_scan(h2span_conn_t *conn, h2span_node_t *node);
static void dmsg_relay_delete(h2span_relay_t *relay);

static void *dmsg_volconf_thread(void *info);
static void dmsg_volconf_stop(h2span_media_config_t *conf);
static void dmsg_volconf_start(h2span_media_config_t *conf,
				const char *hostname);
Esempio n. 11
0
#include "logger.h"
#include "tree.h"
#include "xstack_internal.h"

#define ARP_CACHE_AGE_MAX (20 * 60 * 60) /* Expiration time */

struct arp_cache_entry {
    in_addr_t ip_addr;
    mac_addr_t haddr;
    int age;
    RB_ENTRY(arp_cache_entry) _entry;
};

static struct arp_cache_entry arp_cache[XSTACK_ARP_CACHE_SIZE];
static RB_HEAD(arp_cache_tree, arp_cache_entry) arp_cache_head =
    RB_INITIALIZER(_head);

static int arp_cache_cmp(struct arp_cache_entry * a, struct arp_cache_entry * b)
{
    return a->ip_addr - b->ip_addr;
}

RB_GENERATE_STATIC(arp_cache_tree, arp_cache_entry, _entry, arp_cache_cmp);

static int arp_request(int ether_handle, in_addr_t spa, in_addr_t tpa);

static void arp_hton(const struct arp_ip * host, struct arp_ip * net)
{
    net->arp_htype = htons(host->arp_htype);
    net->arp_ptype = htons(host->arp_ptype);
    net->arp_hlen = host->arp_hlen;
Esempio n. 12
0
    char *filename;
    char *name;
    char *suffix;
    int gzipped;
};

/*
 * Information collected about each unique man page.
 */
struct page_info {
    RB_HEAD(page_alias_tree, page_alias) head;
    RB_ENTRY(page_info) entry;
    ino_t inode;
};

static RB_HEAD(page_info_tree, page_info) page_head = RB_INITIALIZER(&page_head);

/*
 * Sorts page info by inode number.
 */
static int
infosort(const struct page_info *a, const struct page_info *b)
{
    return (memcmp(&a->inode, &b->inode, sizeof(a->inode)));
}

RB_PROTOTYPE(page_info_tree, page_info, entry, infosort);
RB_GENERATE(page_info_tree, page_info, entry, infosort);

/*
 * Sorts page alias first by suffix, then name.
Esempio n. 13
0
	/* Every field is in host byte order, to keep things clear */
	nm.status = code;
	nm.messageid = ntohl(msgid);
	nm.type = type;

	imsg_compose_event(iev_ldpe, IMSG_NOTIFICATION_SEND, peerid, 0,
	    -1, &nm, sizeof(nm));
}

static __inline int lde_nbr_compare(struct lde_nbr *, struct lde_nbr *);

RB_HEAD(nbr_tree, lde_nbr);
RB_PROTOTYPE(nbr_tree, lde_nbr, entry, lde_nbr_compare)
RB_GENERATE(nbr_tree, lde_nbr, entry, lde_nbr_compare)

struct nbr_tree lde_nbrs = RB_INITIALIZER(&lde_nbrs);

static __inline int
lde_nbr_compare(struct lde_nbr *a, struct lde_nbr *b)
{
	return (a->peerid - b->peerid);
}

struct lde_nbr *
lde_nbr_find(u_int32_t peerid)
{
	struct lde_nbr	n;

	n.peerid = peerid;

	return (RB_FIND(nbr_tree, &lde_nbrs, &n));
Esempio n. 14
0
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "variant.h"
#include "entry.h"
#include "db.h"
#include "container.h"
#include <stdio.h>
#include <stdlib.h>

static struct variant_head variant_list = LIST_HEAD_INITIALIZER(&variant_list);
static struct variant_head disabled_list = LIST_HEAD_INITIALIZER(&disabled_list);
static struct tupid_entries variant_root = RB_INITIALIZER(&variant_root);
static struct tupid_entries variant_dt_root = RB_INITIALIZER(&variant_dt_root);

static int load_cb(void *arg, struct tup_entry *tent, int style)
{
	if(arg) {}
	if(style) {}

	if(variant_add(tent, 1, NULL) < 0)
		return -1;
	return 0;
}

int variant_load(void)
{
	if(tup_db_select_node_by_flags(load_cb, NULL, TUP_FLAGS_VARIANT) < 0)
Esempio n. 15
0
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "internal.h"

static int cmp(cur_t *cur1, cur_t *cur2) /* the compare function */
    { return (cur1->id < cur2->id ? -1 : cur1->id > cur2->id); } 

static RB_HEAD(curtree_s, cur_s) Head = RB_INITIALIZER(&Head);

RB_PROTOTYPE_STATIC(curtree_s, cur_s, entry, cmp) 
RB_GENERATE_STATIC(curtree_s, cur_s, entry, cmp) 
 
static cur_t *cur_remove(cur_t *cur) 
    { return RB_REMOVE(curtree_s, &Head, cur); }
static cur_t *cur_insert(cur_t *cur) 
    { return RB_INSERT(curtree_s, &Head, cur); }
cur_t *cur_search(int id) 
    { cur_t tmp; tmp.id = id; return RB_FIND(curtree_s, &Head, &tmp); }
cur_t *cur_first(int id) 
    { cur_t tmp; tmp.id = id; return RB_NFIND(curtree_s, &Head, &tmp); }
cur_t *cur_next(cur_t *cur)
    { return RB_NEXT(curtree_s, &Head, cur); }
#if 0
Esempio n. 16
0
File: mempool.c Progetto: maczpc/csf
};

static int
size_cmp(struct MP_TREE_ENTRY *a, struct MP_TREE_ENTRY *b)
{
	int diff = a->mem_size - b->mem_size;

	if (diff == 0)
		return (0);
	else if (diff < 0)
		return (-1);
	else
		return (1);
}

RB_HEAD(MP_TREE, MP_TREE_ENTRY) mp_tree = RB_INITIALIZER(_head);

RB_PROTOTYPE_STATIC(MP_TREE, MP_TREE_ENTRY, mp_tree_entries, size_cmp);
RB_GENERATE_STATIC(MP_TREE, MP_TREE_ENTRY, mp_tree_entries, size_cmp);

static unsigned int mp_initialized = 0;
static unsigned int g_pre_alloc_num = 10;
static unsigned int g_pre_free_num = 20;

void
mp_init(size_t pre_alloc_num, size_t pre_free_num)
{
	if (pre_alloc_num != 0 && pre_free_num != 0) {
		g_pre_alloc_num = pre_alloc_num;
		if (pre_free_num < pre_alloc_num)
			pre_free_num = pre_alloc_num;
Esempio n. 17
0
#include <stdlib.h>
#include <stdio.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>

#include "sys/event.h"
#include "private.h"

#ifndef NDEBUG
int KQUEUE_DEBUG = 0;
#endif

static RB_HEAD(kqt, kqueue) kqtree       = RB_INITIALIZER(&kqtree);
static pthread_rwlock_t     kqtree_mtx   = PTHREAD_RWLOCK_INITIALIZER;

static int
kqueue_cmp(struct kqueue *a, struct kqueue *b)
{
    return memcmp(&a->kq_sockfd[1], &b->kq_sockfd[1], sizeof(int)); 
}

RB_GENERATE(kqt, kqueue, entries, kqueue_cmp)

/* Must hold the kqtree_mtx when calling this */
static void
kqueue_free(struct kqueue *kq)
{
    RB_REMOVE(kqt, &kqtree, kq);
Esempio n. 18
0
#include <sys/tree.h>
#else
#include "tree.h"
#endif

#include "mibII.h"
#include "mibII_oid.h"

struct sroute {
	RB_ENTRY(sroute) link;
	uint32_t	ifindex;
	uint8_t		index[13];
	uint8_t		type;
	uint8_t		proto;
};
RB_HEAD(sroutes, sroute) sroutes = RB_INITIALIZER(&sroutes);

RB_PROTOTYPE(sroutes, sroute, link, sroute_compare);

#define	ROUTE_UPDATE_INTERVAL	(100 * 60 * 10)	/* 10 min */
static uint64_t route_tick;
static u_int route_total;

/*
 * Compare two routes
 */
static int
sroute_compare(struct sroute *s1, struct sroute *s2)
{

	return (memcmp(s1->index, s2->index, 13));
Esempio n. 19
0
#include "lualib.h"

struct moonassimp_udata_s {
    RB_ENTRY(moonassimp_udata_s) entry;
    uintptr_t id;     /* object id (search key) */
    /* references on the Lua registry */
    int ref;    /* the correspoding userdata */
    void *mem;  /* userdata memory area allocated and released by Lua */
};

#define UNEXPECTED_ERROR "unexpected error (%s, %d)", __FILE__, __LINE__

static int cmp(udata_t *udata1, udata_t *udata2) /* the compare function */
    { return (udata1->id < udata2->id ? -1 : udata1->id > udata2->id); } 

static RB_HEAD(udatatree_s, udata_s) Head = RB_INITIALIZER(&Head);

RB_PROTOTYPE_STATIC(udatatree_s, udata_s, entry, cmp) 
RB_GENERATE_STATIC(udatatree_s, udata_s, entry, cmp) 
 
static udata_t *udata_remove(udata_t *udata) 
    { return RB_REMOVE(udatatree_s, &Head, udata); }
static udata_t *udata_insert(udata_t *udata) 
    { return RB_INSERT(udatatree_s, &Head, udata); }
static udata_t *udata_search(uintptr_t id) 
    { udata_t tmp; tmp.id = id; return RB_FIND(udatatree_s, &Head, &tmp); }
static udata_t *udata_first(uintptr_t id) 
    { udata_t tmp; tmp.id = id; return RB_NFIND(udatatree_s, &Head, &tmp); }
#if 0
static udata_t *udata_next(udata_t *udata)
    { return RB_NEXT(udatatree_s, &Head, udata); }