yagl: Remove cur_ts global variable (1/3) 18/243118/1
authorLukasz Kostyra <l.kostyra@samsung.com>
Tue, 11 Aug 2020 11:33:04 +0000 (13:33 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Thu, 3 Sep 2020 07:49:50 +0000 (09:49 +0200)
commitcbbf50bc721e1f285efbb75ce985dacae10440f7
tree1a299704a01dcf583268a878340a9981322f6996
parentb536515abba5403ad13f9eade98697c57e68fce5
yagl: Remove cur_ts global variable (1/3)

cur_ts was a global variable used for easy global access to currently
running thread's state. Access to the variable was not synchronized at
all. The variable was overwritten each time a thread started working
and NULLed each time a thread stopped working. This was a cause
of multitude of multithreading issues in yagl code. Some examples are:
- Thread A could NULLify cur_ts after finishing work while thread B
tries to dereference it during logging routine setup. This in turn can
result in a randomly occuring segmentation fault (ex. when calling
YAGL_LOG_FUNC_ENTER which accessed cur_ts for PID/TID info).
- Information in cur_ts could be misleading for thread A because
thread B set its own instance of cur_ts right after thread A.
- Memory leaks and other issues due to cur_ts being re-allocated on the
same global pointer.

Issues have to be resolved by removing cur_ts. Now every thread based
function has a first parameter cur_ts, which provides the same information
in a per-thread and reentrant-safe manner.

In situations where cur_ts could not be reached (ex. initialization or
main thread code) YAGL_LOG_NO_TS macro was introduced, which for now sets
pid/tid information to 0. Macro's proper implementation will be done in
upcoming changes.

Some yagl modules also used local _ts structures (ex. egl_api_ts or
egl_onscreen_ts) and used them in the same way cur_ts was managed.
These also provide thread/reentry dangers and will be removed in
consecutive commits.

Change-Id: I9c55371a522d8f06cb3ce8120f88946e9d246695
52 files changed:
hw/yagl/yagl_api.h
hw/yagl/yagl_apis/egl/yagl_egl_api_ps.c
hw/yagl/yagl_apis/egl/yagl_egl_api_ps.h
hw/yagl/yagl_apis/egl/yagl_egl_api_ts.c
hw/yagl/yagl_apis/egl/yagl_egl_api_ts.h
hw/yagl/yagl_apis/egl/yagl_egl_calls.c
hw/yagl/yagl_apis/egl/yagl_egl_context.c
hw/yagl/yagl_apis/egl/yagl_egl_context.h
hw/yagl/yagl_apis/egl/yagl_egl_display.c
hw/yagl/yagl_apis/egl/yagl_egl_display.h
hw/yagl/yagl_apis/egl/yagl_host_egl_calls.c
hw/yagl/yagl_apis/egl/yagl_host_egl_calls.h
hw/yagl/yagl_apis/gles/yagl_gles_api_ts.c
hw/yagl/yagl_apis/gles/yagl_gles_api_ts.h
hw/yagl/yagl_apis/gles/yagl_gles_calls.c
hw/yagl/yagl_apis/gles/yagl_host_gles_calls.c
hw/yagl/yagl_apis/gles/yagl_host_gles_calls.h
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen.c
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.c
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.h
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_display.c
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_surface.c
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_surface.h
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen.c
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.c
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.h
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_display.c
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_surface.c
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_surface.h
hw/yagl/yagl_compiled_transfer.c
hw/yagl/yagl_compiled_transfer.h
hw/yagl/yagl_device.c
hw/yagl/yagl_drivers/egl_glx/yagl_egl_glx.c
hw/yagl/yagl_drivers/gles_ogl/yagl_gles_ogl.c
hw/yagl/yagl_drivers/gles_onscreen/yagl_gles_onscreen.c
hw/yagl/yagl_egl_backend.h
hw/yagl/yagl_eglb_context.h
hw/yagl/yagl_eglb_display.h
hw/yagl/yagl_eglb_surface.h
hw/yagl/yagl_gles_driver.c
hw/yagl/yagl_gles_driver.h
hw/yagl/yagl_log.h
hw/yagl/yagl_mem.c
hw/yagl/yagl_mem.h
hw/yagl/yagl_object_map.h
hw/yagl/yagl_process.c
hw/yagl/yagl_server.c
hw/yagl/yagl_thread.c
hw/yagl/yagl_thread.h
hw/yagl/yagl_transport.c
hw/yagl/yagl_transport.h
hw/yagl/yagl_types.h