Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1610 → Rev 1609

/uspace/trunk/libc/generic/async.c
134,11 → 134,8
void (*cthread)(ipc_callid_t,ipc_call_t *);
} connection_t;
 
/** Identifier of incoming connection handled by current thread */
 
__thread connection_t *PS_connection;
/** If true, it is forbidden to use async_req functions and
* all preemption is disabled */
__thread int in_interrupt_handler;
 
static void default_client_connection(ipc_callid_t callid, ipc_call_t *call);
static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call);
228,7 → 225,6
awaiter_t *cur;
 
wd->timedout = 0;
wd->inlist = 1;
 
tmp = timeout_list.next;
while (tmp != &timeout_list) {
298,6 → 294,9
*/
conn = PS_connection;
 
if (usecs < 0) /* TODO: let it get through the ipc_call once */
return 0;
 
futex_down(&async_futex);
 
if (usecs) {
308,9 → 307,10
}
/* If nothing in queue, wait until something appears */
while (list_empty(&conn->msg_queue)) {
if (usecs)
if (usecs) {
conn->wdata.inlist = 1;
insert_timeout(&conn->wdata);
 
}
conn->wdata.active = 0;
psthread_schedule_next_adv(PS_TO_MANAGER);
/* Futex is up after getting back from async_manager
362,6 → 362,7
/* Setup thread local connection pointer */
PS_connection = (connection_t *)arg;
PS_connection->cthread(PS_connection->callid, &PS_connection->call);
 
/* Remove myself from connection hash table */
futex_down(&async_futex);
key = PS_connection->in_phone_hash;
434,9 → 435,7
/* Unrouted call - do some default behaviour */
switch (IPC_GET_METHOD(*call)) {
case IPC_M_INTERRUPT:
in_interrupt_handler = 1;
(*interrupt_received)(callid,call);
in_interrupt_handler = 0;
return;
case IPC_M_CONNECT_ME_TO:
/* Open new connection with thread etc. */
486,7 → 485,7
}
 
/** Endless loop dispatching incoming calls and answers */
static int async_manager_worker(void)
int async_manager(void)
{
ipc_call_t call;
ipc_callid_t callid;
522,9 → 521,8
continue;
}
 
if (callid & IPC_CALLID_ANSWERED) {
if (callid & IPC_CALLID_ANSWERED)
continue;
}
 
handle_call(callid, &call);
}
539,10 → 537,9
*/
static int async_manager_thread(void *arg)
{
in_interrupt_handler = 0; // TODO: Handle TLS better
futex_up(&async_futex); /* async_futex is always locked when entering
* manager */
async_manager_worker();
async_manager();
}
 
/** Add one manager to manager list */
610,11 → 607,6
{
amsg_t *msg;
 
if (in_interrupt_handler) {
printf("Cannot send asynchronou request in interrupt handler.\n");
_exit(1);
}
 
msg = malloc(sizeof(*msg));
msg->done = 0;
msg->dataptr = dataptr;
636,11 → 628,6
{
amsg_t *msg;
 
if (in_interrupt_handler) {
printf("Cannot send asynchronou request in interrupt handler.\n");
_exit(1);
}
 
msg = malloc(sizeof(*msg));
msg->done = 0;
msg->dataptr = dataptr;
711,6 → 698,8
 
msg->wdata.ptid = psthread_get_id();
msg->wdata.active = 0;
msg->wdata.inlist = 1;
 
insert_timeout(&msg->wdata);
 
/* Leave locked async_futex when entering this function */
736,16 → 725,12
{
amsg_t *msg;
if (in_interrupt_handler) {
printf("Cannot call async_usleep in interrupt handler.\n");
_exit(1);
}
 
msg = malloc(sizeof(*msg));
if (!msg)
return;
 
msg->wdata.ptid = psthread_get_id();
msg->wdata.inlist = 1;
msg->wdata.active = 0;
 
gettimeofday(&msg->wdata.expires, NULL);
771,15 → 756,3
{
interrupt_received = conn;
}
 
/* Primitive functions for simple communication */
void async_msg_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
ipcarg_t arg2, ipcarg_t arg3)
{
ipc_call_async_3(phoneid, method, arg1, arg2, arg3, NULL, NULL, !in_interrupt_handler);
}
 
void async_msg_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2)
{
ipc_call_async_2(phoneid, method, arg1, arg2, NULL, NULL, !in_interrupt_handler);
}