Changeset 78192cc7 in mainline
- Timestamp:
- 2014-07-13T14:06:23Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- af2a76c, f303f2cf
- Parents:
- c1b979a
- Location:
- uspace
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/vlaunch/vlaunch.c
rc1b979a r78192cc7 200 200 } 201 201 202 timer = fibril_timer_create( );202 timer = fibril_timer_create(NULL); 203 203 if (!timer) { 204 204 printf("Unable to create timer.\n"); -
uspace/lib/c/generic/fibril_synch.c
rc1b979a r78192cc7 448 448 int rc; 449 449 450 fibril_mutex_lock( &timer->lock);450 fibril_mutex_lock(timer->lockp); 451 451 452 452 while (timer->state != fts_cleanup) { … … 454 454 case fts_not_set: 455 455 case fts_fired: 456 fibril_condvar_wait(&timer->cv, &timer->lock);456 fibril_condvar_wait(&timer->cv, timer->lockp); 457 457 break; 458 458 case fts_active: 459 459 rc = fibril_condvar_wait_timeout(&timer->cv, 460 &timer->lock, timer->delay);460 timer->lockp, timer->delay); 461 461 if (rc == ETIMEOUT && timer->state == fts_active) { 462 462 timer->state = fts_fired; 463 fibril_mutex_unlock(&timer->lock); 463 timer->handler_running = true; 464 fibril_mutex_unlock(timer->lockp); 464 465 timer->fun(timer->arg); 465 fibril_mutex_lock(&timer->lock); 466 fibril_mutex_lock(timer->lockp); 467 timer->handler_running = false; 466 468 } 467 469 break; … … 475 477 /* Acknowledge timer fibril has finished cleanup. */ 476 478 timer->state = fts_clean; 477 fibril_ condvar_broadcast(&timer->cv);478 f ibril_mutex_unlock(&timer->lock);479 fibril_mutex_unlock(timer->lockp); 480 free(timer); 479 481 480 482 return 0; … … 485 487 * @return New timer on success, @c NULL if out of memory. 486 488 */ 487 fibril_timer_t *fibril_timer_create( void)489 fibril_timer_t *fibril_timer_create(fibril_mutex_t *lock) 488 490 { 489 491 fid_t fid; … … 505 507 timer->fibril = fid; 506 508 timer->state = fts_not_set; 509 timer->lockp = (lock != NULL) ? lock : &timer->lock; 507 510 508 511 fibril_add_ready(fid); 509 510 512 return timer; 511 513 } … … 517 519 void fibril_timer_destroy(fibril_timer_t *timer) 518 520 { 519 fibril_mutex_lock( &timer->lock);521 fibril_mutex_lock(timer->lockp); 520 522 assert(timer->state == fts_not_set || timer->state == fts_fired); 521 523 … … 523 525 timer->state = fts_cleanup; 524 526 fibril_condvar_broadcast(&timer->cv); 525 526 /* Wait for timer fibril to acknowledge. */ 527 while (timer->state != fts_clean) 528 fibril_condvar_wait(&timer->cv, &timer->lock); 529 530 fibril_mutex_unlock(&timer->lock); 527 fibril_mutex_unlock(timer->lockp); 531 528 } 532 529 … … 544 541 fibril_timer_fun_t fun, void *arg) 545 542 { 546 fibril_mutex_lock(&timer->lock); 543 fibril_mutex_lock(timer->lockp); 544 fibril_timer_set_locked(timer, delay, fun, arg); 545 fibril_mutex_unlock(timer->lockp); 546 } 547 548 /** Set locked timer. 549 * 550 * Set timer to execute a callback function after the specified 551 * interval. Must be called when the timer is locked. 552 * 553 * @param timer Timer 554 * @param delay Delay in microseconds 555 * @param fun Callback function 556 * @param arg Argument for @a fun 557 */ 558 void fibril_timer_set_locked(fibril_timer_t *timer, suseconds_t delay, 559 fibril_timer_fun_t fun, void *arg) 560 { 561 assert(fibril_mutex_is_locked(timer->lockp)); 547 562 assert(timer->state == fts_not_set || timer->state == fts_fired); 548 563 timer->state = fts_active; … … 551 566 timer->arg = arg; 552 567 fibril_condvar_broadcast(&timer->cv); 553 fibril_mutex_unlock(&timer->lock);554 568 } 555 569 … … 569 583 fibril_timer_state_t old_state; 570 584 571 fibril_mutex_lock(&timer->lock); 585 fibril_mutex_lock(timer->lockp); 586 old_state = fibril_timer_clear_locked(timer); 587 fibril_mutex_unlock(timer->lockp); 588 589 return old_state; 590 } 591 592 /** Clear locked timer. 593 * 594 * Clears (cancels) timer and returns last state of the timer. 595 * This can be one of: 596 * - fts_not_set If the timer has not been set or has been cleared 597 * - fts_active Timer was set but did not fire 598 * - fts_fired Timer fired 599 * Must be called when the timer is locked. 600 * 601 * @param timer Timer 602 * @return Last timer state 603 */ 604 fibril_timer_state_t fibril_timer_clear_locked(fibril_timer_t *timer) 605 { 606 fibril_timer_state_t old_state; 607 608 assert(fibril_mutex_is_locked(timer->lockp)); 609 610 while (timer->handler_running) 611 fibril_condvar_wait(&timer->cv, timer->lockp); 612 572 613 old_state = timer->state; 573 614 timer->state = fts_not_set; … … 577 618 timer->arg = NULL; 578 619 fibril_condvar_broadcast(&timer->cv); 579 fibril_mutex_unlock(&timer->lock);580 620 581 621 return old_state; -
uspace/lib/c/include/fibril_synch.h
rc1b979a r78192cc7 131 131 typedef struct { 132 132 fibril_mutex_t lock; 133 fibril_mutex_t *lockp; 133 134 fibril_condvar_t cv; 134 135 fid_t fibril; 135 136 fibril_timer_state_t state; 137 bool handler_running; 136 138 137 139 suseconds_t delay; … … 162 164 extern void fibril_condvar_broadcast(fibril_condvar_t *); 163 165 164 extern fibril_timer_t *fibril_timer_create( void);166 extern fibril_timer_t *fibril_timer_create(fibril_mutex_t *); 165 167 extern void fibril_timer_destroy(fibril_timer_t *); 166 168 extern void fibril_timer_set(fibril_timer_t *, suseconds_t, fibril_timer_fun_t, 167 169 void *); 170 extern void fibril_timer_set_locked(fibril_timer_t *, suseconds_t, 171 fibril_timer_fun_t, void *); 168 172 extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *); 173 extern fibril_timer_state_t fibril_timer_clear_locked(fibril_timer_t *); 169 174 170 175 #endif -
uspace/srv/net/dhcp/dhcp.c
rc1b979a r78192cc7 436 436 437 437 dlink->link_id = link_id; 438 dlink->timeout = fibril_timer_create( );438 dlink->timeout = fibril_timer_create(NULL); 439 439 if (dlink->timeout == NULL) { 440 440 rc = ENOMEM; -
uspace/srv/net/tcp/conn.c
rc1b979a r78192cc7 78 78 goto error; 79 79 80 conn->tw_timer = fibril_timer_create(); 80 fibril_mutex_initialize(&conn->lock); 81 82 conn->tw_timer = fibril_timer_create(&conn->lock); 81 83 if (conn->tw_timer == NULL) 82 84 goto error; 83 84 fibril_mutex_initialize(&conn->lock);85 85 86 86 /* One for the user, one for not being in closed state */ … … 200 200 if (atomic_predec(&conn->refcnt) == 0) 201 201 tcp_conn_free(conn); 202 } 203 204 /** Lock connection. 205 * 206 * Must be called before any other connection-manipulating function, 207 * except tcp_conn_{add|del}ref(). Locks the connection including 208 * its timers. Must not be called inside any of the connection 209 * timer handlers. 210 * 211 * @param conn Connection 212 */ 213 void tcp_conn_lock(tcp_conn_t *conn) 214 { 215 fibril_mutex_lock(&conn->lock); 216 } 217 218 /** Unlock connection. 219 * 220 * @param conn Connection 221 */ 222 void tcp_conn_unlock(tcp_conn_t *conn) 223 { 224 fibril_mutex_unlock(&conn->lock); 202 225 } 203 226 … … 1183 1206 log_msg(LOG_DEFAULT, LVL_DEBUG, "tw_timeout_func(%p)", conn); 1184 1207 1185 fibril_mutex_lock(&conn->lock);1208 tcp_conn_lock(conn); 1186 1209 1187 1210 if (conn->cstate == st_closed) { 1188 1211 log_msg(LOG_DEFAULT, LVL_DEBUG, "Connection already closed."); 1189 fibril_mutex_unlock(&conn->lock);1212 tcp_conn_unlock(conn); 1190 1213 tcp_conn_delref(conn); 1191 1214 return; … … 1196 1219 tcp_conn_state_set(conn, st_closed); 1197 1220 1198 fibril_mutex_unlock(&conn->lock);1221 tcp_conn_unlock(conn); 1199 1222 tcp_conn_delref(conn); 1223 1224 log_msg(LOG_DEFAULT, LVL_DEBUG, "tw_timeout_func(%p) end", conn); 1200 1225 } 1201 1226 … … 1206 1231 void tcp_conn_tw_timer_set(tcp_conn_t *conn) 1207 1232 { 1233 log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_conn_tw_timer_set() begin"); 1208 1234 tcp_conn_addref(conn); 1209 fibril_timer_set(conn->tw_timer, TIME_WAIT_TIMEOUT, tw_timeout_func, 1210 (void *)conn); 1235 fibril_timer_set_locked(conn->tw_timer, TIME_WAIT_TIMEOUT, 1236 tw_timeout_func, (void *)conn); 1237 log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_conn_tw_timer_set() end"); 1211 1238 } 1212 1239 … … 1217 1244 void tcp_conn_tw_timer_clear(tcp_conn_t *conn) 1218 1245 { 1219 if (fibril_timer_clear(conn->tw_timer) == fts_active) 1246 log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_conn_tw_timer_clear() begin"); 1247 if (fibril_timer_clear_locked(conn->tw_timer) == fts_active) 1220 1248 tcp_conn_delref(conn); 1249 log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_conn_tw_timer_clear() end"); 1221 1250 } 1222 1251 -
uspace/srv/net/tcp/conn.h
rc1b979a r78192cc7 50 50 extern void tcp_conn_addref(tcp_conn_t *); 51 51 extern void tcp_conn_delref(tcp_conn_t *); 52 extern void tcp_conn_lock(tcp_conn_t *); 53 extern void tcp_conn_unlock(tcp_conn_t *); 52 54 extern bool tcp_conn_got_syn(tcp_conn_t *); 53 55 extern void tcp_conn_segment_arrived(tcp_conn_t *, tcp_segment_t *); -
uspace/srv/net/tcp/tqueue.c
rc1b979a r78192cc7 59 59 static void tcp_tqueue_timer_clear(tcp_conn_t *conn); 60 60 61 #include <stdio.h> 61 62 int tcp_tqueue_init(tcp_tqueue_t *tqueue, tcp_conn_t *conn) 62 63 { 64 printf("tcp_tqueue_init\n"); 63 65 tqueue->conn = conn; 64 tqueue->timer = fibril_timer_create( );66 tqueue->timer = fibril_timer_create(&conn->lock); 65 67 if (tqueue->timer == NULL) 66 68 return ENOMEM; … … 78 80 void tcp_tqueue_fini(tcp_tqueue_t *tqueue) 79 81 { 82 printf("tcp_tqueue_fini\n"); 80 83 if (tqueue->timer != NULL) { 81 84 fibril_timer_destroy(tqueue->timer); … … 319 322 log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: retransmit_timeout_func(%p)", conn->name, conn); 320 323 321 fibril_mutex_lock(&conn->lock);324 tcp_conn_lock(conn); 322 325 323 326 if (conn->cstate == st_closed) { 324 327 log_msg(LOG_DEFAULT, LVL_DEBUG, "Connection already closed."); 325 fibril_mutex_unlock(&conn->lock);328 tcp_conn_unlock(conn); 326 329 tcp_conn_delref(conn); 327 330 return; … … 331 334 if (link == NULL) { 332 335 log_msg(LOG_DEFAULT, LVL_DEBUG, "Nothing to retransmit"); 333 fibril_mutex_unlock(&conn->lock);336 tcp_conn_unlock(conn); 334 337 tcp_conn_delref(conn); 335 338 return; … … 341 344 if (rt_seg == NULL) { 342 345 log_msg(LOG_DEFAULT, LVL_ERROR, "Memory allocation failed."); 343 fibril_mutex_unlock(&conn->lock);346 tcp_conn_unlock(conn); 344 347 tcp_conn_delref(conn); 345 348 /* XXX Handle properly */ … … 353 356 tcp_tqueue_timer_set(tqe->conn); 354 357 355 fibril_mutex_unlock(&conn->lock);358 tcp_conn_unlock(conn); 356 359 tcp_conn_delref(conn); 360 361 log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: retransmit_timeout_func(%p) end", conn->name, conn); 357 362 } 358 363 … … 360 365 static void tcp_tqueue_timer_set(tcp_conn_t *conn) 361 366 { 362 log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_set() ", conn->name);367 log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_set() begin", conn->name); 363 368 364 369 /* Clear first to make sure we update refcnt correctly */ … … 366 371 367 372 tcp_conn_addref(conn); 368 fibril_timer_set (conn->retransmit.timer, RETRANSMIT_TIMEOUT,373 fibril_timer_set_locked(conn->retransmit.timer, RETRANSMIT_TIMEOUT, 369 374 retransmit_timeout_func, (void *) conn); 375 376 log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_set() end", conn->name); 370 377 } 371 378 … … 373 380 static void tcp_tqueue_timer_clear(tcp_conn_t *conn) 374 381 { 375 log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_clear() ", conn->name);376 377 if (fibril_timer_clear (conn->retransmit.timer) == fts_active)382 log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_clear() begin", conn->name); 383 384 if (fibril_timer_clear_locked(conn->retransmit.timer) == fts_active) 378 385 tcp_conn_delref(conn); 386 387 log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_clear() end", conn->name); 379 388 } 380 389 -
uspace/srv/net/tcp/ucall.c
rc1b979a r78192cc7 90 90 /* Wait for connection to be established or reset */ 91 91 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open: Wait for connection."); 92 fibril_mutex_lock(&nconn->lock);92 tcp_conn_lock(nconn); 93 93 while (nconn->cstate == st_listen || 94 94 nconn->cstate == st_syn_sent || … … 100 100 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open: Connection was reset."); 101 101 assert(nconn->cstate == st_closed); 102 fibril_mutex_unlock(&nconn->lock);102 tcp_conn_unlock(nconn); 103 103 return TCP_ERESET; 104 104 } 105 105 106 fibril_mutex_unlock(&nconn->lock);106 tcp_conn_unlock(nconn); 107 107 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open: Connection was established."); 108 108 … … 121 121 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_uc_send()", conn->name); 122 122 123 fibril_mutex_lock(&conn->lock);123 tcp_conn_lock(conn); 124 124 125 125 if (conn->cstate == st_closed) { 126 fibril_mutex_unlock(&conn->lock);126 tcp_conn_unlock(conn); 127 127 return TCP_ENOTEXIST; 128 128 } … … 135 135 136 136 if (conn->snd_buf_fin) { 137 fibril_mutex_unlock(&conn->lock);137 tcp_conn_unlock(conn); 138 138 return TCP_ECLOSING; 139 139 } … … 149 149 150 150 if (conn->reset) { 151 fibril_mutex_unlock(&conn->lock);151 tcp_conn_unlock(conn); 152 152 return TCP_ERESET; 153 153 } … … 165 165 166 166 tcp_tqueue_new_data(conn); 167 fibril_mutex_unlock(&conn->lock);167 tcp_conn_unlock(conn); 168 168 169 169 return TCP_EOK; … … 178 178 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_uc_receive()", conn->name); 179 179 180 fibril_mutex_lock(&conn->lock);180 tcp_conn_lock(conn); 181 181 182 182 if (conn->cstate == st_closed) { 183 fibril_mutex_unlock(&conn->lock);183 tcp_conn_unlock(conn); 184 184 return TCP_ENOTEXIST; 185 185 } … … 197 197 if (conn->rcv_buf_fin) { 198 198 /* End of data, peer closed connection */ 199 fibril_mutex_unlock(&conn->lock);199 tcp_conn_unlock(conn); 200 200 return TCP_ECLOSING; 201 201 } else { 202 202 /* Connection was reset */ 203 203 assert(conn->reset); 204 fibril_mutex_unlock(&conn->lock);204 tcp_conn_unlock(conn); 205 205 return TCP_ERESET; 206 206 } … … 227 227 conn->name, xfer_size); 228 228 229 fibril_mutex_unlock(&conn->lock);229 tcp_conn_unlock(conn); 230 230 231 231 return TCP_EOK; … … 238 238 conn); 239 239 240 fibril_mutex_lock(&conn->lock);240 tcp_conn_lock(conn); 241 241 242 242 if (conn->cstate == st_closed) { 243 243 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_close - ENOTEXIST"); 244 fibril_mutex_unlock(&conn->lock);244 tcp_conn_unlock(conn); 245 245 return TCP_ENOTEXIST; 246 246 } … … 250 250 tcp_conn_reset(conn); 251 251 tcp_conn_remove(conn); 252 tcp_conn_unlock(conn); 252 253 return TCP_EOK; 253 254 } … … 255 256 if (conn->snd_buf_fin) { 256 257 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_close - ECLOSING"); 257 fibril_mutex_unlock(&conn->lock);258 tcp_conn_unlock(conn); 258 259 return TCP_ECLOSING; 259 260 } … … 263 264 tcp_tqueue_new_data(conn); 264 265 265 fibril_mutex_unlock(&conn->lock);266 tcp_conn_unlock(conn); 266 267 return TCP_EOK; 267 268 } … … 321 322 } 322 323 323 fibril_mutex_lock(&conn->lock);324 tcp_conn_lock(conn); 324 325 325 326 if (conn->cstate == st_closed) { 326 327 log_msg(LOG_DEFAULT, LVL_WARN, "Connection is closed."); 327 328 tcp_unexpected_segment(sp, seg); 328 fibril_mutex_unlock(&conn->lock);329 tcp_conn_unlock(conn); 329 330 tcp_conn_delref(conn); 330 331 return; … … 342 343 tcp_conn_segment_arrived(conn, seg); 343 344 344 fibril_mutex_unlock(&conn->lock);345 tcp_conn_unlock(conn); 345 346 tcp_conn_delref(conn); 346 347 }
Note:
See TracChangeset
for help on using the changeset viewer.