Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1451 → Rev 1452

/uspace/trunk/libc/include/unistd.h
38,5 → 38,6
extern ssize_t write(int fd, const void * buf, size_t count);
extern void _exit(int status);
void *sbrk(ssize_t incr);
void usleep(unsigned long usec);
 
#endif
/uspace/trunk/libc/include/async.h
13,15 → 13,17
int _async_init(void);
ipc_callid_t async_get_call(ipc_call_t *data);
 
pstid_t async_new_connection(ipc_callid_t callid, ipc_call_t *call,
void (*cthread)(ipc_callid_t,ipc_call_t *));
aid_t async_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
ipc_call_t *dataptr);
void async_wait_for(aid_t amsgid, ipcarg_t *result);
int async_wait_timeout(aid_t amsgid, ipcarg_t *retval, suseconds_t timeout);
pstid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid,
ipc_call_t *call,
void (*cthread)(ipc_callid_t,ipc_call_t *));
void async_usleep(suseconds_t timeout);
 
 
/* Should be defined by application */
void client_connection(ipc_callid_t callid, ipc_call_t *call) __attribute__((weak));
void interrupt_received(ipc_call_t *call) __attribute__((weak));
 
#endif
/uspace/trunk/libc/generic/time.c
31,6 → 31,9
#include <ipc/ipc.h>
#include <stdio.h>
#include <arch/barrier.h>
#include <unistd.h>
#include <atomic.h>
#include <futex.h>
 
#include <sysinfo.h>
#include <as.h>
93,3 → 96,12
 
return 0;
}
 
/** Wait unconditionally for specified miliseconds */
void usleep(unsigned long usec)
{
atomic_t futex = FUTEX_INITIALIZER;
 
futex_initialize(&futex,0);
futex_down_timeout(&futex, usec, 0);
}
/uspace/trunk/libc/generic/io/stream.c
64,8 → 64,7
if (console_phone < 0) {
while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
volatile int a;
for (a = 0; a < 1048576; a++);
usleep(10000);
}
}
/uspace/trunk/libc/generic/async.c
269,6 → 269,16
ipc_answer_fast(callid, ENOENT, 0, 0);
}
 
/** Function that gets created on interrupt receival
*
* This function is defined as a weak symbol - to be redefined in
* user code.
*/
void interrupt_received(ipc_call_t *call)
{
}
 
 
/** Wrapper for client connection thread
*
* When new connection arrives, thread with this function is created.
308,6 → 318,7
* later we can easily do routing of messages to particular
* threads.
*
* @param in_phone_hash Identification of the incoming connection
* @param callid Callid of the IPC_M_CONNECT_ME_TO packet
* @param call Call data of the opening packet
* @param cthread Thread function that should be called upon
314,7 → 325,8
* opening the connection
* @return New thread id
*/
pstid_t async_new_connection(ipc_callid_t callid, ipc_call_t *call,
pstid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid,
ipc_call_t *call,
void (*cthread)(ipc_callid_t,ipc_call_t *))
{
pstid_t ptid;
326,7 → 338,7
ipc_answer_fast(callid, ENOMEM, 0, 0);
return NULL;
}
conn->in_phone_hash = IPC_GET_ARG3(*call);
conn->in_phone_hash = in_phone_hash;
list_initialize(&conn->msg_queue);
conn->ptid = psthread_create(connection_thread, conn);
conn->callid = callid;
353,19 → 365,23
/** Handle call that was received */
static void handle_call(ipc_callid_t callid, ipc_call_t *call)
{
if (route_call(callid, call))
return;
 
/* Unrouted call - do some default behaviour */
switch (IPC_GET_METHOD(*call)) {
case IPC_M_INTERRUPT:
break;
interrupt_received(call);
return;
case IPC_M_CONNECT_ME_TO:
/* Open new connection with thread etc. */
async_new_connection(callid, call, client_connection);
break;
default:
ipc_answer_fast(callid, EHANGUP, 0, 0);
async_new_connection(IPC_GET_ARG3(*call), callid, call, client_connection);
return;
}
 
/* Try to route call through connection tables */
if (route_call(callid, call))
return;
 
/* Unknown call from unknown phone - hang it up */
ipc_answer_fast(callid, EHANGUP, 0, 0);
}
 
/** Fire all timeouts that expired */
621,3 → 637,29
return 0;
}
 
/** Wait specified time, but in the meantime handle incoming events
*
* @param timeout Time in microseconds to wait
*/
void async_usleep(suseconds_t timeout)
{
amsg_t *msg;
msg = malloc(sizeof(*msg));
if (!msg)
return;
 
msg->ptid = psthread_get_id();
msg->active = 0;
msg->has_timeout = 1;
 
gettimeofday(&msg->expires, NULL);
tv_add(&msg->expires, timeout);
 
futex_down(&async_futex);
insert_timeout(msg);
/* Leave locked async_futex when entering this function */
psthread_schedule_next_adv(PS_TO_MANAGER);
/* futex is up automatically after psthread_schedule_next...*/
free(msg);
}