Changeset 521 for GPL/trunk/lib32/misc.c
- Timestamp:
- Jul 21, 2010, 7:13:21 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/trunk/lib32/misc.c
r518 r521 409 409 //****************************************************************************** 410 410 //****************************************************************************** 411 #define del_timer_sync(t) del_timer(t) /* FIXME: not quite correct on SMP */ 412 int cancel_delayed_work(struct delayed_work *dwork) 413 { 414 struct work_struct *work = &dwork->work; 415 int ret; 416 417 ret = del_timer_sync(&work->timer); 418 if (ret) 419 clear_bit(0, &work->pending); 420 return ret; 421 } 422 //****************************************************************************** 423 //****************************************************************************** 424 int schedule_work(struct work_struct *works) 425 { 426 #ifndef TARGET_OS2 427 return kernel_thread(work_caller, works, 0) >= 0; 428 #else 429 return 1; 430 #endif 431 } 432 //****************************************************************************** 433 //****************************************************************************** 434 static void delayed_work_timer_fn(unsigned long __data) 435 { 436 struct work_struct *work = (struct work_struct *)__data; 437 struct workqueue_struct *wq = work->wq_data; 438 439 if (wq) 440 __x_queue_work(wq, work); 441 else 442 schedule_work(work); 443 } 444 //****************************************************************************** 445 //****************************************************************************** 446 int queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork, unsigned long delay) 447 { 448 struct work_struct *work = &dwork->work; 449 struct timer_list *timer = &work->timer; 450 451 if (!test_and_set_bit(0, &work->pending)) { 452 work->wq_data = wq; 453 timer->expires = jiffies + delay; 454 timer->data = (unsigned long)work; 455 timer->function = delayed_work_timer_fn; 456 add_timer(timer); 457 return 1; 458 } 459 return 0; 460 } 461 //****************************************************************************** 462 //****************************************************************************** 463 /* Greatest common divisor */ 464 unsigned long gcd(unsigned long a, unsigned long b) 465 { 466 unsigned long r; 467 if (a < b) { 468 r = a; 469 a = b; 470 b = r; 471 } 472 while ((r = a % b) != 0) { 473 a = b; 474 b = r; 475 } 476 return b; 477 } 478 479 //****************************************************************************** 480 //****************************************************************************** 481 int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) 482 { 483 char *tail; 484 unsigned long val; 485 size_t len; 486 487 *res = 0; 488 len = strlen(cp); 489 if (len == 0) 490 return -EINVAL; 491 492 val = simple_strtoul(cp, &tail, base); 493 if (tail == cp) 494 return -EINVAL; 495 496 if ((*tail == '\0') || 497 ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { 498 *res = val; 499 return 0; 500 } 501 502 return -EINVAL; 503 } 411
Note:
See TracChangeset
for help on using the changeset viewer.