async.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Ondrej Palkovsky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef _libc_ASYNC_H_
00036 #define _libc_ASYNC_H_
00037 
00038 #include <ipc/ipc.h>
00039 #include <psthread.h>
00040 #include <sys/time.h>
00041 #include <atomic.h>
00042 
00043 typedef ipc_callid_t aid_t;
00044 typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call);
00045 
00046 static inline void async_manager(void)
00047 {
00048         psthread_schedule_next_adv(PS_TO_MANAGER);
00049 }
00050 
00051 ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs);
00052 static inline ipc_callid_t async_get_call(ipc_call_t *data)
00053 {
00054         return async_get_call_timeout(data, 0);
00055 }
00056 
00057 aid_t async_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
00058                    ipc_call_t *dataptr);
00059 aid_t async_send_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
00060                    ipcarg_t arg3, ipc_call_t *dataptr);
00061 void async_wait_for(aid_t amsgid, ipcarg_t *result);
00062 int async_wait_timeout(aid_t amsgid, ipcarg_t *retval, suseconds_t timeout);
00063 
00070 static inline ipcarg_t async_req_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t *r1, ipcarg_t *r2)
00071 {
00072         ipc_call_t result;
00073         ipcarg_t rc;
00074 
00075         aid_t eid = async_send_2(phoneid, method, arg1, arg2, &result);
00076         async_wait_for(eid, &rc);
00077         if (r1) 
00078                 *r1 = IPC_GET_ARG1(result);
00079         if (r2)
00080                 *r2 = IPC_GET_ARG2(result);
00081         return rc;
00082 }
00083 #define async_req(phoneid, method, arg1, r1) async_req_2(phoneid, method, arg1, 0, r1, 0)
00084 
00085 static inline ipcarg_t async_req_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
00086                                    ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *r1, 
00087                                    ipcarg_t *r2, ipcarg_t *r3)
00088 {
00089         ipc_call_t result;
00090         ipcarg_t rc;
00091 
00092         aid_t eid = async_send_3(phoneid, method, arg1, arg2, arg3, &result);
00093         async_wait_for(eid, &rc);
00094         if (r1) 
00095                 *r1 = IPC_GET_ARG1(result);
00096         if (r2)
00097                 *r2 = IPC_GET_ARG2(result);
00098         if (r3)
00099                 *r3 = IPC_GET_ARG3(result);
00100         return rc;
00101 }
00102 
00103 
00104 pstid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid, 
00105                              ipc_call_t *call,
00106                              void (*cthread)(ipc_callid_t,ipc_call_t *));
00107 void async_usleep(suseconds_t timeout);
00108 void async_create_manager(void);
00109 void async_destroy_manager(void);
00110 void async_set_client_connection(async_client_conn_t conn);
00111 void async_set_interrupt_received(async_client_conn_t conn);
00112 int _async_init(void);
00113 
00114 
00115 /* Primitve functions for IPC communication */
00116 void async_msg_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, 
00117                  ipcarg_t arg3);
00118 void async_msg_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2);
00119 #define async_msg(ph,m,a1) async_msg_2(ph,m,a1,0)
00120 
00121 static inline void async_serialize_start(void)
00122 {
00123         psthread_inc_sercount();
00124 }
00125 static inline void async_serialize_end(void)
00126 {
00127         psthread_dec_sercount();
00128 }
00129 
00130 extern atomic_t async_futex;
00131 #endif
00132 
00133 

Generated on Sun Jun 18 18:00:18 2006 for HelenOS Userspace (ia64) by  doxygen 1.4.6