ggiResourceAcquire(3) Acquire and release a LibGGI resource

Other Alias

ggiResourceRelease, ggiResourceMustAcquire


#include <ggi/ggi.h>
int ggiResourceAcquire(ggi_resource_t res, uint32_t actype);
int ggiResourceRelease(ggi_resource_t res);
int ggiResourceMustAcquire(ggi_resource_t res);


ggiResourceAcquire acquires (locks) a LibGGI resource, typically a DirectBuffer (see examples below). The actype indicates the desired access type for the operation. The following flags may be bitwise-or'ed together:
read access to the resource

write access to the resource

ggiResourceRelease releases (unlocks) an already-acquired resource.

ggiResourceMustAcquire determines whether or not the specified resource needs to be acquired before using.


ggiResourceAcquire and ggiResourceRelease return 0 on success, an ggi-error(3) code on failure.

ggiResourceMustAcquire is simply a macro that returns true if the resource must be explicitly acquired and released, or false if not. However, it is still safe to call ggiResourceAcquire or ggiResourceRelease even in the latter case; it would be a no-op.


Using DirectBuffers:

const ggi_directbuffer *dbuf;
/* Acquire DirectBuffer before we use it. */
if (ggiResourceAcquire(dbuf->resource, GGI_ACTYPE_WRITE) != 0) {
      fail("Error acquiring DirectBuffer\n");
/* Do framebuffer rendering here... */
/* Release DirectBuffer when done with it. */