channels: remove thread-local storage usage
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Tue, 15 Nov 2016 16:41:01 +0000 (11:41 -0500)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Tue, 15 Nov 2016 16:41:01 +0000 (11:41 -0500)
26 files changed:
channels/audin/client/alsa/audin_alsa.c
channels/audin/client/oss/audin_oss.c
channels/audin/server/audin.c
channels/cliprdr/client/cliprdr_main.c
channels/cliprdr/server/cliprdr_main.c
channels/drdynvc/server/drdynvc_main.c
channels/drive/client/drive_main.c
channels/echo/server/echo_main.c
channels/encomsp/client/encomsp_main.c
channels/encomsp/server/encomsp_main.c
channels/parallel/client/parallel_main.c
channels/printer/client/printer_main.c
channels/rail/client/rail_main.c
channels/rdpdr/client/rdpdr_main.c
channels/rdpdr/server/rdpdr_main.c
channels/rdpei/client/rdpei_main.c
channels/rdpgfx/server/rdpgfx_main.c
channels/rdpsnd/client/rdpsnd_main.c
channels/rdpsnd/server/rdpsnd_main.c
channels/remdesk/client/remdesk_main.c
channels/remdesk/server/remdesk_main.c
channels/serial/client/serial_main.c
channels/smartcard/client/smartcard_main.c
channels/tsmf/client/tsmf_media.c
include/freerdp/freerdp.h
libfreerdp/core/freerdp.c

index 73cca5f..c776fa7 100644 (file)
@@ -230,7 +230,7 @@ static void* audin_alsa_thread_func(void* arg)
        AudinALSADevice* alsa = (AudinALSADevice*) arg;
        DWORD status;
        DEBUG_DVC("in");
-       freerdp_channel_init_thread_context(alsa->rdpcontext);
+
        rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel;
        tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel;
        buffer = (BYTE*) calloc(1, rbytes_per_frame * alsa->frames_per_packet);
index 28edc3a..b1f3db7 100644 (file)
@@ -190,8 +190,6 @@ static void* audin_oss_thread_func(void* arg)
                goto err_out;
        }
 
-       freerdp_channel_init_thread_context(oss->rdpcontext);
-
        if (oss->dev_unit != -1)
        {
                sprintf_s(dev_name, (PATH_MAX - 1), "/dev/dsp%i", oss->dev_unit);
index 39d4c7d..cefef4c 100644 (file)
@@ -417,7 +417,6 @@ static void* audin_server_thread_func(void* arg)
        buffer = NULL;
        BytesReturned = 0;
        ChannelEvent = NULL;
-       freerdp_channel_init_thread_context(audin->context.rdpcontext);
 
        if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualEventHandle, &buffer,
                                   &BytesReturned) == TRUE)
index 0cefefb..c0bcd2a 100644 (file)
@@ -1052,7 +1052,6 @@ static void* cliprdr_virtual_channel_client_thread(void* arg)
        wMessage message;
        cliprdrPlugin* cliprdr = (cliprdrPlugin*) arg;
        UINT error = CHANNEL_RC_OK;
-       freerdp_channel_init_thread_context(cliprdr->context->rdpcontext);
 
        while (1)
        {
index bbc9870..80955c7 100644 (file)
@@ -1328,7 +1328,7 @@ static void* cliprdr_server_thread(void* arg)
        CliprdrServerContext* context = (CliprdrServerContext*) arg;
        CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
        UINT error;
-       freerdp_channel_init_thread_context(context->rdpcontext);
+
        ChannelEvent = context->GetEventHandle(context);
        nCount = 0;
        events[nCount++] = cliprdr->StopEvent;
index 7dd71e2..bf2b40e 100644 (file)
@@ -49,7 +49,7 @@ static void* drdynvc_server_thread(void* arg)
        buffer = NULL;
        BytesReturned = 0;
        ChannelEvent = NULL;
-       freerdp_channel_init_thread_context(context->rdpcontext);
+
        s = Stream_New(NULL, 4096);
 
        if (!s)
index 41ba191..1df2ddd 100644 (file)
@@ -683,7 +683,6 @@ static void* drive_thread_func(void* arg)
        wMessage message;
        DRIVE_DEVICE* drive = (DRIVE_DEVICE*) arg;
        UINT error = CHANNEL_RC_OK;
-       freerdp_channel_init_thread_context(drive->rdpcontext);
 
        while (1)
        {
index e4ae1e8..277a37e 100644 (file)
@@ -117,7 +117,6 @@ static void* echo_server_thread_func(void* arg)
        echo_server* echo = (echo_server*) arg;
        UINT error;
        DWORD status;
-       freerdp_channel_init_thread_context(echo->context.rdpcontext);
 
        if ((error = echo_server_open_channel(echo)))
        {
index d896d31..6f2e830 100644 (file)
@@ -1045,7 +1045,7 @@ static void* encomsp_virtual_channel_client_thread(void* arg)
        wMessage message;
        encomspPlugin* encomsp = (encomspPlugin*) arg;
        UINT error = CHANNEL_RC_OK;
-       freerdp_channel_init_thread_context(encomsp->rdpcontext);
+
        encomsp_process_connect(encomsp);
 
        while (1)
index 4116c15..4c3cbae 100644 (file)
@@ -187,7 +187,7 @@ static void* encomsp_server_thread(void* arg)
        UINT error = CHANNEL_RC_OK;
        DWORD status;
        context = (EncomspServerContext*) arg;
-       freerdp_channel_init_thread_context(context->rdpcontext);
+
        buffer = NULL;
        BytesReturned = 0;
        ChannelEvent = NULL;
index dda95ce..c38e4de 100644 (file)
@@ -310,7 +310,6 @@ static void* parallel_thread_func(void* arg)
        wMessage message;
        PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) arg;
        UINT error = CHANNEL_RC_OK;
-       freerdp_channel_init_thread_context(parallel->rdpcontext);
 
        while (1)
        {
index 6a569a0..210cb77 100644 (file)
@@ -237,7 +237,6 @@ static void* printer_thread_func(void* arg)
        PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*) arg;
        HANDLE obj[] = {printer_dev->event, printer_dev->stopEvent};
        UINT error = CHANNEL_RC_OK;
-       freerdp_channel_init_thread_context(printer_dev->rdpcontext);
 
        while (1)
        {
index 14f8563..456598d 100644 (file)
@@ -586,7 +586,6 @@ static void* rail_virtual_channel_client_thread(void* arg)
        wMessage message;
        railPlugin* rail = (railPlugin*) arg;
        UINT error = CHANNEL_RC_OK;
-       freerdp_channel_init_thread_context(rail->rdpcontext);
 
        while (1)
        {
index 0c8fdb1..0b1062d 100755 (executable)
@@ -864,7 +864,6 @@ static void* drive_hotplug_thread_func(void* arg)
        UINT error = 0;
        DWORD status;
        rdpdr = (rdpdrPlugin*) arg;
-       freerdp_channel_init_thread_context(rdpdr->rdpcontext);
 
        if (!(rdpdr->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
        {
@@ -1563,8 +1562,6 @@ static void* rdpdr_virtual_channel_client_thread(void* arg)
                return NULL;
        }
 
-       freerdp_channel_init_thread_context(rdpdr->rdpcontext);
-
        if ((error = rdpdr_process_connect(rdpdr)))
        {
                WLog_ERR(TAG, "rdpdr_process_connect failed with error %lu!", error);
index 397cd78..2ee7885 100644 (file)
@@ -1151,7 +1151,7 @@ static void* rdpdr_server_thread(void* arg)
        buffer = NULL;
        BytesReturned = 0;
        ChannelEvent = NULL;
-       freerdp_channel_init_thread_context(context->rdpcontext);
+
        s = Stream_New(NULL, 4096);
 
        if (!s)
index 0177723..d3fa8f2 100644 (file)
@@ -176,7 +176,6 @@ static void* rdpei_schedule_thread(void* arg)
        RdpeiClientContext* context = (RdpeiClientContext*) rdpei->iface.pInterface;
        HANDLE hdl[] = {rdpei->event, rdpei->stopEvent};
        UINT error = CHANNEL_RC_OK;
-       freerdp_channel_init_thread_context(rdpei->rdpcontext);
 
        if (!rdpei)
        {
index 1f471d3..63aefba 100644 (file)
@@ -1335,7 +1335,7 @@ static void* rdpgfx_server_thread_func(void* arg)
        buffer = NULL;
        BytesReturned = 0;
        nCount = 0;
-       freerdp_channel_init_thread_context(context->rdpcontext);
+
        events[nCount++] = priv->stopEvent;
        events[nCount++] = priv->channelEvent;
 
index 1194e00..b400909 100644 (file)
@@ -113,7 +113,7 @@ static void* rdpsnd_schedule_thread(void* arg)
        HANDLE events[2];
        UINT error = CHANNEL_RC_OK;
        DWORD status;
-       freerdp_channel_init_thread_context(rdpsnd->rdpcontext);
+
        events[0] = MessageQueue_Event(rdpsnd->MsgPipe->Out);
        events[1] = rdpsnd->stopEvent;
 
@@ -1247,7 +1247,6 @@ static void* rdpsnd_virtual_channel_client_thread(void* arg)
        wMessage message;
        rdpsndPlugin* rdpsnd = (rdpsndPlugin*) arg;
        UINT error;
-       freerdp_channel_init_thread_context(rdpsnd->rdpcontext);
 
        if ((error = rdpsnd_process_connect(rdpsnd)))
        {
index f62ebf5..09f6d27 100644 (file)
@@ -246,7 +246,7 @@ static void* rdpsnd_server_thread(void* arg)
        RdpsndServerContext* context;
        UINT error = CHANNEL_RC_OK;
        context = (RdpsndServerContext*)arg;
-       freerdp_channel_init_thread_context(context->rdpcontext);
+
        nCount = 0;
        events[nCount++] = context->priv->channelEvent;
        events[nCount++] = context->priv->StopEvent;
index 52711b0..9dea16b 100644 (file)
@@ -848,7 +848,7 @@ static void* remdesk_virtual_channel_client_thread(void* arg)
        wMessage message;
        remdeskPlugin* remdesk = (remdeskPlugin*) arg;
        UINT error = CHANNEL_RC_OK;
-       freerdp_channel_init_thread_context(remdesk->rdpcontext);
+
        remdesk_process_connect(remdesk);
 
        while (1)
index 36feb2c..4531740 100644 (file)
@@ -592,7 +592,7 @@ static void* remdesk_server_thread(void* arg)
        RemdeskServerContext* context;
        UINT error;
        context = (RemdeskServerContext*) arg;
-       freerdp_channel_init_thread_context(context->rdpcontext);
+
        buffer = NULL;
        BytesReturned = 0;
        ChannelEvent = NULL;
index c97ea21..6d04df1 100644 (file)
@@ -462,7 +462,6 @@ static void* irp_thread_func(void* arg)
 {
        IRP_THREAD_DATA* data = (IRP_THREAD_DATA*)arg;
        UINT error;
-       freerdp_channel_init_thread_context(data->serial->rdpcontext);
 
        /* blocks until the end of the request */
        if ((error = serial_process_irp(data->serial, data->irp)))
@@ -680,7 +679,6 @@ static void* serial_thread_func(void* arg)
        wMessage message;
        SERIAL_DEVICE* serial = (SERIAL_DEVICE*) arg;
        UINT error = CHANNEL_RC_OK;
-       freerdp_channel_init_thread_context(serial->rdpcontext);
 
        while (1)
        {
index 9b04637..0d2e315 100644 (file)
@@ -45,7 +45,7 @@ void* smartcard_context_thread(SMARTCARD_CONTEXT* pContext)
        SMARTCARD_OPERATION* operation;
        UINT error = CHANNEL_RC_OK;
        smartcard = pContext->smartcard;
-       freerdp_channel_init_thread_context(smartcard->rdpcontext);
+
        nCount = 0;
        hEvents[nCount++] = MessageQueue_Event(pContext->IrpQueue);
 
@@ -516,7 +516,7 @@ static void* smartcard_thread_func(void* arg)
        wMessage message;
        SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) arg;
        UINT error = CHANNEL_RC_OK;
-       freerdp_channel_init_thread_context(smartcard->rdpcontext);
+
        nCount = 0;
        hEvents[nCount++] = MessageQueue_Event(smartcard->IrpQueue);
        hEvents[nCount++] = Queue_Event(smartcard->CompletedIrpQueue);
index 17af1fa..c4c6c29 100644 (file)
@@ -718,7 +718,7 @@ static void* tsmf_stream_ack_func(void* arg)
        TSMF_STREAM* stream = (TSMF_STREAM*) arg;
        UINT error = CHANNEL_RC_OK;
        DEBUG_TSMF("in %d", stream->stream_id);
-       freerdp_channel_init_thread_context(stream->rdpcontext);
+
        hdl[0] = stream->stopEvent;
        hdl[1] = Queue_Event(stream->sample_ack_list);
 
@@ -806,7 +806,6 @@ static void* tsmf_stream_playback_func(void* arg)
        UINT error = CHANNEL_RC_OK;
        DWORD status;
        DEBUG_TSMF("in %d", stream->stream_id);
-       freerdp_channel_init_thread_context(stream->rdpcontext);
 
        if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO &&
            stream->sample_rate && stream->channels && stream->bits_per_sample)
index 0f71777..4abe1fb 100644 (file)
@@ -307,10 +307,6 @@ FREERDP_API BOOL freerdp_shall_disconnect(freerdp* instance);
 FREERDP_API BOOL freerdp_disconnect(freerdp* instance);
 FREERDP_API BOOL freerdp_reconnect(freerdp* instance);
 
-FREERDP_API void freerdp_channel_init_thread_context(rdpContext* context);
-FREERDP_API freerdp* freerdp_channel_get_instance(void);
-FREERDP_API rdpContext* freerdp_channel_get_context(void);
-
 FREERDP_API UINT freerdp_channel_add_init_handle_data(rdpChannelHandles* handles, void* pInitHandle, void* pUserData);
 FREERDP_API void* freerdp_channel_get_init_handle_data(rdpChannelHandles* handles, void* pInitHandle);
 FREERDP_API void freerdp_channel_remove_init_handle_data(rdpChannelHandles* handles, void* pInitHandle);
index 8fd967a..ee974ac 100644 (file)
 
 /* connectErrorCode is 'extern' in error.h. See comment there.*/
 
-/* Thread local storage variables.
- * They need to be initialized in every thread that
- * has to use them. */
-static WINPR_TLS rdpContext* s_TLSContext = NULL;
-
-void freerdp_channel_init_thread_context(rdpContext* context)
-{
-       s_TLSContext = context;
-}
-
-freerdp* freerdp_channel_get_instance(void)
-{
-       if (!s_TLSContext)
-       {
-               WLog_ERR(TAG,
-                        "Funcion was called from thread that did not call freerdp_channel_init_thread_context");
-               winpr_log_backtrace(TAG, WLOG_ERROR, 20);
-               return NULL;
-       }
-
-       return s_TLSContext->instance;
-}
-
-rdpContext* freerdp_channel_get_context(void)
-{
-       return s_TLSContext;
-}
-
 UINT freerdp_channel_add_init_handle_data(rdpChannelHandles* handles, void* pInitHandle, void* pUserData)
 {
        if (!handles->init)
@@ -181,7 +153,6 @@ BOOL freerdp_connect(freerdp* instance)
        if (!instance)
                return FALSE;
 
-       freerdp_channel_init_thread_context(instance->context);
        /* We always set the return code to 0 before we start the connect sequence*/
        connectErrorCode = 0;
        freerdp_set_last_error(instance->context, FREERDP_ERROR_SUCCESS);