From dc4f845c37a8446de19036e24fd397a0aa864c02 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sat, 23 Oct 2010 11:59:03 +0800 Subject: egl: Add reference count for resources. This is a really simple mechanism. There is no atomicity and the caller is expected to hold the display lock. --- src/egl/main/egldisplay.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 47dcc3e05a..565e44d2d2 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -232,6 +232,42 @@ _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy) } +/** + * Initialize a display resource. + */ +void +_eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *dpy) +{ + memset(res, 0, size); + res->Display = dpy; + res->RefCount = 1; +} + + +/** + * Increment reference count for the resource. + */ +void +_eglGetResource(_EGLResource *res) +{ + assert(res && res->RefCount > 0); + /* hopefully a resource is always manipulated with its display locked */ + res->RefCount++; +} + + +/** + * Decrement reference count for the resource. + */ +EGLBoolean +_eglPutResource(_EGLResource *res) +{ + assert(res && res->RefCount > 0); + res->RefCount--; + return (!res->RefCount); +} + + /** * Link a resource to its display. */ @@ -243,6 +279,7 @@ _eglLinkResource(_EGLResource *res, _EGLResourceType type) res->IsLinked = EGL_TRUE; res->Next = res->Display->ResourceLists[type]; res->Display->ResourceLists[type] = res; + _eglGetResource(res); } @@ -269,6 +306,9 @@ _eglUnlinkResource(_EGLResource *res, _EGLResourceType type) } res->Next = NULL; - /* do not reset res->Display */ res->IsLinked = EGL_FALSE; + _eglPutResource(res); + + /* We always unlink before destroy. The driver still owns a reference */ + assert(res->RefCount); } -- cgit v1.2.3