Skip to content
  • Stefan Hajnoczi's avatar
    ac387a08
    coroutine: use QEMU_DEFINE_STATIC_CO_TLS() · ac387a08
    Stefan Hajnoczi authored
    
    
    Thread-Local Storage variables cannot be used directly from coroutine
    code because the compiler may optimize TLS variable accesses across
    qemu_coroutine_yield() calls. When the coroutine is re-entered from
    another thread the TLS variables from the old thread must no longer be
    used.
    
    Use QEMU_DEFINE_STATIC_CO_TLS() for the current and leader variables.
    The alloc_pool QSLIST needs a typedef so the return value of
    get_ptr_alloc_pool() can be stored in a local variable.
    
    One example of why this code is necessary: a coroutine that yields
    before calling qemu_coroutine_create() to create another coroutine is
    affected by the TLS issue.
    
    Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
    Message-Id: <20220307153853.602859-3-stefanha@redhat.com>
    Reviewed-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    ac387a08
    coroutine: use QEMU_DEFINE_STATIC_CO_TLS()
    Stefan Hajnoczi authored
    
    
    Thread-Local Storage variables cannot be used directly from coroutine
    code because the compiler may optimize TLS variable accesses across
    qemu_coroutine_yield() calls. When the coroutine is re-entered from
    another thread the TLS variables from the old thread must no longer be
    used.
    
    Use QEMU_DEFINE_STATIC_CO_TLS() for the current and leader variables.
    The alloc_pool QSLIST needs a typedef so the return value of
    get_ptr_alloc_pool() can be stored in a local variable.
    
    One example of why this code is necessary: a coroutine that yields
    before calling qemu_coroutine_create() to create another coroutine is
    affected by the TLS issue.
    
    Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
    Message-Id: <20220307153853.602859-3-stefanha@redhat.com>
    Reviewed-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Loading