コード例 #1
0
ファイル: Context.c プロジェクト: KuroyTatakai/libX11
int XDeleteContext(Display *display, XID rid, XContext context)
{
    register DB db;
    register TableEntry entry, *prev;

#ifdef MOTIFBC
    if (!display) db = NullDB; else
#endif
    {
	LockDisplay(display);
	db = display->context_db;
	UnlockDisplay(display);
    }
    if (!db)
	return XCNOENT;
    _XLockMutex(&db->linfo);
    for (prev = &Hash(db, rid, context);
	 (entry = *prev);
	 prev = &entry->next) {
	if (entry->rid == rid && entry->context == context) {
	    *prev = entry->next;
	    Xfree((char *) entry);
	    db->numentries--;
	    if (db->numentries < db->mask && db->mask > INITHASHMASK)
		ResizeTable(db);
	    _XUnlockMutex(&db->linfo);
	    return 0;
	}
    }
    _XUnlockMutex(&db->linfo);
    return XCNOENT;
}
コード例 #2
0
static void
cpSweep1DInsert(cpSweep1D *sweep, void *obj, cpHashValue hashid)
{
	if(sweep->num == sweep->max) ResizeTable(sweep, sweep->max*2);
	
	sweep->table[sweep->num] = MakeTableCell(sweep, obj);
	sweep->num++;
}
コード例 #3
0
cpSpatialIndex *
cpSweep1DInit(cpSweep1D *sweep, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex)
{
	cpSpatialIndexInit((cpSpatialIndex *)sweep, Klass(), bbfunc, staticIndex);
	
	sweep->num = 0;
	ResizeTable(sweep, 32);
	
	return (cpSpatialIndex *)sweep;
}
コード例 #4
0
ファイル: Context.c プロジェクト: KuroyTatakai/libX11
int XSaveContext(
    Display *display,
    register XID rid,
    register XContext context,
    _Xconst char* data)
{
    DB *pdb;
    register DB db;
    TableEntry *head;
    register TableEntry entry;

#ifdef MOTIFBC
    if (!display) {
	pdb = &NullDB;
	db = *pdb;
    } else
#endif
    {
	LockDisplay(display);
	pdb = &display->context_db;
	db = *pdb;
	UnlockDisplay(display);
    }
    if (!db) {
	db = Xmalloc(sizeof(DBRec));
	if (!db)
	    return XCNOMEM;
	db->mask = INITHASHMASK;
	db->table = Xcalloc(db->mask + 1, sizeof(TableEntry));
	if (!db->table) {
	    Xfree((char *)db);
	    return XCNOMEM;
	}
	db->numentries = 0;
	_XCreateMutex(&db->linfo);
#ifdef MOTIFBC
	if (!display) *pdb = db; else
#endif
	{
	    LockDisplay(display);
	    *pdb = db;
	    display->free_funcs->context_db = _XFreeContextDB;
	    UnlockDisplay(display);
	}
    }
    _XLockMutex(&db->linfo);
    head = &Hash(db, rid, context);
    _XUnlockMutex(&db->linfo);
    for (entry = *head; entry; entry = entry->next) {
	if (entry->rid == rid && entry->context == context) {
	    entry->data = (XPointer)data;
	    return 0;
	}
    }
    entry = Xmalloc(sizeof(TableEntryRec));
    if (!entry)
	return XCNOMEM;
    entry->rid = rid;
    entry->context = context;
    entry->data = (XPointer)data;
    entry->next = *head;
    *head = entry;
    _XLockMutex(&db->linfo);
    db->numentries++;
    if (db->numentries > (db->mask << 2))
	ResizeTable(db);
    _XUnlockMutex(&db->linfo);
    return 0;
}