memset(ref, 0, sizeof(*ref));
ref->destroy = destroy;
- qemu_mutex_init(&ref->mutex);
ref->count = 1;
}
{
assert(ref);
assert(!ref->count);
-
- qemu_mutex_destroy(&ref->mutex);
}
void vigs_ref_acquire(struct vigs_ref *ref)
assert(ref);
assert(ref->count > 0);
- qemu_mutex_lock(&ref->mutex);
++ref->count;
- qemu_mutex_unlock(&ref->mutex);
}
void vigs_ref_release(struct vigs_ref *ref)
{
- bool call_destroy = false;
-
assert(ref);
assert(ref->count > 0);
- qemu_mutex_lock(&ref->mutex);
- call_destroy = (--ref->count == 0);
- qemu_mutex_unlock(&ref->mutex);
-
- if (call_destroy) {
+ if (--ref->count == 0) {
assert(ref->destroy);
ref->destroy(ref);
}
#define _QEMU_VIGS_REF_H
#include "vigs_types.h"
-#include "qemu-thread.h"
struct vigs_ref;
{
vigs_ref_destroy_func destroy;
- QemuMutex mutex;
- volatile uint32_t count;
+ uint32_t count;
};
/*
yagl_process_register_egl_interface(cur_ts->ps, egl_api_ps->egl_iface);
- qemu_mutex_init(&egl_api_ps->mutex);
-
QLIST_INIT(&egl_api_ps->displays);
}
{
assert(QLIST_EMPTY(&egl_api_ps->displays));
- qemu_mutex_destroy(&egl_api_ps->mutex);
-
yagl_process_unregister_egl_interface(cur_ts->ps);
}
{
struct yagl_egl_display *dpy;
- qemu_mutex_lock(&egl_api_ps->mutex);
-
QLIST_FOREACH(dpy, &egl_api_ps->displays, entry) {
if (dpy->handle == handle) {
- qemu_mutex_unlock(&egl_api_ps->mutex);
-
return dpy;
}
}
- qemu_mutex_unlock(&egl_api_ps->mutex);
-
return NULL;
}
{
struct yagl_egl_display *dpy;
- qemu_mutex_lock(&egl_api_ps->mutex);
-
QLIST_FOREACH(dpy, &egl_api_ps->displays, entry) {
if (dpy->display_id == display_id) {
- qemu_mutex_unlock(&egl_api_ps->mutex);
-
return dpy;
}
}
dpy = yagl_egl_display_create(egl_api_ps->backend, display_id);
if (!dpy) {
- qemu_mutex_unlock(&egl_api_ps->mutex);
-
return NULL;
}
QLIST_INSERT_HEAD(&egl_api_ps->displays, dpy, entry);
- qemu_mutex_unlock(&egl_api_ps->mutex);
-
return dpy;
}
#define _QEMU_YAGL_EGL_API_PS_H
#include "yagl_api.h"
-#include "qemu-thread.h"
#include "qemu-queue.h"
struct yagl_egl_interface;
struct yagl_egl_api_ps
{
- /*
- * Can access these without locking.
- * @{
- */
-
struct yagl_api_ps base;
struct yagl_egl_backend *backend;
struct yagl_egl_interface *egl_iface;
- /*
- * @}
- */
-
- QemuMutex mutex;
-
QLIST_HEAD(, yagl_egl_display) displays;
};
dpy->handle = yagl_handle_gen();
dpy->backend_dpy = backend_dpy;
- qemu_mutex_init(&dpy->mutex);
-
dpy->initialized = false;
yagl_resource_list_init(&dpy->configs);
yagl_resource_list_cleanup(&dpy->contexts);
yagl_resource_list_cleanup(&dpy->configs);
- qemu_mutex_destroy(&dpy->mutex);
-
dpy->backend_dpy->destroy(dpy->backend_dpy);
g_free(dpy);
YAGL_LOG_FUNC_ENTER(yagl_egl_display_initialize, NULL);
- qemu_mutex_lock(&dpy->mutex);
-
if (dpy->initialized) {
goto out;
}
out:
dpy->initialized = true;
- qemu_mutex_unlock(&dpy->mutex);
-
YAGL_LOG_FUNC_EXIT(NULL);
}
{
bool ret;
- qemu_mutex_lock(&dpy->mutex);
-
ret = dpy->initialized;
- qemu_mutex_unlock(&dpy->mutex);
-
return ret;
}
yagl_resource_list_init(&tmp_list);
- qemu_mutex_lock(&dpy->mutex);
-
yagl_resource_list_move(&dpy->images, &tmp_list);
yagl_resource_list_move(&dpy->surfaces, &tmp_list);
yagl_resource_list_move(&dpy->contexts, &tmp_list);
dpy->initialized = false;
- qemu_mutex_unlock(&dpy->mutex);
-
- /*
- * We release here because we don't want the resources to be released
- * when display mutex is held.
- */
-
yagl_resource_list_cleanup(&tmp_list);
}
{
int ret;
- qemu_mutex_lock(&dpy->mutex);
-
ret = yagl_resource_list_get_count(&dpy->configs);
- qemu_mutex_unlock(&dpy->mutex);
-
return ret;
}
struct yagl_resource *res;
int i = 0;
- qemu_mutex_lock(&dpy->mutex);
-
QTAILQ_FOREACH(res, &dpy->configs.resources, entry) {
if (i >= *num_configs) {
break;
++i;
}
- qemu_mutex_unlock(&dpy->mutex);
-
*num_configs = i;
return handles;
handles = g_malloc(*num_configs * sizeof(yagl_host_handle));
}
- qemu_mutex_lock(&dpy->mutex);
-
QTAILQ_FOREACH(res, &dpy->configs.resources, entry) {
if (!count_only && (i >= *num_configs)) {
break;
}
}
- qemu_mutex_unlock(&dpy->mutex);
-
*num_configs = i;
return handles;
*yagl_egl_display_acquire_config(struct yagl_egl_display *dpy,
yagl_host_handle handle)
{
- struct yagl_egl_config *cfg;
-
- qemu_mutex_lock(&dpy->mutex);
-
- cfg = (struct yagl_egl_config*)yagl_resource_list_acquire(&dpy->configs, handle);
-
- qemu_mutex_unlock(&dpy->mutex);
-
- return cfg;
+ return (struct yagl_egl_config*)yagl_resource_list_acquire(&dpy->configs, handle);
}
struct yagl_egl_config
{
struct yagl_resource *res;
- qemu_mutex_lock(&dpy->mutex);
-
QTAILQ_FOREACH(res, &dpy->configs.resources, entry) {
if (((struct yagl_egl_config*)res)->native.config_id == config_id) {
yagl_resource_acquire(res);
- qemu_mutex_unlock(&dpy->mutex);
-
return (struct yagl_egl_config*)res;
}
}
- qemu_mutex_unlock(&dpy->mutex);
-
return NULL;
}
void yagl_egl_display_add_context(struct yagl_egl_display *dpy,
struct yagl_egl_context *ctx)
{
- qemu_mutex_lock(&dpy->mutex);
-
yagl_resource_list_add(&dpy->contexts, &ctx->res);
-
- qemu_mutex_unlock(&dpy->mutex);
}
struct yagl_egl_context
*yagl_egl_display_acquire_context(struct yagl_egl_display *dpy,
yagl_host_handle handle)
{
- struct yagl_egl_context *ctx;
-
- qemu_mutex_lock(&dpy->mutex);
-
- ctx = (struct yagl_egl_context*)yagl_resource_list_acquire(&dpy->contexts, handle);
-
- qemu_mutex_unlock(&dpy->mutex);
-
- return ctx;
+ return (struct yagl_egl_context*)yagl_resource_list_acquire(&dpy->contexts, handle);
}
bool yagl_egl_display_remove_context(struct yagl_egl_display *dpy,
yagl_host_handle handle)
{
- bool res;
-
- qemu_mutex_lock(&dpy->mutex);
-
- res = yagl_resource_list_remove(&dpy->contexts, handle);
-
- qemu_mutex_unlock(&dpy->mutex);
-
- return res;
+ return yagl_resource_list_remove(&dpy->contexts, handle);
}
void yagl_egl_display_add_surface(struct yagl_egl_display *dpy,
struct yagl_egl_surface *sfc)
{
- qemu_mutex_lock(&dpy->mutex);
-
yagl_resource_list_add(&dpy->surfaces, &sfc->res);
-
- qemu_mutex_unlock(&dpy->mutex);
}
struct yagl_egl_surface
*yagl_egl_display_acquire_surface(struct yagl_egl_display *dpy,
yagl_host_handle handle)
{
- struct yagl_egl_surface *sfc;
-
- qemu_mutex_lock(&dpy->mutex);
-
- sfc = (struct yagl_egl_surface*)yagl_resource_list_acquire(&dpy->surfaces, handle);
-
- qemu_mutex_unlock(&dpy->mutex);
-
- return sfc;
+ return (struct yagl_egl_surface*)yagl_resource_list_acquire(&dpy->surfaces, handle);
}
bool yagl_egl_display_remove_surface(struct yagl_egl_display *dpy,
yagl_host_handle handle)
{
- bool res;
-
- qemu_mutex_lock(&dpy->mutex);
-
- res = yagl_resource_list_remove(&dpy->surfaces, handle);
-
- qemu_mutex_unlock(&dpy->mutex);
-
- return res;
+ return yagl_resource_list_remove(&dpy->surfaces, handle);
}
void yagl_egl_display_add_image(struct yagl_egl_display *dpy,
struct yagl_egl_image *image)
{
- qemu_mutex_lock(&dpy->mutex);
-
yagl_resource_list_add(&dpy->images, &image->res);
-
- qemu_mutex_unlock(&dpy->mutex);
}
struct yagl_egl_image
*yagl_egl_display_acquire_image(struct yagl_egl_display *dpy,
yagl_host_handle handle)
{
- struct yagl_egl_image *image;
-
- qemu_mutex_lock(&dpy->mutex);
-
- image = (struct yagl_egl_image*)yagl_resource_list_acquire(&dpy->images, handle);
-
- qemu_mutex_unlock(&dpy->mutex);
-
- return image;
+ return (struct yagl_egl_image*)yagl_resource_list_acquire(&dpy->images, handle);
}
bool yagl_egl_display_remove_image(struct yagl_egl_display *dpy,
yagl_host_handle handle)
{
- bool res;
-
- qemu_mutex_lock(&dpy->mutex);
-
- res = yagl_resource_list_remove(&dpy->images, handle);
-
- qemu_mutex_unlock(&dpy->mutex);
-
- return res;
+ return yagl_resource_list_remove(&dpy->images, handle);
}
#include "yagl_types.h"
#include "yagl_resource_list.h"
-#include "qemu-thread.h"
#include "qemu-queue.h"
#include <EGL/egl.h>
struct yagl_egl_display
{
- /*
- * Don't need to lock these.
- * @{
- */
-
QLIST_ENTRY(yagl_egl_display) entry;
struct yagl_egl_backend *backend;
struct yagl_eglb_display *backend_dpy;
- /*
- * @}
- */
-
- QemuMutex mutex;
-
bool initialized;
struct yagl_resource_list configs;
sfc->backend_sfc->destroy(sfc->backend_sfc);
- qemu_mutex_destroy(&sfc->backend_sfc_mtx);
-
yagl_egl_config_release(sfc->cfg);
yagl_resource_cleanup(&sfc->res);
sfc->dpy = dpy;
yagl_egl_config_acquire(cfg);
sfc->cfg = cfg;
- qemu_mutex_init(&sfc->backend_sfc_mtx);
sfc->backend_sfc = backend_sfc;
return sfc;
}
-void yagl_egl_surface_lock(struct yagl_egl_surface *sfc)
-{
- qemu_mutex_lock(&sfc->backend_sfc_mtx);
-}
-
-void yagl_egl_surface_unlock(struct yagl_egl_surface *sfc)
-{
- qemu_mutex_unlock(&sfc->backend_sfc_mtx);
-}
-
void yagl_egl_surface_acquire(struct yagl_egl_surface *sfc)
{
if (sfc) {
#include "yagl_types.h"
#include "yagl_resource.h"
-#include "qemu-thread.h"
struct yagl_egl_display;
struct yagl_egl_config;
struct yagl_egl_config *cfg;
- /*
- * Backend surfaces are the only ones that
- * can be accessed from multiple threads
- * simultaneously. When we call
- * eglDestroySurface we want to destroy backend surface
- * immediately. The surface however
- * may be accessed from another thread where it's current
- * (from eglSwapBuffers for example), in that case the result of the call
- * must be EGL_BAD_SURFACE.
- */
- QemuMutex backend_sfc_mtx;
-
struct yagl_eglb_surface *backend_sfc;
};
struct yagl_eglb_surface *backend_sfc);
/*
- * Lock/unlock surface for 'backend_sfc' access, all 'backend_sfc' operations
- * must be carried out while surface is locked.
- * @{
- */
-
-void yagl_egl_surface_lock(struct yagl_egl_surface *sfc);
-
-void yagl_egl_surface_unlock(struct yagl_egl_surface *sfc);
-
-/*
- * @}
- */
-
-/*
* Helper functions that simply acquire/release yagl_egl_surface::res
* @{
*/
goto out;
}
- yagl_egl_surface_lock(surface);
-
- if (surface->backend_sfc->invalid) {
- yagl_egl_surface_unlock(surface);
- YAGL_LOG_CRITICAL("we're the one who invalidate the surface, but it's already invalid!");
- YAGL_SET_ERR(EGL_BAD_SURFACE);
- goto out;
- }
-
surface->backend_sfc->invalidate(surface->backend_sfc);
- yagl_egl_surface_unlock(surface);
-
*retval = EGL_TRUE;
out:
value = EGL_MULTISAMPLE_RESOLVE_DEFAULT;
break;
default:
- yagl_egl_surface_lock(surface);
if (!surface->backend_sfc->query(surface->backend_sfc,
attribute,
&value)) {
- yagl_egl_surface_unlock(surface);
YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
goto out;
}
- yagl_egl_surface_unlock(surface);
}
if (!yagl_mem_prepare_EGLint(cur_ts->mt1, value_)) {
goto out;
}
- yagl_egl_surface_lock(surface);
-
- if (surface->backend_sfc->invalid) {
- yagl_egl_surface_unlock(surface);
- YAGL_SET_ERR(EGL_BAD_SURFACE);
- goto out;
- }
-
if (!surface->backend_sfc->swap_buffers(surface->backend_sfc)) {
- yagl_egl_surface_unlock(surface);
YAGL_SET_ERR(EGL_BAD_ALLOC);
goto out;
}
- yagl_egl_surface_unlock(surface);
-
*retval = EGL_TRUE;
out:
goto out;
}
- yagl_egl_surface_lock(surface);
-
- if (surface->backend_sfc->invalid) {
- yagl_egl_surface_unlock(surface);
- YAGL_SET_ERR(EGL_BAD_SURFACE);
- goto out;
- }
-
if (!surface->backend_sfc->copy_buffers(surface->backend_sfc, target)) {
- yagl_egl_surface_unlock(surface);
YAGL_SET_ERR(EGL_BAD_NATIVE_PIXMAP);
goto out;
}
- yagl_egl_surface_unlock(surface);
-
*retval = EGL_TRUE;
out:
}
}
- yagl_egl_surface_lock(surface);
-
- if (surface->backend_sfc->invalid) {
- yagl_egl_surface_unlock(surface);
- YAGL_LOG_ERROR("surface was destroyed, weird scenario!");
- YAGL_SET_ERR(EGL_BAD_SURFACE);
- goto out;
- }
-
if (!egl_api_ts->backend->make_current(egl_api_ts->backend,
dpy->backend_dpy,
egl_api_ts->context->backend_ctx,
draw_sfc,
read_sfc)) {
- yagl_egl_surface_unlock(surface);
YAGL_LOG_ERROR("make_current failed");
YAGL_SET_ERR(EGL_BAD_ALLOC);
goto out;
backend_sfc = NULL;
- yagl_egl_surface_unlock(surface);
-
*retval = EGL_TRUE;
out:
yagl_range_list_cleanup(&buffer->fixed_part.range_list);
yagl_range_list_cleanup(&buffer->byte_part.range_list);
- qemu_mutex_destroy(&buffer->mutex);
-
g_free(buffer->data);
yagl_object_cleanup(&buffer->base);
buffer->driver = driver;
- qemu_mutex_init(&buffer->mutex);
-
driver->GenBuffers(1, &buffer->default_part.global_name);
yagl_range_list_init(&buffer->default_part.range_list);
void *data,
GLenum usage)
{
- qemu_mutex_lock(&buffer->mutex);
-
if (size > 0) {
if (size > buffer->size) {
g_free(buffer->data);
yagl_range_list_add(&buffer->default_part.range_list, 0, buffer->size);
yagl_range_list_add(&buffer->fixed_part.range_list, 0, buffer->size);
yagl_range_list_add(&buffer->byte_part.range_list, 0, buffer->size);
-
- qemu_mutex_unlock(&buffer->mutex);
}
bool yagl_gles_buffer_update_data(struct yagl_gles_buffer *buffer,
GLint size,
void *data)
{
- qemu_mutex_lock(&buffer->mutex);
-
if ((offset < 0) || (size < 0) || ((offset + size) > buffer->size)) {
- qemu_mutex_unlock(&buffer->mutex);
return false;
}
if (size == 0) {
- qemu_mutex_unlock(&buffer->mutex);
return true;
}
yagl_range_list_add(&buffer->fixed_part.range_list, offset, size);
yagl_range_list_add(&buffer->byte_part.range_list, offset, size);
- qemu_mutex_unlock(&buffer->mutex);
-
return true;
}
return false;
}
- qemu_mutex_lock(&buffer->mutex);
-
if ((offset < 0) || (count <= 0) || ((offset + (count * index_size)) > buffer->size)) {
- qemu_mutex_unlock(&buffer->mutex);
return false;
}
}
}
- qemu_mutex_unlock(&buffer->mutex);
-
return true;
}
return false;
}
- qemu_mutex_lock(&buffer->mutex);
-
if (need_convert) {
switch (type) {
case GL_BYTE:
&yagl_gles_buffer_transfer_default);
}
- qemu_mutex_unlock(&buffer->mutex);
-
buffer->driver->BindBuffer(target, old_buffer_name);
return true;
GLenum pname,
GLint *param)
{
- qemu_mutex_lock(&buffer->mutex);
-
switch (pname) {
case GL_BUFFER_SIZE:
*param = buffer->size;
*param = buffer->usage;
break;
default:
- qemu_mutex_unlock(&buffer->mutex);
return false;
}
- qemu_mutex_unlock(&buffer->mutex);
-
return true;
}
void yagl_gles_buffer_set_bound(struct yagl_gles_buffer *buffer)
{
- qemu_mutex_lock(&buffer->mutex);
-
buffer->was_bound = true;
-
- qemu_mutex_unlock(&buffer->mutex);
}
bool yagl_gles_buffer_was_bound(struct yagl_gles_buffer *buffer)
{
- bool ret = false;
-
- qemu_mutex_lock(&buffer->mutex);
-
- ret = buffer->was_bound;
-
- qemu_mutex_unlock(&buffer->mutex);
-
- return ret;
+ return buffer->was_bound;
}
#include "yagl_types.h"
#include "yagl_object.h"
#include "yagl_range_list.h"
-#include "qemu-thread.h"
/*
* VBO implementation is somewhat tricky because
struct yagl_gles_driver *driver;
- QemuMutex mutex;
-
struct yagl_gles_buffer_part default_part;
struct yagl_gles_buffer_part fixed_part;
struct yagl_gles_buffer_part byte_part;
fb->driver->DeleteFramebuffers(1, &fb->global_name);
yagl_unensure_ctx();
- qemu_mutex_destroy(&fb->mutex);
-
yagl_object_cleanup(&fb->base);
g_free(fb);
fb->driver = driver;
fb->global_name = global_name;
- qemu_mutex_init(&fb->mutex);
-
for (i = 0; i < YAGL_NUM_GLES_FRAMEBUFFER_ATTACHMENTS; ++i) {
fb->attachment_states[i].type = GL_NONE;
}
return false;
}
- qemu_mutex_lock(&fb->mutex);
-
if (rb) {
fb->attachment_states[framebuffer_attachment].type = GL_RENDERBUFFER;
fb->attachment_states[framebuffer_attachment].local_name = rb_local_name;
(rb ? rb->global_name : 0));
}
- qemu_mutex_unlock(&fb->mutex);
-
return true;
}
return false;
}
- qemu_mutex_lock(&fb->mutex);
-
if (texture) {
fb->attachment_states[framebuffer_attachment].type = GL_TEXTURE;
fb->attachment_states[framebuffer_attachment].local_name = texture_local_name;
level);
}
- qemu_mutex_unlock(&fb->mutex);
-
return true;
}
return false;
}
- qemu_mutex_lock(&fb->mutex);
-
switch (pname) {
case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
*value = fb->attachment_states[framebuffer_attachment].type;
value);
break;
default:
- qemu_mutex_unlock(&fb->mutex);
return false;
}
- qemu_mutex_unlock(&fb->mutex);
-
return true;
}
void yagl_gles_framebuffer_set_bound(struct yagl_gles_framebuffer *fb)
{
- qemu_mutex_lock(&fb->mutex);
-
fb->was_bound = true;
-
- qemu_mutex_unlock(&fb->mutex);
}
bool yagl_gles_framebuffer_was_bound(struct yagl_gles_framebuffer *fb)
{
- bool ret = false;
-
- qemu_mutex_lock(&fb->mutex);
-
- ret = fb->was_bound;
-
- qemu_mutex_unlock(&fb->mutex);
-
- return ret;
+ return fb->was_bound;
}
yagl_object_name global_name;
- QemuMutex mutex;
-
struct yagl_gles_framebuffer_attachment_state attachment_states[YAGL_NUM_GLES_FRAMEBUFFER_ATTACHMENTS];
bool was_bound;
rb->driver->DeleteRenderbuffers(1, &rb->global_name);
yagl_unensure_ctx();
- qemu_mutex_destroy(&rb->mutex);
-
yagl_object_cleanup(&rb->base);
g_free(rb);
rb->driver = driver;
rb->global_name = global_name;
- qemu_mutex_init(&rb->mutex);
-
return rb;
}
void yagl_gles_renderbuffer_set_bound(struct yagl_gles_renderbuffer *rb)
{
- qemu_mutex_lock(&rb->mutex);
-
rb->was_bound = true;
-
- qemu_mutex_unlock(&rb->mutex);
}
bool yagl_gles_renderbuffer_was_bound(struct yagl_gles_renderbuffer *rb)
{
- bool ret = false;
-
- qemu_mutex_lock(&rb->mutex);
-
- ret = rb->was_bound;
-
- qemu_mutex_unlock(&rb->mutex);
-
- return ret;
+ return rb->was_bound;
}
yagl_object_name global_name;
- QemuMutex mutex;
-
bool was_bound;
};
yagl_unensure_ctx();
}
- qemu_mutex_destroy(&texture->mutex);
-
yagl_object_cleanup(&texture->base);
g_free(texture);
texture->global_name = global_name;
texture->target = 0;
- qemu_mutex_init(&texture->mutex);
-
return texture;
}
bool yagl_gles_texture_bind(struct yagl_gles_texture *texture,
GLenum target)
{
- qemu_mutex_lock(&texture->mutex);
-
if (texture->target && (texture->target != target)) {
- qemu_mutex_unlock(&texture->mutex);
return false;
}
texture->target = target;
- qemu_mutex_unlock(&texture->mutex);
-
return true;
}
GLenum yagl_gles_texture_get_target(struct yagl_gles_texture *texture)
{
- GLenum target;
-
- qemu_mutex_lock(&texture->mutex);
-
- target = texture->target;
-
- qemu_mutex_unlock(&texture->mutex);
-
- return target;
+ return texture->target;
}
void yagl_gles_texture_set_image(struct yagl_gles_texture *texture,
assert(texture->target);
assert(image);
- qemu_mutex_lock(&texture->mutex);
-
if (texture->image == image) {
- qemu_mutex_unlock(&texture->mutex);
return;
}
texture->driver->BindTexture(texture->target,
texture->global_name);
-
- qemu_mutex_unlock(&texture->mutex);
}
void yagl_gles_texture_unset_image(struct yagl_gles_texture *texture)
{
- qemu_mutex_lock(&texture->mutex);
-
if (texture->image) {
GLuint global_name = 0;
texture->driver->BindTexture(texture->target,
texture->global_name);
}
-
- qemu_mutex_unlock(&texture->mutex);
}
struct yagl_gles_driver *driver;
- QemuMutex mutex;
-
yagl_object_name global_name;
GLenum target;
program->driver->DeleteProgram(program->global_name);
yagl_unensure_ctx();
- qemu_mutex_destroy(&program->mutex);
-
yagl_object_cleanup(&program->base);
g_free(program);
program->driver = driver;
program->global_name = global_name;
- qemu_mutex_init(&program->mutex);
-
return program;
}
struct yagl_gles2_shader *shader,
yagl_object_name shader_local_name)
{
- qemu_mutex_lock(&program->mutex);
-
switch (shader->type) {
case GL_VERTEX_SHADER:
if (program->vertex_shader_local_name) {
- qemu_mutex_unlock(&program->mutex);
return false;
}
program->vertex_shader_local_name = shader_local_name;
break;
case GL_FRAGMENT_SHADER:
if (program->fragment_shader_local_name) {
- qemu_mutex_unlock(&program->mutex);
return false;
}
program->fragment_shader_local_name = shader_local_name;
break;
default:
- qemu_mutex_unlock(&program->mutex);
return false;
}
program->driver->AttachShader(program->global_name,
shader->global_name);
- qemu_mutex_unlock(&program->mutex);
-
return true;
}
struct yagl_gles2_shader *shader,
yagl_object_name shader_local_name)
{
- qemu_mutex_lock(&program->mutex);
-
if (program->vertex_shader_local_name == shader_local_name) {
program->vertex_shader_local_name = 0;
} else if (program->fragment_shader_local_name == shader_local_name) {
program->fragment_shader_local_name = 0;
} else {
- qemu_mutex_unlock(&program->mutex);
return false;
}
program->driver->DetachShader(program->global_name,
shader->global_name);
- qemu_mutex_unlock(&program->mutex);
-
return true;
}
yagl_object_name global_name;
- QemuMutex mutex;
-
yagl_object_name vertex_shader_local_name;
yagl_object_name fragment_shader_local_name;
uint32_t bpp,
target_ulong pixels)
{
- struct yagl_egl_offscreen_image *oimage =
- (struct yagl_egl_offscreen_image*)image;
struct yagl_eglb_context *ctx =
(egl_offscreen_ts->ctx ? &egl_offscreen_ts->ctx->base : NULL);
- bool res;
if (!ctx) {
return true;
}
- qemu_mutex_lock(&oimage->update_mtx);
-
if (!image->glegl_image) {
image->glegl_image = ctx->client_ctx->create_image(ctx->client_ctx);
if (!image->glegl_image) {
- qemu_mutex_unlock(&oimage->update_mtx);
return true;
}
}
- res = image->glegl_image->update(image->glegl_image, width, height, bpp, pixels);
-
- qemu_mutex_unlock(&oimage->update_mtx);
-
- return res;
+ return image->glegl_image->update(image->glegl_image, width, height, bpp, pixels);
}
static void yagl_egl_offscreen_image_destroy(struct yagl_eglb_image *image)
YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_image_destroy, NULL);
- qemu_mutex_destroy(&oimage->update_mtx);
-
yagl_eglb_image_cleanup(image);
g_free(oimage);
yagl_eglb_image_init(&image->base, buffer, &dpy->base);
- qemu_mutex_init(&image->update_mtx);
-
image->base.update_offscreen = &yagl_egl_offscreen_image_update;
image->base.destroy = &yagl_egl_offscreen_image_destroy;
#define _QEMU_YAGL_EGL_OFFSCREEN_IMAGE_H
#include "yagl_eglb_image.h"
-#include "qemu-thread.h"
struct yagl_egl_offscreen_display;
struct yagl_egl_offscreen_image
{
struct yagl_eglb_image base;
-
- /*
- * To serialize 'update_offscreen'.
- */
- QemuMutex update_mtx;
};
struct yagl_egl_offscreen_image
yagl_compiled_transfer_destroy(osfc->bimage_ct);
osfc->bimage_ct = NULL;
-
- sfc->invalid = true;
}
static void yagl_egl_offscreen_surface_replace(struct yagl_eglb_surface *sfc,
static void yagl_egl_onscreen_surface_invalidate(struct yagl_eglb_surface *sfc)
{
- sfc->invalid = true;
}
static bool yagl_egl_onscreen_surface_query(struct yagl_eglb_surface *sfc,
EGLenum type;
- bool invalid;
-
union
{
struct yagl_egl_window_attribs window;
} attribs;
/*
- * The following function are guaranteed to
- * be serialized.
- * @{
- */
-
- /*
* Indicates that user has called eglDestroySurface on this
* surface. Surface cannot be destroyed immediately, since
* it can be current to some thread, but its resources
- * can be released here. Implementation must set 'invalid'
- * to true if the surface should be considered invalid. If
- * a surface is invalid then calls to eglSwapBuffers,
- * eglCopyBuffers, etc will fail automatically.
+ * can be released here.
*/
void (*invalidate)(struct yagl_eglb_surface */*sfc*/);
yagl_winsys_id /*target*/);
void (*destroy)(struct yagl_eglb_surface */*sfc*/);
-
- /*
- * @}
- */
};
void yagl_eglb_surface_init(struct yagl_eglb_surface *sfc,
#include "yagl_handle_gen.h"
-#include "qemu-thread.h"
static yagl_host_handle g_handle_gen_next = 0;
-static QemuMutex g_handle_gen_mutex;
void yagl_handle_gen_init(void)
{
- qemu_mutex_init(&g_handle_gen_mutex);
}
void yagl_handle_gen_reset(void)
{
- qemu_mutex_lock(&g_handle_gen_mutex);
g_handle_gen_next = 0;
- qemu_mutex_unlock(&g_handle_gen_mutex);
}
void yagl_handle_gen_cleanup(void)
{
- qemu_mutex_destroy(&g_handle_gen_mutex);
}
yagl_host_handle yagl_handle_gen(void)
{
yagl_host_handle ret;
- qemu_mutex_lock(&g_handle_gen_mutex);
if (!g_handle_gen_next)
{
/*
++g_handle_gen_next;
}
ret = g_handle_gen_next++;
- qemu_mutex_unlock(&g_handle_gen_mutex);
return ret;
}
#include "yagl_log.h"
-#include "qemu-thread.h"
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
static char** g_log_facilities_match = NULL;
static char** g_log_facilities_no_match = NULL;
static bool g_log_func_trace = false;
-static QemuMutex g_log_mutex;
static const char* yagl_log_datatype_to_format(const char* type)
{
char* facilities;
char* func_trace;
- qemu_mutex_init(&g_log_mutex);
-
if (level < 0)
{
g_log_level = yagl_log_level_off;
g_log_facilities_match = NULL;
}
g_log_func_trace = 0;
- qemu_mutex_destroy(&g_log_mutex);
}
void yagl_log_event(yagl_log_level log_level,
{
va_list args;
- qemu_mutex_lock(&g_log_mutex);
-
yagl_log_print_current_time();
fprintf(stderr,
" %-5s [%u/%u] %s:%d",
va_end(args);
}
fprintf(stderr, "\n");
-
- qemu_mutex_unlock(&g_log_mutex);
}
void yagl_log_func_enter(yagl_pid process_id,
{
va_list args;
- qemu_mutex_lock(&g_log_mutex);
-
yagl_log_print_current_time();
fprintf(stderr,
" %-5s [%u/%u] {{{ %s(",
va_end(args);
}
fprintf(stderr, "):%d\n", line);
-
- qemu_mutex_unlock(&g_log_mutex);
}
void yagl_log_func_exit(yagl_pid process_id,
{
va_list args;
- qemu_mutex_lock(&g_log_mutex);
-
yagl_log_print_current_time();
fprintf(stderr,
" %-5s [%u/%u] }}} %s:%d",
va_end(args);
}
fprintf(stderr, "\n");
-
- qemu_mutex_unlock(&g_log_mutex);
}
void yagl_log_func_enter_split(yagl_pid process_id,
char format[1025] = { '\0' };
va_list args;
- qemu_mutex_lock(&g_log_mutex);
-
yagl_log_print_current_time();
fprintf(stderr,
" %-5s [%u/%u] {{{ %s(",
}
fprintf(stderr, "):%d\n", line);
-
- qemu_mutex_unlock(&g_log_mutex);
}
void yagl_log_func_exit_split(yagl_pid process_id,
{
va_list args;
- qemu_mutex_lock(&g_log_mutex);
-
yagl_log_print_current_time();
fprintf(stderr,
" %-5s [%u/%u] }}} %s:%d",
}
fprintf(stderr, "\n");
-
- qemu_mutex_unlock(&g_log_mutex);
}
bool yagl_log_is_enabled_for_level(yagl_log_level log_level)
memset(ref, 0, sizeof(*ref));
ref->destroy = destroy;
- qemu_mutex_init(&ref->mutex);
ref->count = 1;
yagl_stats_new_ref();
assert(ref);
assert(!ref->count);
- qemu_mutex_destroy(&ref->mutex);
-
yagl_stats_delete_ref();
}
assert(ref);
assert(ref->count > 0);
- qemu_mutex_lock(&ref->mutex);
++ref->count;
- qemu_mutex_unlock(&ref->mutex);
}
void yagl_ref_release(struct yagl_ref *ref)
{
- bool call_destroy = false;
-
assert(ref);
assert(ref->count > 0);
- qemu_mutex_lock(&ref->mutex);
- call_destroy = (--ref->count == 0);
- qemu_mutex_unlock(&ref->mutex);
-
- if (call_destroy)
+ if (--ref->count == 0)
{
assert(ref->destroy);
ref->destroy(ref);
#define _QEMU_YAGL_REF_H
#include "yagl_types.h"
-#include "qemu-thread.h"
struct yagl_ref;
{
yagl_ref_destroy_func destroy;
- QemuMutex mutex;
- volatile uint32_t count;
+ uint32_t count;
};
/*
yagl_namespace_cleanup(&sg->namespaces[i]);
}
- qemu_mutex_destroy(&sg->mutex);
-
yagl_ref_cleanup(&sg->ref);
g_free(sg);
yagl_ref_init(&sg->ref, &yagl_sharegroup_destroy);
- qemu_mutex_init(&sg->mutex);
-
for (i = 0; i < YAGL_NUM_NAMESPACES; ++i) {
yagl_namespace_init(&sg->namespaces[i]);
}
int ns,
struct yagl_object *obj)
{
- yagl_object_name local_name;
-
- qemu_mutex_lock(&sg->mutex);
-
- local_name = yagl_namespace_add(&sg->namespaces[ns], obj);
-
- qemu_mutex_unlock(&sg->mutex);
-
- return local_name;
+ return yagl_namespace_add(&sg->namespaces[ns], obj);
}
struct yagl_object *yagl_sharegroup_add_named(struct yagl_sharegroup *sg,
yagl_object_name local_name,
struct yagl_object *obj)
{
- struct yagl_object *ret;
-
- qemu_mutex_lock(&sg->mutex);
-
- ret = yagl_namespace_add_named(&sg->namespaces[ns], local_name, obj);
-
- qemu_mutex_unlock(&sg->mutex);
-
- return ret;
+ return yagl_namespace_add_named(&sg->namespaces[ns], local_name, obj);
}
void yagl_sharegroup_remove(struct yagl_sharegroup *sg,
int ns,
yagl_object_name local_name)
{
- qemu_mutex_lock(&sg->mutex);
-
yagl_namespace_remove(&sg->namespaces[ns], local_name);
-
- qemu_mutex_unlock(&sg->mutex);
}
void yagl_sharegroup_remove_check(struct yagl_sharegroup *sg,
{
struct yagl_object *actual_obj;
- qemu_mutex_lock(&sg->mutex);
-
actual_obj = yagl_namespace_acquire(&sg->namespaces[ns], local_name);
if (actual_obj == obj) {
}
yagl_object_release(actual_obj);
-
- qemu_mutex_unlock(&sg->mutex);
}
struct yagl_object *yagl_sharegroup_acquire_object(struct yagl_sharegroup *sg,
int ns,
yagl_object_name local_name)
{
- struct yagl_object *obj;
-
- qemu_mutex_lock(&sg->mutex);
-
- obj = yagl_namespace_acquire(&sg->namespaces[ns], local_name);
-
- qemu_mutex_unlock(&sg->mutex);
-
- return obj;
+ return yagl_namespace_acquire(&sg->namespaces[ns], local_name);
}
#include "yagl_types.h"
#include "yagl_ref.h"
#include "yagl_namespace.h"
-#include "qemu-thread.h"
#define YAGL_NUM_NAMESPACES 5
{
struct yagl_ref ref;
- QemuMutex mutex;
-
struct yagl_namespace namespaces[YAGL_NUM_NAMESPACES];
};
#include "yagl_log.h"
#include "yagl_process.h"
#include "yagl_thread.h"
-#include "qemu-thread.h"
#ifdef CONFIG_YAGL_STATS
static uint32_t g_num_calls = 0;
static uint32_t g_bytes_unused = UINT32_MAX;
-static QemuMutex g_stats_mutex;
-
void yagl_stats_init(void)
{
- qemu_mutex_init(&g_stats_mutex);
}
void yagl_stats_cleanup(void)
{
- qemu_mutex_destroy(&g_stats_mutex);
}
void yagl_stats_new_ref(void)
{
- qemu_mutex_lock(&g_stats_mutex);
++g_num_refs;
- qemu_mutex_unlock(&g_stats_mutex);
}
void yagl_stats_delete_ref(void)
{
- qemu_mutex_lock(&g_stats_mutex);
if (g_num_refs-- == 0) {
assert(0);
}
- qemu_mutex_unlock(&g_stats_mutex);
}
void yagl_stats_batch(uint32_t num_calls, uint32_t bytes_unused)
{
- qemu_mutex_lock(&g_stats_mutex);
-
if (num_calls > g_num_calls) {
g_num_calls = num_calls;
}
}
if (++g_num_batches >= YAGL_STATS_MAX_BATCHES) {
- qemu_mutex_unlock(&g_stats_mutex);
yagl_stats_dump();
- qemu_mutex_lock(&g_stats_mutex);
g_num_batches = 0;
g_num_calls = 0;
g_bytes_unused = UINT32_MAX;
}
-
- qemu_mutex_unlock(&g_stats_mutex);
}
void yagl_stats_dump(void)
{
YAGL_LOG_FUNC_ENTER(yagl_stats_dump, NULL);
- qemu_mutex_lock(&g_stats_mutex);
-
YAGL_LOG_DEBUG("<<STATS");
YAGL_LOG_DEBUG("num yagl_ref's: %u", g_num_refs);
YAGL_LOG_DEBUG("# of calls per batch: %u",
((g_bytes_unused == UINT32_MAX) ? 0 : g_bytes_unused));
YAGL_LOG_DEBUG(">>STATS");
- qemu_mutex_unlock(&g_stats_mutex);
-
YAGL_LOG_FUNC_EXIT(NULL);
}