Hand-apply patches (chansrv/rail) from Authentic8: 516fd1d 6a4fb28 c038a99

This commit is contained in:
Jim Grandy
2013-07-06 08:42:05 -07:00
parent 2291519714
commit 142a93829b
3 changed files with 212 additions and 91 deletions
+139
View File
@@ -76,6 +76,143 @@ int g_exec_pid = 0;
/* this variable gets bumped up once per DVC we create */
tui32 g_dvc_chan_id = 100;
struct timeout_obj
{
tui32 mstime;
void* data;
void (*callback)(void* data);
struct timeout_obj* next;
};
static struct timeout_obj* g_timeout_head = 0;
static struct timeout_obj* g_timeout_tail = 0;
/*****************************************************************************/
int APP_CC
add_timeout(int msoffset, void (*callback)(void* data), void* data)
{
struct timeout_obj* tobj;
tui32 now;
LOG(10, ("add_timeout:"));
now = g_time3();
tobj = g_malloc(sizeof(struct timeout_obj), 1);
tobj->mstime = now + msoffset;
tobj->callback = callback;
tobj->data = data;
if (g_timeout_tail == 0)
{
g_timeout_head = tobj;
g_timeout_tail = tobj;
}
else
{
g_timeout_tail->next = tobj;
g_timeout_tail = tobj;
}
return 0;
}
/*****************************************************************************/
static int APP_CC
get_timeout(int* timeout)
{
struct timeout_obj* tobj;
tui32 now;
int ltimeout;
LOG(10, ("get_timeout:"));
ltimeout = *timeout;
if (ltimeout < 1)
{
ltimeout = 0;
}
tobj = g_timeout_head;
if (tobj != 0)
{
now = g_time3();
while (tobj != 0)
{
LOG(10, (" now %u tobj->mstime %u", now, tobj->mstime));
if (now < tobj->mstime)
{
ltimeout = tobj->mstime - now;
}
tobj = tobj->next;
}
}
if (ltimeout > 0)
{
LOG(10, (" ltimeout %d", ltimeout));
if (*timeout < 1)
{
*timeout = ltimeout;
}
else
{
if (*timeout > ltimeout)
{
*timeout = ltimeout;
}
}
}
return 0;
}
/*****************************************************************************/
static int APP_CC
check_timeout(void)
{
struct timeout_obj* tobj;
struct timeout_obj* last_tobj;
struct timeout_obj* temp_tobj;
int count;
tui32 now;
LOG(10, ("check_timeout:"));
count = 0;
tobj = g_timeout_head;
if (tobj != 0)
{
last_tobj = 0;
while (tobj != 0)
{
count++;
now = g_time3();
if (now >= tobj->mstime)
{
tobj->callback(tobj->data);
if (last_tobj == 0)
{
g_timeout_head = tobj->next;
if (g_timeout_head == 0)
{
g_timeout_tail = 0;
}
}
else
{
last_tobj->next = tobj->next;
if (g_timeout_tail == tobj)
{
g_timeout_tail = last_tobj;
}
}
temp_tobj = tobj;
tobj = tobj->next;
g_free(temp_tobj);
}
else
{
last_tobj = tobj;
tobj = tobj->next;
}
}
}
LOG(10, (" count %d", count));
return 0;
}
/*****************************************************************************/
/* add data to chan_item, on its way to the client */
/* returns error */
@@ -940,6 +1077,7 @@ channel_thread_loop(void *in_val)
while (g_obj_wait(objs, num_objs, 0, 0, timeout) == 0)
{
check_timeout();
if (g_is_wait_obj_set(g_term_event))
{
LOGM((LOG_LEVEL_INFO, "channel_thread_loop: g_term_event set"));
@@ -1022,6 +1160,7 @@ channel_thread_loop(void *in_val)
sound_get_wait_objs(objs, &num_objs, &timeout);
dev_redir_get_wait_objs(objs, &num_objs, &timeout);
xfuse_get_wait_objs(objs, &num_objs, &timeout);
get_timeout(&timeout);
} /* end while (g_obj_wait(objs, num_objs, 0, 0, timeout) == 0) */
}