| 487 | } |
| 488 | |
| 489 | int bthread_id_cancel(bthread_id_t id) { |
| 490 | bthread::Id* const meta = address_resource(bthread::get_slot(id)); |
| 491 | if (!meta) { |
| 492 | return EINVAL; |
| 493 | } |
| 494 | uint32_t* butex = meta->butex; |
| 495 | const uint32_t id_ver = bthread::get_version(id); |
| 496 | meta->mutex.lock(); |
| 497 | if (!meta->has_version(id_ver)) { |
| 498 | meta->mutex.unlock(); |
| 499 | return EINVAL; |
| 500 | } |
| 501 | if (*butex != meta->first_ver) { |
| 502 | meta->mutex.unlock(); |
| 503 | return EPERM; |
| 504 | } |
| 505 | *butex = meta->end_ver(); |
| 506 | meta->first_ver = *butex; |
| 507 | meta->locked_ver = *butex; |
| 508 | meta->mutex.unlock(); |
| 509 | return_resource(bthread::get_slot(id)); |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | int bthread_id_join(bthread_id_t id) { |
| 514 | const bthread::IdResourceId slot = bthread::get_slot(id); |
no test coverage detected