Changeset 6610565b in mainline for uspace/lib/c/generic
- Timestamp:
- 2011-01-10T16:20:56Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1ffa73b, 8048c648, 8426912a, 977fcea, f401312
- Parents:
- a97ea0f (diff), 4a5c6c1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/lib/c/generic
- Files:
-
- 10 edited
- 1 moved
-
adt/char_map.c (modified) (6 diffs)
-
adt/measured_strings.c (modified) (6 diffs)
-
async_sess.c (modified) (8 diffs)
-
device/char_dev.c (moved) (moved from uspace/lib/c/generic/device/char.c ) (5 diffs)
-
device/hw_res.c (modified) (4 diffs)
-
devman.c (modified) (3 diffs)
-
fibril.c (modified) (1 diff)
-
fibril_synch.c (modified) (3 diffs)
-
io/vprintf.c (modified) (2 diffs)
-
mem.c (modified) (1 diff)
-
net/modules.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/char_map.c
ra97ea0f r6610565b 65 65 */ 66 66 static int 67 char_map_add_item(char_map_t *map, const char*identifier, size_t length,67 char_map_add_item(char_map_t *map, const uint8_t *identifier, size_t length, 68 68 const int value) 69 69 { … … 139 139 */ 140 140 int 141 char_map_add(char_map_t *map, const char*identifier, size_t length,141 char_map_add(char_map_t *map, const uint8_t *identifier, size_t length, 142 142 const int value) 143 143 { … … 200 200 */ 201 201 static char_map_t * 202 char_map_find_node(const char_map_t *map, const char*identifier,202 char_map_find_node(const char_map_t *map, const uint8_t *identifier, 203 203 size_t length) 204 204 { … … 241 241 * @return CHAR_MAP_NULL if the key is not assigned a value. 242 242 */ 243 int char_map_exclude(char_map_t *map, const char*identifier, size_t length)243 int char_map_exclude(char_map_t *map, const uint8_t *identifier, size_t length) 244 244 { 245 245 char_map_t *node; … … 269 269 * @return CHAR_MAP_NULL if the key is not assigned a value. 270 270 */ 271 int char_map_find(const char_map_t *map, const char*identifier, size_t length)271 int char_map_find(const char_map_t *map, const uint8_t *identifier, size_t length) 272 272 { 273 273 char_map_t *node; … … 329 329 */ 330 330 int 331 char_map_update(char_map_t *map, const char*identifier, const size_t length,331 char_map_update(char_map_t *map, const uint8_t *identifier, const size_t length, 332 332 const int value) 333 333 { -
uspace/lib/c/generic/adt/measured_strings.c
ra97ea0f r6610565b 59 59 */ 60 60 measured_string_t * 61 measured_string_create_bulk(const char*string, size_t length)61 measured_string_create_bulk(const uint8_t *string, size_t length) 62 62 { 63 63 measured_string_t *new; … … 68 68 } 69 69 new = (measured_string_t *) malloc(sizeof(measured_string_t) + 70 (sizeof( char) * (length + 1)));70 (sizeof(uint8_t) * (length + 1))); 71 71 if (!new) 72 72 return NULL; 73 73 74 74 new->length = length; 75 new->value = (( char*) new) + sizeof(measured_string_t);75 new->value = ((uint8_t *) new) + sizeof(measured_string_t); 76 76 // append terminating zero explicitly - to be safe 77 77 memcpy(new->value, string, new->length); … … 97 97 new = (measured_string_t *) malloc(sizeof(measured_string_t)); 98 98 if (new) { 99 new->value = ( char*) malloc(source->length + 1);99 new->value = (uint8_t *) malloc(source->length + 1); 100 100 if (new->value) { 101 101 new->length = source->length; … … 131 131 */ 132 132 int 133 measured_strings_receive(measured_string_t **strings, char**data,133 measured_strings_receive(measured_string_t **strings, uint8_t **data, 134 134 size_t count) 135 135 { … … 137 137 size_t index; 138 138 size_t length; 139 char*next;139 uint8_t *next; 140 140 ipc_callid_t callid; 141 141 int rc; … … 311 311 */ 312 312 int 313 measured_strings_return(int phone, measured_string_t **strings, char**data,313 measured_strings_return(int phone, measured_string_t **strings, uint8_t **data, 314 314 size_t count) 315 315 { 316 316 size_t *lengths; 317 317 size_t index; 318 char*next;318 uint8_t *next; 319 319 int rc; 320 320 -
uspace/lib/c/generic/async_sess.c
ra97ea0f r6610565b 110 110 typedef struct { 111 111 link_t sess_link; /**< Link for the session list of inactive connections. */ 112 link_t global_link; /**< Link for the global list of inactive connecti nos. */112 link_t global_link; /**< Link for the global list of inactive connections. */ 113 113 int data_phone; /**< Connected data phone. */ 114 114 } conn_node_t; 115 115 116 116 /** 117 * Mutex protecting the inactive_conn_head list and the session list. 117 * Mutex protecting the inactive_conn_head list, the session list and the 118 * avail_phone condition variable. 118 119 */ 119 120 static fibril_mutex_t async_sess_mutex; … … 128 129 */ 129 130 static LIST_INITIALIZE(session_list_head); 131 132 /** 133 * Condition variable used to wait for a phone to become available. 134 */ 135 static FIBRIL_CONDVAR_INITIALIZE(avail_phone_cv); 130 136 131 137 /** Initialize the async_sess subsystem. … … 150 156 * @param sess Session structure provided by caller, will be filled in. 151 157 * @param phone Phone connected to the desired server task. 152 */ 153 void async_session_create(async_sess_t *sess, int phone) 158 * @param arg1 Value to pass as first argument upon creating a new 159 * connection. Typical use is to identify a resource within 160 * the server that the caller wants to access (port ID, 161 * interface ID, device ID, etc.). 162 */ 163 void async_session_create(async_sess_t *sess, int phone, sysarg_t arg1) 154 164 { 155 165 sess->sess_phone = phone; 166 sess->connect_arg1 = arg1; 156 167 list_initialize(&sess->conn_head); 157 168 … … 192 203 free(conn); 193 204 } 205 206 fibril_condvar_broadcast(&avail_phone_cv); 194 207 } 195 208 … … 231 244 */ 232 245 retry: 233 data_phone = async_connect_me_to(sess->sess_phone, 0, 0, 0); 246 data_phone = async_connect_me_to(sess->sess_phone, 247 sess->connect_arg1, 0, 0); 234 248 if (data_phone >= 0) { 235 249 /* success, do nothing */ … … 250 264 } else { 251 265 /* 252 * This is unfortunate. We failed both to find a cached 253 * connection or to create a new one even after cleaning up 254 * the cache. This is most likely due to too many 255 * open sessions (connected session phones). 266 * Wait for a phone to become available. 256 267 */ 257 data_phone = ELIMIT; 268 fibril_condvar_wait(&avail_phone_cv, &async_sess_mutex); 269 goto retry; 258 270 } 259 271 } … … 273 285 274 286 fibril_mutex_lock(&async_sess_mutex); 287 fibril_condvar_signal(&avail_phone_cv); 275 288 conn = (conn_node_t *) malloc(sizeof(conn_node_t)); 276 289 if (!conn) { … … 279 292 * means that we simply hang up. 280 293 */ 294 ipc_hangup(data_phone); 281 295 fibril_mutex_unlock(&async_sess_mutex); 282 ipc_hangup(data_phone);283 296 return; 284 297 } -
uspace/lib/c/generic/device/char_dev.c
ra97ea0f r6610565b 34 34 35 35 #include <ipc/dev_iface.h> 36 #include <device/char .h>36 #include <device/char_dev.h> 37 37 #include <errno.h> 38 38 #include <async.h> … … 45 45 * using its character interface. 46 46 * 47 * @param dev_phone Phone to the device. 48 * @param buf Buffer for the data read 49 * from or written to the device. 50 * @param len Maximum length of the data to be 51 * read or written. 52 * @param read Read from the device if true, 53 * write to it otherwise. 47 * @param dev_phone Phone to the device. 48 * @param buf Buffer for the data read from or written to the device. 49 * @param size Maximum size of data (in bytes) to be read or written. 50 * @param read Read from the device if true, write to it otherwise. 54 51 * 55 * @return Non-negative number of bytes actually read 56 * from or written to the device on success, 57 * negative error number otherwise. 58 * 52 * @return Non-negative number of bytes actually read from or 53 * written to the device on success, negative error number 54 * otherwise. 59 55 */ 60 static ssize_t rw_dev(int dev_phone, void *buf, size_t len, bool read)56 static ssize_t char_dev_rw(int dev_phone, void *buf, size_t size, bool read) 61 57 { 62 58 async_serialize_start(); … … 68 64 if (read) { 69 65 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), 70 CHAR_ READ_DEV, &answer);71 ret = async_data_read_start(dev_phone, buf, len);66 CHAR_DEV_READ, &answer); 67 ret = async_data_read_start(dev_phone, buf, size); 72 68 } else { 73 69 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), 74 CHAR_ WRITE_DEV, &answer);75 ret = async_data_write_start(dev_phone, buf, len);70 CHAR_DEV_WRITE, &answer); 71 ret = async_data_write_start(dev_phone, buf, size); 76 72 } 77 73 … … 82 78 if (rc == EOK) 83 79 return (ssize_t) ret; 84 80 85 81 return (ssize_t) rc; 86 82 } … … 96 92 } 97 93 98 /** Read from device using its character interface.94 /** Read from character device. 99 95 * 100 * @param dev_phone Phone to the device. 101 * @param buf Output buffer for the data 102 * read from the device. 103 * @param len Maximum length of the data to be read. 96 * @param dev_phone Phone to the device. 97 * @param buf Output buffer for the data read from the device. 98 * @param size Maximum size (in bytes) of the data to be read. 104 99 * 105 * @return Non-negative number of bytes actually read 106 * from the device on success, negative error 107 * number otherwise. 108 * 100 * @return Non-negative number of bytes actually read from the 101 * device on success, negative error number otherwise. 109 102 */ 110 ssize_t read_dev(int dev_phone, void *buf, size_t len)103 ssize_t char_dev_read(int dev_phone, void *buf, size_t size) 111 104 { 112 return rw_dev(dev_phone, buf, len, true);105 return char_dev_rw(dev_phone, buf, size, true); 113 106 } 114 107 115 /** Write to device using its character interface.108 /** Write to character device. 116 109 * 117 * @param dev_phone Phone to the device.118 * @param buf Input buffer containg the data119 * to be written to thedevice.120 * @param len Maximum lengthof the data to be written.110 * @param dev_phone Phone to the device. 111 * @param buf Input buffer containg the data to be written to the 112 * device. 113 * @param size Maximum size (in bytes) of the data to be written. 121 114 * 122 * @return Non-negative number of bytes actually written 123 * to the device on success, negative error number 124 * otherwise. 125 * 115 * @return Non-negative number of bytes actually written to the 116 * device on success, negative error number otherwise. 126 117 */ 127 ssize_t write_dev(int dev_phone, void *buf, size_t len)118 ssize_t char_dev_write(int dev_phone, void *buf, size_t size) 128 119 { 129 return rw_dev(dev_phone, buf, len, false);120 return char_dev_rw(dev_phone, buf, size, false); 130 121 } 131 122 -
uspace/lib/c/generic/device/hw_res.c
ra97ea0f r6610565b 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 29 /** @addtogroup libc 30 30 * @{ … … 32 32 /** @file 33 33 */ 34 34 35 35 #include <device/hw_res.h> 36 36 #include <errno.h> … … 38 38 #include <malloc.h> 39 39 40 int get_hw_resources(int dev_phone, hw_resource_list_t *hw_resources)40 int hw_res_get_resource_list(int dev_phone, hw_resource_list_t *hw_resources) 41 41 { 42 42 sysarg_t count = 0; 43 int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE), GET_RESOURCE_LIST, &count); 43 44 int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE), 45 HW_RES_GET_RESOURCE_LIST, &count); 46 44 47 hw_resources->count = count; 45 48 if (rc != EOK) … … 57 60 return rc; 58 61 } 59 62 60 63 return EOK; 61 64 } 62 65 63 bool enable_interrupt(int dev_phone)66 bool hw_res_enable_interrupt(int dev_phone) 64 67 { 65 int rc = async_req_1_0(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE), ENABLE_INTERRUPT); 68 int rc = async_req_1_0(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE), 69 HW_RES_ENABLE_INTERRUPT); 70 66 71 return rc == EOK; 67 72 } 68 69 70 71 /** @} 73 74 /** @} 72 75 */ -
uspace/lib/c/generic/devman.c
ra97ea0f r6610565b 42 42 #include <devman.h> 43 43 #include <async.h> 44 #include <fibril_synch.h> 44 45 #include <errno.h> 45 46 #include <malloc.h> … … 50 51 static int devman_phone_client = -1; 51 52 53 static FIBRIL_MUTEX_INITIALIZE(devman_phone_mutex); 54 52 55 int devman_get_phone(devman_interface_t iface, unsigned int flags) 53 56 { 54 57 switch (iface) { 55 58 case DEVMAN_DRIVER: 56 if (devman_phone_driver >= 0) 59 fibril_mutex_lock(&devman_phone_mutex); 60 if (devman_phone_driver >= 0) { 61 fibril_mutex_unlock(&devman_phone_mutex); 57 62 return devman_phone_driver; 63 } 58 64 59 65 if (flags & IPC_FLAG_BLOCKING) 60 devman_phone_driver = ipc_connect_me_to_blocking(PHONE_NS, 66 devman_phone_driver = async_connect_me_to_blocking( 67 PHONE_NS, SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 68 else 69 devman_phone_driver = async_connect_me_to(PHONE_NS, 61 70 SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 62 else 63 devman_phone_driver = ipc_connect_me_to(PHONE_NS, 64 SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 65 71 72 fibril_mutex_unlock(&devman_phone_mutex); 66 73 return devman_phone_driver; 67 74 case DEVMAN_CLIENT: 68 if (devman_phone_client >= 0) 75 fibril_mutex_lock(&devman_phone_mutex); 76 if (devman_phone_client >= 0) { 77 fibril_mutex_unlock(&devman_phone_mutex); 69 78 return devman_phone_client; 79 } 70 80 71 81 if (flags & IPC_FLAG_BLOCKING) 72 devman_phone_client = ipc_connect_me_to_blocking(PHONE_NS, 82 devman_phone_client = async_connect_me_to_blocking( 83 PHONE_NS, SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 84 else 85 devman_phone_client = async_connect_me_to(PHONE_NS, 73 86 SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 74 else 75 devman_phone_client = ipc_connect_me_to(PHONE_NS, 76 SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 77 87 88 fibril_mutex_unlock(&devman_phone_mutex); 78 89 return devman_phone_client; 79 90 default: … … 245 256 246 257 if (flags & IPC_FLAG_BLOCKING) { 247 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,258 phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN, 248 259 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle); 249 260 } else { 250 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN,261 phone = async_connect_me_to(PHONE_NS, SERVICE_DEVMAN, 251 262 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle); 252 263 } -
uspace/lib/c/generic/fibril.c
ra97ea0f r6610565b 361 361 } 362 362 363 int fibril_get_sercount(void) 364 { 365 return serialization_count; 366 } 367 363 368 /** @} 364 369 */ -
uspace/lib/c/generic/fibril_synch.c
ra97ea0f r6610565b 104 104 fibril_t *f = (fibril_t *) fibril_get_id(); 105 105 106 if (fibril_get_sercount() != 0) 107 core(); 108 106 109 futex_down(&async_futex); 107 110 if (fm->counter-- <= 0) { … … 194 197 fibril_t *f = (fibril_t *) fibril_get_id(); 195 198 199 if (fibril_get_sercount() != 0) 200 core(); 201 196 202 futex_down(&async_futex); 197 203 if (frw->writers) { … … 219 225 fibril_t *f = (fibril_t *) fibril_get_id(); 220 226 227 if (fibril_get_sercount() != 0) 228 core(); 229 221 230 futex_down(&async_futex); 222 231 if (frw->writers || frw->readers) { -
uspace/lib/c/generic/io/vprintf.c
ra97ea0f r6610565b 37 37 #include <unistd.h> 38 38 #include <io/printf_core.h> 39 #include <f utex.h>39 #include <fibril_synch.h> 40 40 #include <async.h> 41 41 #include <str.h> 42 42 43 static atomic_t printf_futex = FUTEX_INITIALIZER;43 static FIBRIL_MUTEX_INITIALIZE(printf_mutex); 44 44 45 45 static int vprintf_str_write(const char *str, size_t size, void *stream) … … 85 85 * Prevent other threads to execute printf_core() 86 86 */ 87 futex_down(&printf_futex); 88 89 /* 90 * Prevent other fibrils of the same thread 91 * to execute printf_core() 92 */ 93 async_serialize_start(); 87 fibril_mutex_lock(&printf_mutex); 94 88 95 89 int ret = printf_core(fmt, &ps, ap); 96 90 97 async_serialize_end(); 98 futex_up(&printf_futex); 91 fibril_mutex_unlock(&printf_mutex); 99 92 100 93 return ret; -
uspace/lib/c/generic/mem.c
ra97ea0f r6610565b 222 222 /** Compare two memory areas. 223 223 * 224 * @param s1 Pointer to the first area to compare. 225 * @param s2 Pointer to the second area to compare. 226 * @param len Size of the first area in bytes. Both areas must have 227 * the same length. 228 * @return If len is 0, return zero. If the areas match, return 229 * zero. Otherwise return non-zero. 230 */ 231 int bcmp(const char *s1, const char *s2, size_t len) 232 { 233 for (; len && *s1++ == *s2++; len--) 234 ; 224 * @param s1 Pointer to the first area to compare. 225 * @param s2 Pointer to the second area to compare. 226 * @param len Size of the first area in bytes. Both areas must have 227 * the same length. 228 * 229 * @return If len is 0, return zero. If the areas match, return 230 * zero. Otherwise return non-zero. 231 * 232 */ 233 int bcmp(const void *s1, const void *s2, size_t len) 234 { 235 uint8_t *u1 = (uint8_t *) s1; 236 uint8_t *u2 = (uint8_t *) s2; 237 238 for (; (len != 0) && (*u1++ == *u2++); len--); 239 235 240 return len; 236 241 } -
uspace/lib/c/generic/net/modules.c
ra97ea0f r6610565b 32 32 33 33 /** @file 34 * Generic module functions implementation. 34 * Generic module functions implementation. 35 35 * 36 36 * @todo MAKE IT POSSIBLE TO REMOVE THIS FILE VIA EITHER REPLACING PART OF ITS … … 52 52 #define MODULE_WAIT_TIME (10 * 1000) 53 53 54 /** Answer s thecall.55 * 56 * @param[in] callid The call identifier.57 * @param[in] result The message processing result.58 * @param[in] answer The message processing answer.59 * @param[in] answer_count The number of answer parameters.60 * /61 void 62 answer_call(ipc_callid_t callid, int result, ipc_call_t *answer,63 int answer_count)64 { 65 /* Choose the most efficient answerfunction */66 if ( answer || (!answer_count)) {67 switch ( answer_count) {54 /** Answer a call. 55 * 56 * @param[in] callid Call identifier. 57 * @param[in] result Message processing result. 58 * @param[in] answer Message processing answer. 59 * @param[in] count Number of answer parameters. 60 * 61 */ 62 void answer_call(ipc_callid_t callid, int result, ipc_call_t *answer, 63 size_t count) 64 { 65 /* Choose the most efficient function */ 66 if ((answer != NULL) || (count == 0)) { 67 switch (count) { 68 68 case 0: 69 69 ipc_answer_0(callid, (sysarg_t) result); … … 228 228 } 229 229 230 /** Refreshes answer structure and parameters count. 231 * 232 * Erases all attributes. 233 * 234 * @param[in,out] answer The message processing answer structure. 235 * @param[in,out] answer_count The number of answer parameters. 236 */ 237 void refresh_answer(ipc_call_t *answer, int *answer_count) 238 { 239 if (answer_count) 240 *answer_count = 0; 241 242 if (answer) { 230 /** Refresh answer structure and argument count. 231 * 232 * Erase all arguments. 233 * 234 * @param[in,out] answer Message processing answer structure. 235 * @param[in,out] count Number of answer arguments. 236 * 237 */ 238 void refresh_answer(ipc_call_t *answer, size_t *count) 239 { 240 if (count != NULL) 241 *count = 0; 242 243 if (answer != NULL) { 243 244 IPC_SET_RETVAL(*answer, 0); 244 /* Just to be precise */245 245 IPC_SET_IMETHOD(*answer, 0); 246 246 IPC_SET_ARG1(*answer, 0);
Note:
See TracChangeset
for help on using the changeset viewer.
