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 {
 | 
					typedef struct _PrivateDesc {
 | 
				
			||||||
    devprivate_key_t *key;
 | 
					    devprivate_key_t *key;
 | 
				
			||||||
    RESTYPE type;
 | 
					 | 
				
			||||||
    pointer parent;
 | 
					 | 
				
			||||||
    unsigned size;
 | 
					    unsigned size;
 | 
				
			||||||
    CallbackListPtr initfuncs;
 | 
					    CallbackListPtr initfuncs;
 | 
				
			||||||
    CallbackListPtr deletefuncs;
 | 
					    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
 | 
					_X_EXPORT int
 | 
				
			||||||
dixRequestPrivate(RESTYPE type, devprivate_key_t *const key,
 | 
					dixRequestPrivate(devprivate_key_t *const key, unsigned size)
 | 
				
			||||||
		  unsigned size, pointer parent)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PrivateDescRec *item = findItem(key);
 | 
					    PrivateDescRec *item = findItem(key);
 | 
				
			||||||
    if (item) {
 | 
					    if (item) {
 | 
				
			||||||
	assert(item->type == type);
 | 
					 | 
				
			||||||
	if (size > item->size)
 | 
						if (size > item->size)
 | 
				
			||||||
	    item->size = size;
 | 
						    item->size = size;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
| 
						 | 
					@ -91,8 +87,6 @@ dixRequestPrivate(RESTYPE type, devprivate_key_t *const key,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* add privates descriptor */
 | 
						/* add privates descriptor */
 | 
				
			||||||
	item->key = key;
 | 
						item->key = key;
 | 
				
			||||||
	item->type = type;
 | 
					 | 
				
			||||||
	item->parent = parent;
 | 
					 | 
				
			||||||
	item->size = size;
 | 
						item->size = size;
 | 
				
			||||||
	item->next = items;
 | 
						item->next = items;
 | 
				
			||||||
	items = item;
 | 
						items = item;
 | 
				
			||||||
| 
						 | 
					@ -116,7 +110,6 @@ dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key)
 | 
				
			||||||
    ptr = (PrivateRec *)xalloc(size);
 | 
					    ptr = (PrivateRec *)xalloc(size);
 | 
				
			||||||
    if (!ptr)
 | 
					    if (!ptr)
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
    memset(ptr, 0, size);
 | 
					 | 
				
			||||||
    ptr->key = key;
 | 
					    ptr->key = key;
 | 
				
			||||||
    ptr->value = (size > sizeof(PrivateRec)) ? (ptr + 1) : NULL;
 | 
					    ptr->value = (size > sizeof(PrivateRec)) ? (ptr + 1) : NULL;
 | 
				
			||||||
    ptr->next = *privates;
 | 
					    ptr->next = *privates;
 | 
				
			||||||
| 
						 | 
					@ -130,57 +123,6 @@ dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key)
 | 
				
			||||||
    return &ptr->value;
 | 
					    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.
 | 
					 * Called to free privates at object deletion time.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					@ -204,16 +146,9 @@ dixFreePrivates(PrivateRec *privates)
 | 
				
			||||||
    /* second pass frees the memory */
 | 
					    /* second pass frees the memory */
 | 
				
			||||||
    ptr = privates;
 | 
					    ptr = privates;
 | 
				
			||||||
    while (ptr) {
 | 
					    while (ptr) {
 | 
				
			||||||
	if (ptr->dontfree)
 | 
						next = ptr->next;
 | 
				
			||||||
	    ptr = ptr->next;
 | 
						xfree(ptr);
 | 
				
			||||||
	else {
 | 
						ptr = next;
 | 
				
			||||||
	    next = ptr->next;
 | 
					 | 
				
			||||||
	    while (next && next->dontfree)
 | 
					 | 
				
			||||||
		next = next->next;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	    xfree(ptr);
 | 
					 | 
				
			||||||
	    ptr = next;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -225,8 +160,11 @@ dixRegisterPrivateInitFunc(devprivate_key_t *const key,
 | 
				
			||||||
			   CallbackProcPtr callback, pointer data)
 | 
								   CallbackProcPtr callback, pointer data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PrivateDescRec *item = findItem(key);
 | 
					    PrivateDescRec *item = findItem(key);
 | 
				
			||||||
    if (!item)
 | 
					    if (!item) {
 | 
				
			||||||
	return FALSE;
 | 
						if (!dixRequestPrivate(key, 0))
 | 
				
			||||||
 | 
						    return FALSE;
 | 
				
			||||||
 | 
						item = findItem(key);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    return AddCallback(&item->initfuncs, callback, data);
 | 
					    return AddCallback(&item->initfuncs, callback, data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -235,8 +173,11 @@ dixRegisterPrivateDeleteFunc(devprivate_key_t *const key,
 | 
				
			||||||
			     CallbackProcPtr callback, pointer data)
 | 
								     CallbackProcPtr callback, pointer data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PrivateDescRec *item = findItem(key);
 | 
					    PrivateDescRec *item = findItem(key);
 | 
				
			||||||
    if (!item)
 | 
					    if (!item) {
 | 
				
			||||||
	return FALSE;
 | 
						if (!dixRequestPrivate(key, 0))
 | 
				
			||||||
 | 
						    return FALSE;
 | 
				
			||||||
 | 
						item = findItem(key);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    return AddCallback(&item->deletefuncs, callback, data);
 | 
					    return AddCallback(&item->deletefuncs, callback, data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -264,7 +264,6 @@ _X_HIDDEN void *dixLookupTab[] = {
 | 
				
			||||||
    SYMFUNC(dixRegisterPrivateInitFunc)
 | 
					    SYMFUNC(dixRegisterPrivateInitFunc)
 | 
				
			||||||
    SYMFUNC(dixRegisterPrivateDeleteFunc)
 | 
					    SYMFUNC(dixRegisterPrivateDeleteFunc)
 | 
				
			||||||
    SYMFUNC(dixAllocatePrivate)
 | 
					    SYMFUNC(dixAllocatePrivate)
 | 
				
			||||||
    SYMFUNC(dixAllocatePrivates)
 | 
					 | 
				
			||||||
    SYMFUNC(dixFreePrivates)
 | 
					    SYMFUNC(dixFreePrivates)
 | 
				
			||||||
    SYMFUNC(dixRegisterPrivateOffset)
 | 
					    SYMFUNC(dixRegisterPrivateOffset)
 | 
				
			||||||
    SYMFUNC(dixLookupPrivateOffset)
 | 
					    SYMFUNC(dixLookupPrivateOffset)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,13 +19,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 | 
				
			||||||
 * STUFF FOR PRIVATES
 | 
					 * STUFF FOR PRIVATES
 | 
				
			||||||
 *****************************************************************/
 | 
					 *****************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct _PrivateKey {
 | 
					typedef char devprivate_key_t;
 | 
				
			||||||
    int unused;
 | 
					 | 
				
			||||||
} devprivate_key_t;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct _Private {
 | 
					typedef struct _Private {
 | 
				
			||||||
    devprivate_key_t	*key;
 | 
					    devprivate_key_t	*key;
 | 
				
			||||||
    int			dontfree;
 | 
					 | 
				
			||||||
    pointer		value;
 | 
					    pointer		value;
 | 
				
			||||||
    struct _Private	*next;
 | 
					    struct _Private	*next;
 | 
				
			||||||
} PrivateRec;
 | 
					} PrivateRec;
 | 
				
			||||||
| 
						 | 
					@ -39,11 +36,10 @@ typedef struct _Private {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Request pre-allocated private space for your driver/module.
 | 
					 * 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
 | 
					extern int
 | 
				
			||||||
dixRequestPrivate(RESTYPE type, devprivate_key_t *const key,
 | 
					dixRequestPrivate(devprivate_key_t *const key, unsigned size);
 | 
				
			||||||
		  unsigned size, pointer pScreen);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Allocates a new private and attaches it to an existing object.
 | 
					 * 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);
 | 
								     CallbackProcPtr callback, pointer userdata);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Allocates all pre-requested private space in one chunk.
 | 
					 * Frees private data.
 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
extern PrivateRec *
 | 
					 | 
				
			||||||
dixAllocatePrivates(RESTYPE type, pointer parent);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Frees any private space that is not part of an object.
 | 
					 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
extern void
 | 
					extern void
 | 
				
			||||||
dixFreePrivates(PrivateRec *privates);
 | 
					dixFreePrivates(PrivateRec *privates);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue