diff options
author | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2007-03-01 15:00:02 -0500 |
---|---|---|
committer | Eamon Walsh <ewalsh@moss-uranus.epoch.ncsc.mil> | 2007-03-05 11:50:45 -0500 |
commit | e684824709fa8ffe03dde3c8dfbc58c267515a4f (patch) | |
tree | dd9172343b3dea7cd2ab0ae365724c62cff81673 /include/privates.h | |
parent | 74f1de1de9633119c2cf26086875717181c8a6f7 (diff) |
devPrivates rework: redo interface and implementation.
Diffstat (limited to 'include/privates.h')
-rw-r--r-- | include/privates.h | 126 |
1 files changed, 104 insertions, 22 deletions
diff --git a/include/privates.h b/include/privates.h index 8d7427074..898fdd9c9 100644 --- a/include/privates.h +++ b/include/privates.h @@ -19,59 +19,141 @@ 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 struct _Private { + devprivate_key_t *key; + int dontfree; + pointer value; + struct _Private *next; +} PrivateRec; + /* - * Request private space for your driver/module in all resources of a type. - * A non-null pScreen argument restricts to resources on a given screen. + * Request pre-allocated private space for your driver/module. + * A non-null pScreen argument restricts to objects on a given screen. */ extern int -dixRequestPrivate(RESTYPE type, unsigned size, pointer pScreen); +dixRequestPrivate(RESTYPE type, devprivate_key_t *const key, + unsigned size, pointer pScreen); /* - * Request private space in just one individual resource object. + * Allocates a new private and attaches it to an existing object. */ -extern int -dixRequestSinglePrivate(RESTYPE type, unsigned size, pointer instance); +extern pointer * +dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key); /* * Look up a private pointer. */ -extern pointer -dixLookupPrivate(RESTYPE type, int index, pointer instance); +static _X_INLINE pointer +dixLookupPrivate(PrivateRec **privates, devprivate_key_t *const key) +{ + PrivateRec *rec = *privates; + pointer *ptr; + + while (rec) { + if (rec->key == key) + return rec->value; + rec = rec->next; + } + + ptr = dixAllocatePrivate(privates, key); + return ptr ? *ptr : NULL; +} + +/* + * Look up the address of a private pointer. + */ +static _X_INLINE pointer * +dixLookupPrivateAddr(PrivateRec **privates, devprivate_key_t *const key) +{ + PrivateRec *rec = *privates; + + while (rec) { + if (rec->key == key) + return &rec->value; + rec = rec->next; + } + + return dixAllocatePrivate(privates, key); +} + +/* + * Set a private pointer. + */ +static _X_INLINE int +dixSetPrivate(PrivateRec **privates, devprivate_key_t *const key, pointer val) +{ + PrivateRec *rec; + + top: + rec = *privates; + while (rec) { + if (rec->key == key) { + rec->value = val; + return TRUE; + } + rec = rec->next; + } + + if (!dixAllocatePrivate(privates, key)) + return FALSE; + goto top; +} /* * Register callbacks to be called on private allocation/freeing. * The calldata argument to the callbacks is a PrivateCallbackPtr. */ typedef struct _PrivateCallback { + devprivate_key_t *key; /* private registration key */ pointer value; /* pointer to private */ - int index; /* registration index */ - ResourcePtr resource; /* resource record (do not modify!) */ -} PrivateCallbackRec, *PrivateCallbackPtr; +} PrivateCallbackRec; extern int -dixRegisterPrivateInitFunc(RESTYPE type, int index, +dixRegisterPrivateInitFunc(devprivate_key_t *const key, CallbackProcPtr callback, pointer userdata); extern int -dixRegisterPrivateDeleteFunc(RESTYPE type, int index, +dixRegisterPrivateDeleteFunc(devprivate_key_t *const key, CallbackProcPtr callback, pointer userdata); /* - * Internal functions + * 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. */ extern void -dixResetPrivates(void); +dixFreePrivates(PrivateRec *privates); +/* + * Resets the subsystem, called from the main loop. + */ extern int -dixUpdatePrivates(void); +dixResetPrivates(void); -extern ResourcePtr -dixAllocateResourceRec(RESTYPE type, pointer value, pointer parent); +/* + * These next two functions are necessary because the position of + * the devPrivates field varies by structure and calling code might + * only know the resource type, not the structure definition. + */ -extern void -dixCallPrivateInitFuncs(ResourcePtr res); +/* + * Looks up the offset where the devPrivates field is located by type. + */ +extern unsigned +dixLookupPrivateOffset(RESTYPE type); -extern void -dixFreeResourceRec(ResourcePtr res); +/* + * Specifies the offset where the devPrivates field is located. + */ +extern int +dixRegisterPrivateOffset(RESTYPE type, unsigned offset); #endif /* PRIVATES_H */ |