Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1609 → Rev 1610

/uspace/trunk/fb/helenos.xbm
File deleted
/uspace/trunk/fb/fb.c
42,7 → 42,6
#include <async.h>
 
#include "font-8x16.h"
#include "helenos.xbm"
#include "fb.h"
#include "main.h"
#include "../console/screenbuffer.h"
/uspace/trunk/klog/klog.c
40,12 → 40,12
{
int i;
// psthread_serialize_start();
async_serialize_start();
/* TODO: remove workaround around non-functional vsnprintf */
for (i=0; klog[i + IPC_GET_ARG2(*call)] && i < IPC_GET_ARG3(*call); i++)
putchar(klog[i + IPC_GET_ARG2(*call)]);
putchar('\n');
// psthread_serialize_done();
async_serialize_end();
}
 
int main(int argc, char *argv[])
/uspace/trunk/kbd/generic/kbd.c
38,9 → 38,67
#include <kbd.h>
#include <libadt/fifo.h>
#include <key_buffer.h>
#include <async.h>
 
#define NAME "KBD"
 
int cons_connected = 0;
int phone2cons = -1;
keybuffer_t keybuffer;
 
static void irq_handler(ipc_callid_t iid, ipc_call_t *call)
{
int chr;
if (cons_connected && phone2cons != -1) {
/* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */
kbd_arch_process(&keybuffer, IPC_GET_ARG2(*call));
while (!keybuffer_empty(&keybuffer)) {
if (!keybuffer_pop(&keybuffer, (int *)&chr))
break;
 
async_msg(phone2cons, KBD_PUSHCHAR, chr);
}
}
}
 
static void console_connection(ipc_callid_t iid, ipc_call_t *icall)
{
ipc_callid_t callid;
ipc_call_t call;
int retval;
 
if (cons_connected) {
ipc_answer_fast(iid, ELIMIT, 0, 0);
return;
}
cons_connected = 1;
ipc_answer_fast(iid, 0, 0, 0);
 
while (1) {
callid = async_get_call(&call);
switch (IPC_GET_METHOD(call)) {
case IPC_M_PHONE_HUNGUP:
cons_connected = 0;
ipc_hangup(phone2cons);
phone2cons = -1;
ipc_answer_fast(callid, 0,0,0);
return;
case IPC_M_CONNECT_TO_ME:
if (phone2cons != -1) {
retval = ELIMIT;
break;
}
phone2cons = IPC_GET_ARG3(call);
retval = 0;
break;
}
ipc_answer_fast(callid, retval, 0, 0);
}
}
 
 
int main(int argc, char **argv)
{
ipc_call_t call;
49,12 → 107,8
ipcarg_t phonead;
ipcarg_t phoneid;
char connected = 0;
keybuffer_t keybuffer;
ipcarg_t retval, arg1, arg2;
//open("null",0);
//open("stdout",0);
/* Initialize arch dependent parts */
if (!(res = kbd_arch_init())) {
return -1;
67,57 → 121,10
if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead)) != 0) {
return -1;
};
while (1) {
callid = ipc_wait_for_call(&call);
switch (IPC_GET_METHOD(call)) {
case IPC_M_PHONE_HUNGUP:
connected = 0;
retval = 0;
break;
case IPC_M_CONNECT_ME_TO:
/* Only one connected client allowed */
if (connected) {
retval = ELIMIT;
} else {
retval = 0;
connected = 1;
}
break;
case IPC_M_CONNECT_TO_ME:
phoneid = IPC_GET_ARG3(call);
retval = 0;
break;
}
 
case IPC_M_INTERRUPT:
if (connected) {
int chr;
/* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */
kbd_arch_process(&keybuffer, IPC_GET_ARG2(call));
async_set_client_connection(console_connection);
async_set_interrupt_received(irq_handler);
async_manager();
 
retval = 0;
 
while (!keybuffer_empty(&keybuffer)) {
if (!keybuffer_pop(&keybuffer, (int *)&chr)) {
break;
}
{
arg1=chr;
send_call(phoneid, KBD_PUSHCHAR, arg1);
}
}
 
}
break;
default:
retval = ENOENT;
break;
}
 
if (! (callid & IPC_CALLID_NOTIFICATION)) {
ipc_answer_fast(callid, retval, arg1, arg2);
}
}
}
 
/uspace/trunk/console/console.c
25,6 → 25,8
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* TODO: remove */
#include <stdio.h>
 
 
#include <kbd.h>
91,33 → 93,33
 
static void clrscr(void)
{
nsend_call(fb_info.phone, FB_CLEAR, 0);
async_msg(fb_info.phone, FB_CLEAR, 0);
}
 
static void curs_visibility(int v)
{
send_call(fb_info.phone, FB_CURSOR_VISIBILITY, v);
async_msg(fb_info.phone, FB_CURSOR_VISIBILITY, v);
}
 
static void curs_goto(int row, int col)
{
nsend_call_2(fb_info.phone, FB_CURSOR_GOTO, row, col);
async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col);
}
 
static void set_style(style_t *style)
{
nsend_call_2(fb_info.phone, FB_SET_STYLE, style->fg_color, style->bg_color);
async_msg_2(fb_info.phone, FB_SET_STYLE, style->fg_color, style->bg_color);
}
 
static void set_style_col(int fgcolor, int bgcolor)
{
nsend_call_2(fb_info.phone, FB_SET_STYLE, fgcolor, bgcolor);
async_msg_2(fb_info.phone, FB_SET_STYLE, fgcolor, bgcolor);
}
 
static void prtchr(char c, int row, int col)
{
nsend_call_3(fb_info.phone, FB_PUTCHAR, c, row, col);
async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col);
}
 
165,7 → 167,7
scr->position_y = scr->size_y - 1;
screenbuffer_clear_line(scr, scr->top_line++);
if (console == active_console)
nsend_call(fb_info.phone, FB_SCROLL, 1);
async_msg(fb_info.phone, FB_SCROLL, 1);
}
scr->position_x = scr->position_x % scr->size_x;
185,15 → 187,15
int newpmap;
/* Save screen */
newpmap = sync_send(fb_info.phone, FB_VP2PIXMAP, 0, NULL);
newpmap = async_req(fb_info.phone, FB_VP2PIXMAP, 0, NULL);
if (newpmap < 0)
return -1;
 
if (oldpixmap != -1) {
/* Show old screen */
nsend_call_2(fb_info.phone, FB_VP_DRAW_PIXMAP, 0, oldpixmap);
async_msg_2(fb_info.phone, FB_VP_DRAW_PIXMAP, 0, oldpixmap);
/* Drop old pixmap */
nsend_call(fb_info.phone, FB_DROP_PIXMAP, oldpixmap);
async_msg(fb_info.phone, FB_DROP_PIXMAP, oldpixmap);
}
return newpmap;
236,7 → 238,6
kernel_pixmap = switch_screens(console_pixmap);
console_pixmap = -1;
}
active_console = newcons;
gcons_change_console(newcons);
conn = &connections[active_console];
244,13 → 245,12
set_style(&conn->screenbuffer.style);
curs_goto(conn->screenbuffer.position_y, conn->screenbuffer.position_x);
curs_visibility(0);
if (interbuffer) {
for (i = 0; i < conn->screenbuffer.size_x; i++)
for (j = 0; j < conn->screenbuffer.size_y; j++)
interbuffer[i + j*conn->screenbuffer.size_x] = *get_field_at(&(conn->screenbuffer),i, j);
/* This call can preempt, but we are already at the end */
j = sync_send_2(fb_info.phone, FB_DRAW_TEXT_DATA, 0, 0, NULL, NULL);
j = async_req_2(fb_info.phone, FB_DRAW_TEXT_DATA, 0, 0, NULL, NULL);
};
if ((!interbuffer) || (j != 0)){
301,10 → 301,12
conn = &connections[active_console];
// if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + CONSOLE_COUNT)) {
if ((c >= 0x101) && (c < 0x101 + CONSOLE_COUNT)) {
async_serialize_start();
if (c == 0x112)
change_console(KERNEL_CONSOLE);
else
change_console(c - 0x101);
async_serialize_end();
break;
}
321,7 → 323,7
break;
default:
retval = ENOENT;
}
}
ipc_answer_fast(callid, retval, 0, 0);
}
}
340,21 → 342,26
return;
}
conn = &connections[consnum];
conn->used = 1;
async_serialize_start();
gcons_notify_connect(consnum);
conn->used = 1;
conn->client_phone = IPC_GET_ARG3(call);
screenbuffer_clear(&conn->screenbuffer);
/* Accept the connection */
ipc_answer_fast(iid,0,0,0);
 
while (1) {
async_serialize_end();
callid = async_get_call(&call);
async_serialize_start();
 
arg1 = arg2 = 0;
switch (IPC_GET_METHOD(call)) {
case IPC_M_PHONE_HUNGUP:
gcons_notify_disconnect(consnum);
/* Answer all pending requests */
while (conn->keyrequest_counter > 0) {
conn->keyrequest_counter--;
364,6 → 371,7
/* Commit hangup */
ipc_answer_fast(callid, 0,0,0);
async_serialize_end();
return;
case CONSOLE_PUTCHAR:
write_char(consnum, IPC_GET_ARG1(call));
372,7 → 380,7
case CONSOLE_CLEAR:
/* Send message to fb */
if (consnum == active_console) {
send_call(fb_info.phone, FB_CLEAR, 0);
async_msg(fb_info.phone, FB_CLEAR, 0);
}
screenbuffer_clear(&conn->screenbuffer);
391,7 → 399,7
arg2 = fb_info.cols;
break;
case CONSOLE_FLUSH:
sync_send_2(fb_info.phone, FB_FLUSH, 0, 0, NULL, NULL);
async_req_2(fb_info.phone, FB_FLUSH, 0, 0, NULL, NULL);
break;
case CONSOLE_SET_STYLE:
459,7 → 467,7
/* Initialize gcons */
gcons_init(fb_info.phone);
/* Synchronize, the gcons can have something in queue */
sync_send(fb_info.phone, FB_FLUSH, 0, NULL);
async_req(fb_info.phone, FB_FLUSH, 0, NULL);
 
ipc_call_sync_2(fb_info.phone, FB_GET_CSIZE, 0, 0, &(fb_info.rows), &(fb_info.cols));
/uspace/trunk/console/gcons.c
75,7 → 75,7
 
static void vp_switch(int vp)
{
nsend_call(fbphone,FB_VIEWPORT_SWITCH, vp);
async_msg(fbphone,FB_VIEWPORT_SWITCH, vp);
}
 
/** Create view port */
90,19 → 90,19
 
static void clear(void)
{
nsend_call(fbphone, FB_CLEAR, 0);
async_msg(fbphone, FB_CLEAR, 0);
}
 
static void set_style(int fgcolor, int bgcolor)
{
nsend_call_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor);
async_msg_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor);
}
 
/** Transparent putchar */
static void tran_putch(char c, int row, int col)
{
nsend_call_3(fbphone, FB_TRANS_PUTCHAR, c, row, col);
async_msg_3(fbphone, FB_TRANS_PUTCHAR, c, row, col);
}
 
/** Redraw the button showing state of a given console */
114,7 → 114,7
 
vp_switch(cstatus_vp[consnum]);
if (ic_pixmaps[state] != -1)
nsend_call_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum], ic_pixmaps[state]);
async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum], ic_pixmaps[state]);
 
if (state != CONS_DISCONNECTED && state != CONS_KERNEL && state != CONS_DISCONNECTED_SEL) {
snprintf(data, 5, "%d", consnum+1);
238,17 → 238,17
 
memcpy(shm, logo, size);
/* Send area */
rc = sync_send_2(fbphone, FB_PREPARE_SHM, (ipcarg_t)shm, 0, NULL, NULL);
rc = async_req_2(fbphone, FB_PREPARE_SHM, (ipcarg_t)shm, 0, NULL, NULL);
if (rc)
goto exit;
rc = sync_send_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t)shm, 0, PROTO_READ, NULL, NULL, NULL);
rc = async_req_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t)shm, 0, PROTO_READ, NULL, NULL, NULL);
if (rc)
goto drop;
/* Draw logo */
nsend_call_2(fbphone, FB_DRAW_PPM, x, y);
async_msg_2(fbphone, FB_DRAW_PPM, x, y);
drop:
/* Drop area */
nsend_call(fbphone, FB_DROP_SHM, 0);
async_msg(fbphone, FB_DROP_SHM, 0);
exit:
/* Remove area */
munmap(shm, size);
297,21 → 297,21
 
memcpy(shm, data, size);
/* Send area */
rc = sync_send_2(fbphone, FB_PREPARE_SHM, (ipcarg_t)shm, 0, NULL, NULL);
rc = async_req_2(fbphone, FB_PREPARE_SHM, (ipcarg_t)shm, 0, NULL, NULL);
if (rc)
goto exit;
rc = sync_send_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t)shm, 0, PROTO_READ, NULL, NULL, NULL);
rc = async_req_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t)shm, 0, PROTO_READ, NULL, NULL, NULL);
if (rc)
goto drop;
 
/* Obtain pixmap */
rc = sync_send(fbphone, FB_SHM2PIXMAP, 0, NULL);
rc = async_req(fbphone, FB_SHM2PIXMAP, 0, NULL);
if (rc < 0)
goto drop;
pxid = rc;
drop:
/* Drop area */
nsend_call(fbphone, FB_DROP_SHM, 0);
async_msg(fbphone, FB_DROP_SHM, 0);
exit:
/* Remove area */
munmap(shm, size);
/uspace/trunk/libc/include/psthread.h
40,10 → 40,13
(c)->tls = (sysarg_t) (ptls);
#endif /* context_set */
 
#define PSTHREAD_SERIALIZED 1
 
typedef enum {
PS_TO_MANAGER,
PS_FROM_MANAGER,
PS_PREEMPT
PS_PREEMPT,
PS_FROM_DEAD
} pschange_type;
 
typedef sysarg_t pstid_t;
75,6 → 78,8
void psthread_add_manager(pstid_t psthrid);
void psthread_remove_manager(void);
pstid_t psthread_get_id(void);
void psthread_inc_sercount(void);
void psthread_dec_sercount(void);
 
static inline int psthread_schedule_next() {
return psthread_schedule_next_adv(PS_PREEMPT);
/uspace/trunk/libc/include/async.h
37,7 → 37,11
typedef ipc_callid_t aid_t;
typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call);
 
int async_manager(void);
static inline void async_manager(void)
{
psthread_schedule_next_adv(PS_TO_MANAGER);
}
 
ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs);
static inline ipc_callid_t async_get_call(ipc_call_t *data)
{
57,7 → 61,7
*
* @return Return code of message
*/
static inline ipcarg_t sync_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t *r1, ipcarg_t *r2)
static inline ipcarg_t async_req_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t *r1, ipcarg_t *r2)
{
ipc_call_t result;
ipcarg_t rc;
70,9 → 74,9
*r2 = IPC_GET_ARG2(result);
return rc;
}
#define sync_send(phoneid, method, arg1, r1) sync_send_2(phoneid, method, arg1, 0, r1, 0)
#define async_req(phoneid, method, arg1, r1) async_req_2(phoneid, method, arg1, 0, r1, 0)
 
static inline ipcarg_t sync_send_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
static inline ipcarg_t async_req_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *r1,
ipcarg_t *r2, ipcarg_t *r3)
{
102,6 → 106,20
int _async_init(void);
 
 
/* Primitve functions for IPC communication */
void async_msg_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
ipcarg_t arg3);
void async_msg_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2);
#define async_msg(ph,m,a1) async_msg_2(ph,m,a1,0)
 
static inline void async_serialize_start(void)
{
psthread_inc_sercount();
}
static inline void async_serialize_end(void)
{
psthread_dec_sercount();
}
 
extern atomic_t async_futex;
 
#endif
/uspace/trunk/libc/include/ipc/ipc.h
81,16 → 81,4
extern int ipc_unregister_irq(int irq);
extern int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1);
 
 
/* Primitve functions for IPC communication */
void send_call_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
ipcarg_t arg3);
void send_call_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2);
#define send_call(ph,m,a1) send_call_2(ph,m,a1,0)
/* These functions never preempt */
void nsend_call_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
ipcarg_t arg2, ipcarg_t arg3);
void nsend_call_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2);
#define nsend_call(ph,m,a1) nsend_call_2(ph,m,a1,0)
 
#endif
/uspace/trunk/libc/generic/psthread.c
42,6 → 42,7
#endif
 
static LIST_INITIALIZE(ready_list);
static LIST_INITIALIZE(serialized_list);
static LIST_INITIALIZE(manager_list);
 
static void psthread_exit(void) __attribute__ ((noinline));
48,6 → 49,12
static void psthread_main(void);
 
static atomic_t psthread_futex = FUTEX_INITIALIZER;
/** Count of real threads that are in async_serialized mode */
static int serialized_threads; /* Protected by async_futex */
/** Thread-local count of serialization. If >0, we must not preempt */
static __thread serialization_count;
/** Counter of threads residing in async_manager */
static int threads_in_manager;
 
/** Setup PSthread information into TCB structure */
psthread_data_t * psthread_setup()
77,35 → 84,12
free(pt);
}
 
/** Function to preempt to other pseudo thread without adding
* currently running pseudo thread to ready_list.
*/
void psthread_exit(void)
{
psthread_data_t *pt;
 
futex_down(&psthread_futex);
 
if (!list_empty(&ready_list))
pt = list_get_instance(ready_list.next, psthread_data_t, link);
else if (!list_empty(&manager_list))
pt = list_get_instance(manager_list.next, psthread_data_t, link);
else {
printf("Cannot find suitable psthread to run.\n");
_exit(0);
}
list_remove(&pt->link);
futex_up(&psthread_futex);
 
context_restore(&pt->ctx);
/* Never reached */
}
 
/** Function that is called on entry to new uspace thread */
void psthread_main(void)
{
psthread_data_t *pt = __tcb_get()->pst_data;
 
serialization_count = 0; // TODO: WHY HERE?
pt->retval = pt->func(pt->arg);
 
pt->finished = 1;
112,7 → 96,7
if (pt->waiter)
list_append(&pt->waiter->link, &ready_list);
 
psthread_exit();
psthread_schedule_next_adv(PS_FROM_DEAD);
}
 
/** Schedule next userspace pseudo thread.
127,7 → 111,7
*/
int psthread_schedule_next_adv(pschange_type ctype)
{
psthread_data_t *pt;
psthread_data_t *srcpt, *dstpt;
int retval = 0;
futex_down(&psthread_futex);
135,33 → 119,61
if (ctype == PS_PREEMPT && list_empty(&ready_list))
goto ret_0;
 
if (ctype == PS_FROM_MANAGER && list_empty(&ready_list)) {
goto ret_0;
if (ctype == PS_FROM_MANAGER) {
if (list_empty(&ready_list) && list_empty(&serialized_list))
goto ret_0;
/* Do not preempt if there is not sufficient count of thread managers */
if (list_empty(&serialized_list) && threads_in_manager <= serialized_threads) {
goto ret_0;
}
}
/* If we are going to manager and none exists, create it */
while (ctype == PS_TO_MANAGER && list_empty(&manager_list)) {
futex_up(&psthread_futex);
async_create_manager();
futex_down(&psthread_futex);
if (ctype == PS_TO_MANAGER || ctype == PS_FROM_DEAD) {
while (list_empty(&manager_list)) {
futex_up(&psthread_futex);
async_create_manager();
futex_down(&psthread_futex);
}
}
if (ctype != PS_FROM_DEAD) {
/* Save current state */
srcpt = __tcb_get()->pst_data;
if (!context_save(&srcpt->ctx)) {
if (serialization_count)
srcpt->flags &= ~PSTHREAD_SERIALIZED;
return 1; // futex_up already done here
}
 
pt = __tcb_get()->pst_data;
if (!context_save(&pt->ctx))
return 1; // futex_up already done here
/* Save myself to correct run list */
if (ctype == PS_PREEMPT)
list_append(&srcpt->link, &ready_list);
else if (ctype == PS_FROM_MANAGER) {
list_append(&srcpt->link, &manager_list);
threads_in_manager--;
} /* If ctype == PS_TO_MANAGER, don't save ourselves to any list, we should
* already be somewhere, or we will be lost */
}
 
if (ctype == PS_PREEMPT)
list_append(&pt->link, &ready_list);
else if (ctype == PS_FROM_MANAGER)
list_append(&pt->link, &manager_list);
if (ctype == PS_TO_MANAGER)
pt = list_get_instance(manager_list.next,psthread_data_t, link);
else
pt = list_get_instance(ready_list.next, psthread_data_t, link);
list_remove(&pt->link);
/* Choose new thread to run */
if (ctype == PS_TO_MANAGER || ctype == PS_FROM_DEAD) {
dstpt = list_get_instance(manager_list.next,psthread_data_t, link);
if (serialization_count && ctype == PS_TO_MANAGER) {
serialized_threads++;
srcpt->flags |= PSTHREAD_SERIALIZED;
}
threads_in_manager++;
} else {
if (!list_empty(&serialized_list)) {
dstpt = list_get_instance(serialized_list.next, psthread_data_t, link);
serialized_threads--;
} else
dstpt = list_get_instance(ready_list.next, psthread_data_t, link);
}
list_remove(&dstpt->link);
 
futex_up(&psthread_futex);
context_restore(&pt->ctx);
context_restore(&dstpt->ctx);
 
ret_0:
futex_up(&psthread_futex);
182,13 → 194,10
/* Handle psthrid = Kernel address -> it is wait for call */
pt = (psthread_data_t *) psthrid;
 
if (!pt->finished) {
mypt = __tcb_get()->pst_data;
if (context_save(&((psthread_data_t *) mypt)->ctx)) {
pt->waiter = (psthread_data_t *) mypt;
psthread_exit();
}
}
/* TODO */
printf("join unsupported\n");
_exit(1);
 
retval = pt->retval;
 
free(pt->stack);
223,6 → 232,7
pt->func = func;
pt->finished = 0;
pt->waiter = NULL;
pt->flags = 0;
 
context_save(&pt->ctx);
context_set(&pt->ctx, FADDR(psthread_main), pt->stack, PSTHREAD_INITIAL_STACK_PAGES_NO*getpagesize(),
238,7 → 248,10
 
pt = (psthread_data_t *) psthrid;
futex_down(&psthread_futex);
list_append(&pt->link, &ready_list);
if ((pt->flags & PSTHREAD_SERIALIZED))
list_append(&pt->link, &serialized_list);
else
list_append(&pt->link, &ready_list);
futex_up(&psthread_futex);
}
 
271,3 → 284,21
{
return (pstid_t)__tcb_get()->pst_data;
}
 
/** Disable preemption
*
* If the thread wants to send several message in row and does not want
* to be preempted, it should start async_serialize_start() in the beginning
* of communication and async_serialize_end() in the end. If it is a
* true multithreaded application, it should protect the communication channel
* by a futex as well. Interrupt messages will can still be preempted.
*/
void psthread_inc_sercount(void)
{
serialization_count++;
}
 
void psthread_dec_sercount(void)
{
serialization_count--;
}
/uspace/trunk/libc/generic/ipc.c
437,26 → 437,3
return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1);
}
 
/* Primitive functions for simple communication */
void send_call_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, 1);
}
 
void send_call_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2)
{
ipc_call_async_2(phoneid, method, arg1, arg2, NULL, NULL, 1);
}
 
void nsend_call_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, 0);
}
 
void nsend_call_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2)
{
ipc_call_async_2(phoneid, method, arg1, arg2, NULL, NULL, 0);
}
 
/uspace/trunk/libc/generic/async.c
134,8 → 134,11
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);
225,6 → 228,7
awaiter_t *cur;
 
wd->timedout = 0;
wd->inlist = 1;
 
tmp = timeout_list.next;
while (tmp != &timeout_list) {
294,9 → 298,6
*/
conn = PS_connection;
 
if (usecs < 0) /* TODO: let it get through the ipc_call once */
return 0;
 
futex_down(&async_futex);
 
if (usecs) {
307,10 → 308,9
}
/* If nothing in queue, wait until something appears */
while (list_empty(&conn->msg_queue)) {
if (usecs) {
conn->wdata.inlist = 1;
if (usecs)
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,7 → 362,6
/* 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;
435,7 → 434,9
/* 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. */
485,7 → 486,7
}
 
/** Endless loop dispatching incoming calls and answers */
int async_manager(void)
static int async_manager_worker(void)
{
ipc_call_t call;
ipc_callid_t callid;
521,8 → 522,9
continue;
}
 
if (callid & IPC_CALLID_ANSWERED)
if (callid & IPC_CALLID_ANSWERED) {
continue;
}
 
handle_call(callid, &call);
}
537,9 → 539,10
*/
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();
async_manager_worker();
}
 
/** Add one manager to manager list */
607,6 → 610,11
{
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;
628,6 → 636,11
{
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;
698,8 → 711,6
 
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 */
725,12 → 736,16
{
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);
756,3 → 771,15
{
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);
}
/uspace/trunk/libc/generic/io/stream.c
64,7 → 64,7
size_t i = 0;
 
while (i < count) {
if (sync_send_2(streams[0].phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1) < 0) {
if (async_req_2(streams[0].phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1) < 0) {
return -1;
}
((char *)buf)[i++] = r0;
78,7 → 78,7
ipcarg_t r0,r1;
 
for (i = 0; i < count; i++)
send_call(streams[1].phone, CONSOLE_PUTCHAR, ((const char *)buf)[i]);
async_msg(streams[1].phone, CONSOLE_PUTCHAR, ((const char *)buf)[i]);
return count;
}
130,7 → 130,7
fd_t open(const char *fname, int flags)
{
int c = 0;
 
while (((streams[c].w) || (streams[c].r)) && (c < FDS))
c++;
if (c == FDS)
159,6 → 159,8
 
ssize_t write(int fd, const void *buf, size_t count)
{
// __SYSCALL3(SYS_IO, 1, (sysarg_t)buf, (sysarg_t) count);
// return count;
if (fd < FDS)
return streams[fd].w(streams[fd].param, buf, count);
/uspace/trunk/tetris/screen.c
80,7 → 80,7
 
static void set_style(int fgcolor, int bgcolor)
{
send_call_2(con_phone, CONSOLE_SET_STYLE, fgcolor, bgcolor);
async_msg_2(con_phone, CONSOLE_SET_STYLE, fgcolor, bgcolor);
}
 
static void start_standout(void)
96,7 → 96,7
 
void clear_screen(void)
{
send_call(con_phone, CONSOLE_CLEAR, 0);
async_msg(con_phone, CONSOLE_CLEAR, 0);
moveto(0,0);
}
 
108,7 → 108,7
{
 
resume_normal();
send_call(con_phone, CONSOLE_CLEAR, 0);
async_msg(con_phone, CONSOLE_CLEAR, 0);
curscore = -1;
memset((char *)curscreen, 0, sizeof(curscreen));
}
120,7 → 120,7
scr_init(void)
{
con_phone = get_fd_phone(1);
send_call(con_phone, CONSOLE_CURSOR_VISIBILITY, 0);
async_msg(con_phone, CONSOLE_CURSOR_VISIBILITY, 0);
resume_normal();
scr_clear();
}
127,12 → 127,12
 
void moveto(int r, int c)
{
send_call_2(con_phone, CONSOLE_GOTO, r, c);
async_msg_2(con_phone, CONSOLE_GOTO, r, c);
}
 
static void fflush(void)
{
send_call(con_phone, CONSOLE_FLUSH, 0);
async_msg(con_phone, CONSOLE_FLUSH, 0);
}
 
winsize_t winsize;
139,7 → 139,7
 
static int get_display_size(winsize_t *ws)
{
return sync_send_2(con_phone, CONSOLE_GETSIZE, 0, 0, &ws->ws_row, &ws->ws_col);
return async_req_2(con_phone, CONSOLE_GETSIZE, 0, 0, &ws->ws_row, &ws->ws_col);
}
 
static void