devPrivates rework: redo interface again, dropping parent and type parameters
as well as preallocation routine.
This commit is contained in:
		
							parent
							
								
									c45f676208
								
							
						
					
					
						commit
						947f8d249b
					
				| 
						 | 
				
			
			@ -48,8 +48,6 @@ from The Open Group.
 | 
			
		|||
 | 
			
		||||
typedef struct _PrivateDesc {
 | 
			
		||||
    devprivate_key_t *key;
 | 
			
		||||
    RESTYPE type;
 | 
			
		||||
    pointer parent;
 | 
			
		||||
    unsigned size;
 | 
			
		||||
    CallbackListPtr initfuncs;
 | 
			
		||||
    CallbackListPtr deletefuncs;
 | 
			
		||||
| 
						 | 
				
			
			@ -72,15 +70,13 @@ findItem(devprivate_key_t *const key)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Request pre-allocated space in resources of a given type.
 | 
			
		||||
 * Request pre-allocated space.
 | 
			
		||||
 */
 | 
			
		||||
_X_EXPORT int
 | 
			
		||||
dixRequestPrivate(RESTYPE type, devprivate_key_t *const key,
 | 
			
		||||
		  unsigned size, pointer parent)
 | 
			
		||||
dixRequestPrivate(devprivate_key_t *const key, unsigned size)
 | 
			
		||||
{
 | 
			
		||||
    PrivateDescRec *item = findItem(key);
 | 
			
		||||
    if (item) {
 | 
			
		||||
	assert(item->type == type);
 | 
			
		||||
	if (size > item->size)
 | 
			
		||||
	    item->size = size;
 | 
			
		||||
    } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -91,8 +87,6 @@ dixRequestPrivate(RESTYPE type, devprivate_key_t *const key,
 | 
			
		|||
 | 
			
		||||
	/* add privates descriptor */
 | 
			
		||||
	item->key = key;
 | 
			
		||||
	item->type = type;
 | 
			
		||||
	item->parent = parent;
 | 
			
		||||
	item->size = size;
 | 
			
		||||
	item->next = items;
 | 
			
		||||
	items = item;
 | 
			
		||||
| 
						 | 
				
			
			@ -116,7 +110,6 @@ dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key)
 | 
			
		|||
    ptr = (PrivateRec *)xalloc(size);
 | 
			
		||||
    if (!ptr)
 | 
			
		||||
	return NULL;
 | 
			
		||||
    memset(ptr, 0, size);
 | 
			
		||||
    ptr->key = key;
 | 
			
		||||
    ptr->value = (size > sizeof(PrivateRec)) ? (ptr + 1) : NULL;
 | 
			
		||||
    ptr->next = *privates;
 | 
			
		||||
| 
						 | 
				
			
			@ -130,57 +123,6 @@ dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key)
 | 
			
		|||
    return &ptr->value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Allocates pre-requested privates in a single chunk.
 | 
			
		||||
 */
 | 
			
		||||
_X_EXPORT PrivateRec *
 | 
			
		||||
dixAllocatePrivates(RESTYPE type, pointer parent)
 | 
			
		||||
{
 | 
			
		||||
    unsigned count = 0, size = 0;
 | 
			
		||||
    PrivateCallbackRec calldata;
 | 
			
		||||
    PrivateDescRec *item;
 | 
			
		||||
    PrivateRec *ptr;
 | 
			
		||||
    char *value;
 | 
			
		||||
 | 
			
		||||
    /* first pass figures out total size */
 | 
			
		||||
    for (item = items; item; item = item->next)
 | 
			
		||||
	if ((item->type == type || item->type == RC_ANY) &&
 | 
			
		||||
	    (item->parent == NULL || item->parent == parent)) {
 | 
			
		||||
 | 
			
		||||
	    size += sizeof(PrivateRec) + item->size;
 | 
			
		||||
	    count++;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    /* allocate one chunk of memory for everything */
 | 
			
		||||
    ptr = (PrivateRec *)xalloc(size);
 | 
			
		||||
    if (!ptr)
 | 
			
		||||
	return NULL;
 | 
			
		||||
    memset(ptr, 0, size);
 | 
			
		||||
    value = (char *)(ptr + count);
 | 
			
		||||
 | 
			
		||||
    /* second pass sets up records and calls init funcs */
 | 
			
		||||
    count = 0;
 | 
			
		||||
    for (item = items; item; item = item->next)
 | 
			
		||||
	if ((item->type == type || item->type == RC_ANY) &&
 | 
			
		||||
	    (item->parent == NULL || item->parent == parent)) {
 | 
			
		||||
 | 
			
		||||
	    ptr[count].key = calldata.key = item->key;
 | 
			
		||||
	    ptr[count].dontfree = (count > 0);
 | 
			
		||||
	    ptr[count].value = calldata.value = (items->size ? value : NULL);
 | 
			
		||||
	    ptr[count].next = ptr + (count + 1);
 | 
			
		||||
 | 
			
		||||
	    CallCallbacks(&item->initfuncs, &calldata);
 | 
			
		||||
 | 
			
		||||
	    count++;
 | 
			
		||||
	    value += item->size;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    if (count > 0)
 | 
			
		||||
	ptr[count-1].next = NULL;
 | 
			
		||||
 | 
			
		||||
    return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Called to free privates at object deletion time.
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -204,18 +146,11 @@ dixFreePrivates(PrivateRec *privates)
 | 
			
		|||
    /* second pass frees the memory */
 | 
			
		||||
    ptr = privates;
 | 
			
		||||
    while (ptr) {
 | 
			
		||||
	if (ptr->dontfree)
 | 
			
		||||
	    ptr = ptr->next;
 | 
			
		||||
	else {
 | 
			
		||||
	next = ptr->next;
 | 
			
		||||
	    while (next && next->dontfree)
 | 
			
		||||
		next = next->next;
 | 
			
		||||
 | 
			
		||||
	xfree(ptr);
 | 
			
		||||
	ptr = next;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Callback registration
 | 
			
		||||
| 
						 | 
				
			
			@ -225,8 +160,11 @@ dixRegisterPrivateInitFunc(devprivate_key_t *const key,
 | 
			
		|||
			   CallbackProcPtr callback, pointer data)
 | 
			
		||||
{
 | 
			
		||||
    PrivateDescRec *item = findItem(key);
 | 
			
		||||
    if (!item)
 | 
			
		||||
    if (!item) {
 | 
			
		||||
	if (!dixRequestPrivate(key, 0))
 | 
			
		||||
	    return FALSE;
 | 
			
		||||
	item = findItem(key);
 | 
			
		||||
    }
 | 
			
		||||
    return AddCallback(&item->initfuncs, callback, data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -235,8 +173,11 @@ dixRegisterPrivateDeleteFunc(devprivate_key_t *const key,
 | 
			
		|||
			     CallbackProcPtr callback, pointer data)
 | 
			
		||||
{
 | 
			
		||||
    PrivateDescRec *item = findItem(key);
 | 
			
		||||
    if (!item)
 | 
			
		||||
    if (!item) {
 | 
			
		||||
	if (!dixRequestPrivate(key, 0))
 | 
			
		||||
	    return FALSE;
 | 
			
		||||
	item = findItem(key);
 | 
			
		||||
    }
 | 
			
		||||
    return AddCallback(&item->deletefuncs, callback, data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -264,7 +264,6 @@ _X_HIDDEN void *dixLookupTab[] = {
 | 
			
		|||
    SYMFUNC(dixRegisterPrivateInitFunc)
 | 
			
		||||
    SYMFUNC(dixRegisterPrivateDeleteFunc)
 | 
			
		||||
    SYMFUNC(dixAllocatePrivate)
 | 
			
		||||
    SYMFUNC(dixAllocatePrivates)
 | 
			
		||||
    SYMFUNC(dixFreePrivates)
 | 
			
		||||
    SYMFUNC(dixRegisterPrivateOffset)
 | 
			
		||||
    SYMFUNC(dixLookupPrivateOffset)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,13 +19,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 | 
			
		|||
 * STUFF FOR PRIVATES
 | 
			
		||||
 *****************************************************************/
 | 
			
		||||
 | 
			
		||||
typedef struct _PrivateKey {
 | 
			
		||||
    int unused;
 | 
			
		||||
} devprivate_key_t;
 | 
			
		||||
typedef char devprivate_key_t;
 | 
			
		||||
 | 
			
		||||
typedef struct _Private {
 | 
			
		||||
    devprivate_key_t	*key;
 | 
			
		||||
    int			dontfree;
 | 
			
		||||
    pointer		value;
 | 
			
		||||
    struct _Private	*next;
 | 
			
		||||
} PrivateRec;
 | 
			
		||||
| 
						 | 
				
			
			@ -39,11 +36,10 @@ typedef struct _Private {
 | 
			
		|||
 | 
			
		||||
/*
 | 
			
		||||
 * Request pre-allocated private space for your driver/module.
 | 
			
		||||
 * A non-null pScreen argument restricts to objects on a given screen.
 | 
			
		||||
 * Calling this is not necessary if only a pointer by itself is needed.
 | 
			
		||||
 */
 | 
			
		||||
extern int
 | 
			
		||||
dixRequestPrivate(RESTYPE type, devprivate_key_t *const key,
 | 
			
		||||
		  unsigned size, pointer pScreen);
 | 
			
		||||
dixRequestPrivate(devprivate_key_t *const key, unsigned size);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Allocates a new private and attaches it to an existing object.
 | 
			
		||||
| 
						 | 
				
			
			@ -128,13 +124,7 @@ dixRegisterPrivateDeleteFunc(devprivate_key_t *const key,
 | 
			
		|||
			     CallbackProcPtr callback, pointer userdata);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Allocates all pre-requested private space in one chunk.
 | 
			
		||||
 */
 | 
			
		||||
extern PrivateRec *
 | 
			
		||||
dixAllocatePrivates(RESTYPE type, pointer parent);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Frees any private space that is not part of an object.
 | 
			
		||||
 * Frees private data.
 | 
			
		||||
 */
 | 
			
		||||
extern void
 | 
			
		||||
dixFreePrivates(PrivateRec *privates);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue