summaryrefslogtreecommitdiffstats
path: root/xrdp/xrdp.c
diff options
context:
space:
mode:
Diffstat (limited to 'xrdp/xrdp.c')
-rw-r--r--xrdp/xrdp.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/xrdp/xrdp.c b/xrdp/xrdp.c
index fb8dfbc0..9fc10df6 100644
--- a/xrdp/xrdp.c
+++ b/xrdp/xrdp.c
@@ -22,6 +22,8 @@
#include "xrdp.h"
+#define THREAD_WAITING 100
+
static struct xrdp_listen* g_listen = 0;
static long g_threadid = 0; /* main threadid */
@@ -37,6 +39,9 @@ static long g_sync_param2 = 0;
static long (*g_sync_func)(long param1, long param2);
/*****************************************************************************/
+/* This function is used to run a function from the main thread.
+ Sync_func is the function pointer that will run from main thread
+ The function can have two long in parameters and must return long */
long APP_CC
g_xrdp_sync(long (*sync_func)(long param1, long param2), long sync_param1,
long sync_param2)
@@ -44,31 +49,45 @@ g_xrdp_sync(long (*sync_func)(long param1, long param2), long sync_param1,
long sync_result;
int sync_command;
+ /* If the function is called from the main thread, the function can
+ * be called directly. g_threadid= main thread ID*/
if (tc_threadid_equal(tc_get_threadid(), g_threadid))
{
/* this is the main thread, call the function directly */
sync_result = sync_func(sync_param1, sync_param2);
+ /*g_writeln("g_xrdp_sync processed IN main thread -> continue");*/
}
else
{
+ /* All threads have to wait here until the main thread
+ * process the function. g_process_waiting_function() is called
+ * from the listening thread. g_process_waiting_function() process the function*/
tc_mutex_lock(g_sync1_mutex);
tc_mutex_lock(g_sync_mutex);
g_sync_param1 = sync_param1;
g_sync_param2 = sync_param2;
g_sync_func = sync_func;
- g_sync_command = 100;
+ /* set a value THREAD_WAITING so the g_process_waiting_function function
+ * know if any function must be processed */
+ g_sync_command = THREAD_WAITING;
tc_mutex_unlock(g_sync_mutex);
- g_set_wait_obj(g_sync_event);
+ /* set this event so that the main thread know if
+ * g_process_waiting_function() must be called */
+ g_set_wait_obj(g_sync_event);
do
{
g_sleep(100);
tc_mutex_lock(g_sync_mutex);
- sync_command = g_sync_command;
+ /* load new value from global to see if the g_process_waiting_function()
+ * function has processed the function */
+ sync_command = g_sync_command;
sync_result = g_sync_result;
tc_mutex_unlock(g_sync_mutex);
}
- while (sync_command != 0);
+ while (sync_command != 0); /* loop until g_process_waiting_function()
+ * has processed the request*/
tc_mutex_unlock(g_sync1_mutex);
+ /*g_writeln("g_xrdp_sync processed BY main thread -> continue");*/
}
return sync_result;
}
@@ -132,15 +151,17 @@ pipe_sig(int sig_num)
}
/*****************************************************************************/
+/*Some function must be called from the main thread.
+ if g_sync_command==THREAD_WAITING a function is waiting to be processed*/
void APP_CC
-g_loop(void)
+g_process_waiting_function(void)
{
tc_mutex_lock(g_sync_mutex);
if (g_sync_command != 0)
{
if (g_sync_func != 0)
{
- if (g_sync_command == 100)
+ if (g_sync_command == THREAD_WAITING)
{
g_sync_result = g_sync_func(g_sync_param1, g_sync_param2);
}
@@ -426,12 +447,16 @@ main(int argc, char** argv)
pid = g_getpid();
g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid);
g_term_event = g_create_wait_obj(text);
- g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid);
- g_sync_event = g_create_wait_obj(text);
if (g_term_event == 0)
{
g_writeln("error creating g_term_event");
}
+ g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid);
+ g_sync_event = g_create_wait_obj(text);
+ if (g_sync_event == 0)
+ {
+ g_writeln("error creating g_sync_event");
+ }
xrdp_listen_main_loop(g_listen, startup_params);
xrdp_listen_delete(g_listen);
tc_mutex_delete(g_sync_mutex);