Changeset 4579
- Timestamp:
- 11/05/08 12:29:56 (2 months ago)
- Files:
-
- trunk/src/charon/config/peer_cfg.c (modified) (7 diffs)
- trunk/src/charon/network/sender.c (modified) (7 diffs)
- trunk/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c (modified) (9 diffs)
- trunk/src/charon/plugins/kernel_netlink/kernel_netlink_net.c (modified) (30 diffs)
- trunk/src/charon/plugins/kernel_netlink/kernel_netlink_shared.c (modified) (10 diffs)
- trunk/src/charon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c (modified) (26 diffs)
- trunk/src/charon/processing/jobs/callback_job.c (modified) (9 diffs)
- trunk/src/charon/processing/processor.c (modified) (13 diffs)
- trunk/src/charon/sa/authenticators/eap/eap_manager.c (modified) (9 diffs)
- trunk/src/charon/sa/connect_manager.c (modified) (32 diffs)
- trunk/src/charon/sa/ike_sa_manager.c (modified) (40 diffs)
- trunk/src/charon/sa/mediation_manager.c (modified) (13 diffs)
- trunk/src/libstrongswan/plugins/openssl/openssl_plugin.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/charon/config/peer_cfg.c
r4276 r4579 19 19 20 20 #include <string.h> 21 #include <pthread.h>22 21 23 22 #include "peer_cfg.h" 24 23 24 #include <utils/mutex.h> 25 25 #include <utils/linked_list.h> 26 26 #include <utils/identification.h> … … 78 78 * mutex to lock access to list of child_cfgs 79 79 */ 80 pthread_mutex_tmutex;80 mutex_t *mutex; 81 81 82 82 /** … … 198 198 static void add_child_cfg(private_peer_cfg_t *this, child_cfg_t *child_cfg) 199 199 { 200 pthread_mutex_lock(&this->mutex);200 this->mutex->lock(this->mutex); 201 201 this->child_cfgs->insert_last(this->child_cfgs, child_cfg); 202 pthread_mutex_unlock(&this->mutex);202 this->mutex->unlock(this->mutex); 203 203 } 204 204 … … 208 208 static void remove_child_cfg(private_peer_cfg_t *this, enumerator_t *enumerator) 209 209 { 210 pthread_mutex_lock(&this->mutex);210 this->mutex->lock(this->mutex); 211 211 this->child_cfgs->remove_at(this->child_cfgs, enumerator); 212 pthread_mutex_unlock(&this->mutex);212 this->mutex->unlock(this->mutex); 213 213 } 214 214 … … 220 220 enumerator_t *enumerator; 221 221 222 pthread_mutex_lock(&this->mutex);222 this->mutex->lock(this->mutex); 223 223 enumerator = this->child_cfgs->create_enumerator(this->child_cfgs); 224 224 return enumerator_create_cleaner(enumerator, 225 (void*) pthread_mutex_unlock, &this->mutex);225 (void*)this->mutex->unlock, this->mutex); 226 226 } 227 227 … … 481 481 DESTROY_IF(this->peer_id); 482 482 #endif /* ME */ 483 this->mutex->destroy(this->mutex); 483 484 free(this->name); 484 485 free(this->pool); … … 537 538 this->ike_cfg = ike_cfg; 538 539 this->child_cfgs = linked_list_create(); 539 pthread_mutex_init(&this->mutex, NULL);540 this->mutex = mutex_create(MUTEX_DEFAULT); 540 541 this->my_id = my_id; 541 542 this->other_id = other_id; trunk/src/charon/network/sender.c
r3742 r4579 25 25 #include <network/socket.h> 26 26 #include <processing/jobs/callback_job.h> 27 #include <utils/mutex.h> 27 28 28 29 … … 51 52 * mutex to synchronize access to list 52 53 */ 53 pthread_mutex_tmutex;54 mutex_t *mutex; 54 55 55 56 /** 56 57 * condvar to signal for packets added to list 57 58 */ 58 pthread_cond_t gotone;59 condvar_t *got; 59 60 60 61 /** 61 62 * condvar to signal for packets sent 62 63 */ 63 pthread_cond_t sentone;64 condvar_t *sent; 64 65 }; 65 66 … … 75 76 DBG1(DBG_NET, "sending packet: from %#H to %#H", src, dst); 76 77 77 pthread_mutex_lock(&this->mutex);78 this->mutex->lock(this->mutex); 78 79 this->list->insert_last(this->list, packet); 79 pthread_cond_signal(&this->gotone);80 pthread_mutex_unlock(&this->mutex);80 this->got->signal(this->got); 81 this->mutex->unlock(this->mutex); 81 82 } 82 83 … … 89 90 int oldstate; 90 91 91 pthread_mutex_lock(&this->mutex);92 this->mutex->lock(this->mutex); 92 93 while (this->list->get_count(this->list) == 0) 93 94 { 94 95 /* add cleanup handler, wait for packet, remove cleanup handler */ 95 pthread_cleanup_push((void(*)(void*)) pthread_mutex_unlock, (void*)&this->mutex);96 pthread_cleanup_push((void(*)(void*))this->mutex->unlock, this->mutex); 96 97 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); 97 98 98 pthread_cond_wait(&this->gotone, &this->mutex);99 this->got->wait(this->got, this->mutex); 99 100 100 101 pthread_setcancelstate(oldstate, NULL); … … 102 103 } 103 104 this->list->remove_first(this->list, (void**)&packet); 104 pthread_cond_signal(&this->sentone);105 pthread_mutex_unlock(&this->mutex);105 this->sent->signal(this->sent); 106 this->mutex->unlock(this->mutex); 106 107 107 108 charon->socket->send(charon->socket, packet); … … 116 117 { 117 118 /* send all packets in the queue */ 118 pthread_mutex_lock(&this->mutex);119 this->mutex->lock(this->mutex); 119 120 while (this->list->get_count(this->list)) 120 121 { 121 pthread_cond_wait(&this->sentone, &this->mutex);122 this->sent->wait(this->sent, this->mutex); 122 123 } 123 pthread_mutex_unlock(&this->mutex); 124 pthread_mutex_destroy(&this->mutex); 124 this->mutex->unlock(this->mutex); 125 this->got->destroy(this->got); 126 this->sent->destroy(this->sent); 127 this->mutex->destroy(this->mutex); 125 128 this->job->cancel(this->job); 126 129 this->list->destroy(this->list); … … 134 137 { 135 138 private_sender_t *this = malloc_thing(private_sender_t); 136 139 137 140 this->public.send = (void(*)(sender_t*,packet_t*))send_; 138 141 this->public.destroy = (void(*)(sender_t*)) destroy; 139 142 140 143 this->list = linked_list_create(); 141 pthread_mutex_init(&this->mutex, NULL);142 pthread_cond_init(&this->gotone, NULL);143 pthread_cond_init(&this->sentone, NULL);144 144 this->mutex = mutex_create(MUTEX_DEFAULT); 145 this->got = condvar_create(CONDVAR_DEFAULT); 146 this->sent = condvar_create(CONDVAR_DEFAULT); 147 145 148 this->job = callback_job_create((callback_job_cb_t)send_packets, 146 149 this, NULL, NULL); 147 150 charon->processor->queue_job(charon->processor, (job_t*)this->job); 148 151 149 152 return &this->public; 150 153 } trunk/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c
r4576 r4579 38 38 39 39 #include <daemon.h> 40 #include <utils/mutex.h> 40 41 #include <utils/linked_list.h> 41 42 #include <processing/jobs/callback_job.h> … … 253 254 * mutex to lock access to various lists 254 255 */ 255 pthread_mutex_tmutex;256 mutex_t *mutex; 256 257 257 258 /** … … 1375 1376 1376 1377 /* find the policy, which matches EXACTLY */ 1377 pthread_mutex_lock(&this->mutex);1378 this->mutex->lock(this->mutex); 1378 1379 iterator = this->policies->create_iterator(this->policies, TRUE); 1379 1380 while (iterator->iterate(iterator, (void**)¤t)) … … 1419 1420 policy_info->action = XFRM_POLICY_ALLOW; 1420 1421 policy_info->share = XFRM_SHARE_ANY; 1421 pthread_mutex_unlock(&this->mutex);1422 this->mutex->unlock(this->mutex); 1422 1423 1423 1424 /* policies don't expire */ … … 1635 1636 1636 1637 /* find the policy */ 1637 pthread_mutex_lock(&this->mutex);1638 this->mutex->lock(this->mutex); 1638 1639 enumerator = this->policies->create_enumerator(this->policies); 1639 1640 while (enumerator->enumerate(enumerator, ¤t)) … … 1647 1648 /* is used by more SAs, keep in kernel */ 1648 1649 DBG2(DBG_KNL, "policy still used by another CHILD_SA, not removed"); 1649 pthread_mutex_unlock(&this->mutex);1650 this->mutex->unlock(this->mutex); 1650 1651 enumerator->destroy(enumerator); 1651 1652 return SUCCESS; … … 1656 1657 } 1657 1658 } 1658 pthread_mutex_unlock(&this->mutex);1659 this->mutex->unlock(this->mutex); 1659 1660 enumerator->destroy(enumerator); 1660 1661 if (!to_delete) … … 1710 1711 this->socket_xfrm->destroy(this->socket_xfrm); 1711 1712 this->policies->destroy(this->policies); 1713 this->mutex->destroy(this->mutex); 1712 1714 free(this); 1713 1715 } … … 1734 1736 /* private members */ 1735 1737 this->policies = linked_list_create(); 1736 pthread_mutex_init(&this->mutex, NULL);1738 this->mutex = mutex_create(MUTEX_DEFAULT); 1737 1739 this->install_routes = lib->settings->get_bool(lib->settings, 1738 1740 "charon.install_routes", TRUE); trunk/src/charon/plugins/kernel_netlink/kernel_netlink_net.c
r4576 r4579 30 30 31 31 #include <daemon.h> 32 #include <utils/mutex.h> 32 33 #include <utils/linked_list.h> 33 34 #include <processing/jobs/callback_job.h> … … 117 118 * mutex to lock access to various lists 118 119 */ 119 pthread_mutex_tmutex;120 mutex_t *mutex; 120 121 121 122 /** 122 123 * condition variable to signal virtual IP add/removal 123 124 */ 124 pthread_cond_t cond;125 condvar_t *condvar; 125 126 126 127 /** … … 254 255 } 255 256 256 pthread_mutex_lock(&this->mutex);257 this->mutex->lock(this->mutex); 257 258 switch (hdr->nlmsg_type) 258 259 { … … 316 317 } 317 318 } 318 pthread_mutex_unlock(&this->mutex);319 this->mutex->unlock(this->mutex); 319 320 320 321 /* send an update to all IKE_SAs */ … … 374 375 } 375 376 376 pthread_mutex_lock(&this->mutex);377 this->mutex->lock(this->mutex); 377 378 ifaces = this->ifaces->create_enumerator(this->ifaces); 378 379 while (ifaces->enumerate(ifaces, &iface)) … … 432 433 } 433 434 ifaces->destroy(ifaces); 434 pthread_mutex_unlock(&this->mutex);435 this->mutex->unlock(this->mutex); 435 436 host->destroy(host); 436 437 … … 471 472 if (host) 472 473 { 474 this->mutex->lock(this->mutex); 473 475 if (!get_vip_refcount(this, host)) 474 476 { /* ignore routes added for virtual IPs */ 475 477 fire_roam_job(this, FALSE); 476 478 } 479 this->mutex->unlock(this->mutex); 477 480 host->destroy(host); 478 481 } … … 525 528 case RTM_DELADDR: 526 529 process_addr(this, hdr, TRUE); 527 pthread_cond_broadcast(&this->cond);530 this->condvar->broadcast(this->condvar); 528 531 break; 529 532 case RTM_NEWLINK: 530 533 case RTM_DELLINK: 531 534 process_link(this, hdr, TRUE); 532 pthread_cond_broadcast(&this->cond);535 this->condvar->broadcast(this->condvar); 533 536 break; 534 537 case RTM_NEWROUTE: … … 561 564 static void address_enumerator_destroy(address_enumerator_t *data) 562 565 { 563 pthread_mutex_unlock(&data->this->mutex);566 data->this->mutex->unlock(data->this->mutex); 564 567 free(data); 565 568 } … … 615 618 data->include_virtual_ips = include_virtual_ips; 616 619 617 pthread_mutex_lock(&this->mutex);620 this->mutex->lock(this->mutex); 618 621 return enumerator_create_nested( 619 622 enumerator_create_filter(this->ifaces->create_enumerator(this->ifaces), … … 634 637 DBG2(DBG_KNL, "getting interface name for %H", ip); 635 638 636 pthread_mutex_lock(&this->mutex);639 this->mutex->lock(this->mutex); 637 640 ifaces = this->ifaces->create_enumerator(this->ifaces); 638 641 while (ifaces->enumerate(ifaces, &iface)) … … 654 657 } 655 658 ifaces->destroy(ifaces); 656 pthread_mutex_unlock(&this->mutex);659 this->mutex->unlock(this->mutex); 657 660 658 661 if (name) … … 678 681 DBG2(DBG_KNL, "getting iface index for %s", name); 679 682 680 pthread_mutex_lock(&this->mutex);683 this->mutex->lock(this->mutex); 681 684 ifaces = this->ifaces->create_enumerator(this->ifaces); 682 685 while (ifaces->enumerate(ifaces, &iface)) … … 689 692 } 690 693 ifaces->destroy(ifaces); 691 pthread_mutex_unlock(&this->mutex);694 this->mutex->unlock(this->mutex); 692 695 693 696 if (ifindex == 0) … … 770 773 return NULL; 771 774 } 775 this->mutex->lock(this->mutex); 772 776 current = out; 773 777 while (NLMSG_OK(current, len)) … … 847 851 { 848 852 /* no source addr, get one from the interfaces */ 849 pthread_mutex_lock(&this->mutex);850 853 ifaces = this->ifaces->create_enumerator(this->ifaces); 851 854 while (ifaces->enumerate(ifaces, &iface)) … … 871 874 } 872 875 ifaces->destroy(ifaces); 873 pthread_mutex_unlock(&this->mutex);874 876 } 875 877 } … … 883 885 } 884 886 free(out); 887 this->mutex->unlock(this->mutex); 885 888 886 889 if (nexthop) … … 958 961 DBG2(DBG_KNL, "adding virtual IP %H", virtual_ip); 959 962 960 pthread_mutex_lock(&this->mutex);963 this->mutex->lock(this->mutex); 961 964 ifaces = this->ifaces->create_enumerator(this->ifaces); 962 965 while (ifaces->enumerate(ifaces, &iface)) … … 978 981 addrs->destroy(addrs); 979 982 ifaces->destroy(ifaces); 980 pthread_mutex_unlock(&this->mutex);983 this->mutex->unlock(this->mutex); 981 984 return SUCCESS; 982 985 } … … 999 1002 while (get_vip_refcount(this, virtual_ip) == 0) 1000 1003 { /* wait until address appears */ 1001 pthread_cond_wait(&this->cond, &this->mutex);1004 this->condvar->wait(this->condvar, this->mutex); 1002 1005 } 1003 1006 ifaces->destroy(ifaces); 1004 pthread_mutex_unlock(&this->mutex);1007 this->mutex->unlock(this->mutex); 1005 1008 return SUCCESS; 1006 1009 } 1007 1010 ifaces->destroy(ifaces); 1008 pthread_mutex_unlock(&this->mutex);1011 this->mutex->unlock(this->mutex); 1009 1012 DBG1(DBG_KNL, "adding virtual IP %H failed", virtual_ip); 1010 1013 return FAILED; … … 1012 1015 } 1013 1016 ifaces->destroy(ifaces); 1014 pthread_mutex_unlock(&this->mutex);1017 this->mutex->unlock(this->mutex); 1015 1018 1016 1019 DBG1(DBG_KNL, "interface address %H not found, unable to install" … … 1032 1035 DBG2(DBG_KNL, "deleting virtual IP %H", virtual_ip); 1033 1036 1034 pthread_mutex_lock(&this->mutex);1037 this->mutex->lock(this->mutex); 1035 1038 ifaces = this->ifaces->create_enumerator(this->ifaces); 1036 1039 while (ifaces->enumerate(ifaces, &iface)) … … 1050 1053 while (get_vip_refcount(this, virtual_ip) > 0) 1051 1054 { 1052 pthread_cond_wait(&this->cond, &this->mutex);1055 this->condvar->wait(this->condvar, this->mutex); 1053 1056 } 1054 1057 } 1055 1058 addrs->destroy(addrs); 1056 1059 ifaces->destroy(ifaces); 1057 pthread_mutex_unlock(&this->mutex);1060 this->mutex->unlock(this->mutex); 1058 1061 return status; 1059 1062 } … … 1066 1069 addrs->destroy(addrs); 1067 1070 ifaces->destroy(ifaces); 1068 pthread_mutex_unlock(&this->mutex);1071 this->mutex->unlock(this->mutex); 1069 1072 return SUCCESS; 1070 1073 } … … 1073 1076 } 1074 1077 ifaces->destroy(ifaces); 1075 pthread_mutex_unlock(&this->mutex);1078 this->mutex->unlock(this->mutex); 1076 1079 1077 1080 DBG2(DBG_KNL, "virtual IP %H not cached, unable to delete", virtual_ip); … … 1233 1236 free(out); 1234 1237 1235 pthread_mutex_lock(&this->mutex);1238 this->mutex->lock(this->mutex); 1236 1239 ifaces = this->ifaces->create_enumerator(this->ifaces); 1237 1240 while (ifaces->enumerate(ifaces, &iface)) … … 1249 1252 } 1250 1253 ifaces->destroy(ifaces); 1251 pthread_mutex_unlock(&this->mutex);1254 this->mutex->unlock(this->mutex); 1252 1255 return SUCCESS; 1253 1256 } … … 1302 1305 this->socket->destroy(this->socket); 1303 1306 this->ifaces->destroy_function(this->ifaces, (void*)iface_entry_destroy); 1307 this->condvar->destroy(this->condvar); 1308 this->mutex->destroy(this->mutex); 1304 1309 free(this); 1305 1310 } … … 1326 1331 /* private members */ 1327 1332 this->ifaces = linked_list_create(); 1328 pthread_mutex_init(&this->mutex, NULL);1329 pthread_cond_init(&this->cond, NULL);1333 this->mutex = mutex_create(MUTEX_DEFAULT); 1334 this->condvar = condvar_create(CONDVAR_DEFAULT); 1330 1335 timerclear(&this->last_roam); 1331 1336 this->routing_table = lib->settings->get_int(lib->settings, trunk/src/charon/plugins/kernel_netlink/kernel_netlink_shared.c
r4576 r4579 21 21 #include <errno.h> 22 22 #include <unistd.h> 23 #include <pthread.h>24 23 25 24 #include "kernel_netlink_shared.h" 26 25 27 26 #include <daemon.h> 27 #include <utils/mutex.h> 28 28 29 29 typedef struct private_netlink_socket_t private_netlink_socket_t; … … 41 41 * mutex to lock access to netlink socket 42 42 */ 43 pthread_mutex_tmutex;43 mutex_t *mutex; 44 44 45 45 /** … … 65 65 struct nlmsghdr *msg, peek; 66 66 67 pthread_mutex_lock(&this->mutex);67 this->mutex->lock(this->mutex); 68 68 69 69 in->nlmsg_seq = ++this->seq; … … 87 87 continue; 88 88 } 89 pthread_mutex_unlock(&this->mutex);89 this->mutex->unlock(this->mutex); 90 90 DBG1(DBG_KNL, "error sending to netlink socket: %s", strerror(errno)); 91 91 return FAILED; … … 119 119 } 120 120 DBG1(DBG_KNL, "error reading from netlink socket: %s", strerror(errno)); 121 pthread_mutex_unlock(&this->mutex);121 this->mutex->unlock(this->mutex); 122 122 free(result.ptr); 123 123 return FAILED; … … 126 126 { 127 127 DBG1(DBG_KNL, "received corrupted netlink message"); 128 pthread_mutex_unlock(&this->mutex);128 this->mutex->unlock(this->mutex); 129 129 free(result.ptr); 130 130 return FAILED; … … 137 137 continue; 138 138 } 139 pthread_mutex_unlock(&this->mutex);139 this->mutex->unlock(this->mutex); 140 140 free(result.ptr); 141 141 return FAILED; … … 163 163 *out = (struct nlmsghdr*)result.ptr; 164 164 165 pthread_mutex_unlock(&this->mutex);165 this->mutex->unlock(this->mutex); 166 166 167 167 return SUCCESS; … … 223 223 { 224 224 close(this->socket); 225 this->mutex->destroy(this->mutex); 225 226 free(this); 226 227 } … … 240 241 /* private members */ 241 242 this->seq = 200; 242 pthread_mutex_init(&this->mutex, NULL);243 this->mutex = mutex_create(MUTEX_DEFAULT); 243 244 244 245 memset(&addr, 0, sizeof(addr)); trunk/src/charon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c
r4561 r4579 31 31 #include <daemon.h> 32 32 #include <utils/host.h> 33 #include <utils/mutex.h> 33 34 #include <processing/jobs/callback_job.h> 34 35 #include <processing/jobs/acquire_job.h> … … 84 85 * mutex to lock access to various lists 85 86 */ 86 pthread_mutex_tmutex;87 mutex_t *mutex; 87 88 88 89 /** … … 104 105 * mutex to lock access to the PF_KEY socket 105 106 */ 106 pthread_mutex_t mutex_pfkey; 107 107 mutex_t *mutex_pfkey; 108 108 109 109 /** … … 112 112 int socket; 113 113 114 115 114 /** 116 115 * PF_KEY socket to receive acquire and expire events 117 116 */ 118 117 int socket_events; 119 120 118 121 119 /** … … 636 634 int in_len, len; 637 635 638 pthread_mutex_lock(&this->mutex_pfkey);636 this->mutex_pfkey->lock(this->mutex_pfkey); 639 637 640 638 in->sadb_msg_seq = ++this->seq; … … 654 652 continue; 655 653 } 656 pthread_mutex_unlock(&this->mutex_pfkey);654 this->mutex_pfkey->unlock(this->mutex_pfkey); 657 655 DBG1(DBG_KNL, "error sending to PF_KEY socket: %s", strerror(errno)); 658 656 return FAILED; … … 676 674 } 677 675 DBG1(DBG_KNL, "error reading from PF_KEY socket: %s", strerror(errno)); 678 pthread_mutex_unlock(&this->mutex_pfkey);676 this->mutex_pfkey->unlock(this->mutex_pfkey); 679 677 return FAILED; 680 678 } … … 683 681 { 684 682 DBG1(DBG_KNL, "received corrupted PF_KEY message"); 685 pthread_mutex_unlock(&this->mutex_pfkey);683 this->mutex_pfkey->unlock(this->mutex_pfkey); 686 684 return FAILED; 687 685 } … … 689 687 { 690 688 DBG1(DBG_KNL, "buffer was too small to receive the complete PF_KEY message"); 691 pthread_mutex_unlock(&this->mutex_pfkey);689 this->mutex_pfkey->unlock(this->mutex_pfkey); 692 690 return FAILED; 693 691 } … … 705 703 continue; 706 704 } 707 pthread_mutex_unlock(&this->mutex_pfkey);705 this->mutex_pfkey->unlock(this->mutex_pfkey); 708 706 return FAILED; 709 707 } … … 721 719 memcpy(*out, buf, len); 722 720 723 pthread_mutex_unlock(&this->mutex_pfkey);721 this->mutex_pfkey->unlock(this->mutex_pfkey); 724 722 725 723 return SUCCESS; … … 765 763 766 764 index = response.x_policy->sadb_x_policy_id; 767 pthread_mutex_lock(&this->mutex);765 this->mutex->lock(this->mutex); 768 766 if (this->policies->find_first(this->policies, 769 767 (linked_list_match_t)policy_entry_match_byindex, (void**)&policy, &index) == SUCCESS) … … 778 776 src_ts = sadb_address2ts(response.src); 779 777 dst_ts = sadb_address2ts(response.dst); 780 pthread_mutex_unlock(&this->mutex);778 this->mutex->unlock(this->mutex); 781 779 782 780 DBG1(DBG_KNL, "creating acquire job for policy %R === %R with reqid {%u}", … … 1429 1427 1430 1428 /* find a matching policy */ 1431 pthread_mutex_lock(&this->mutex);1429 this->mutex->lock(this->mutex); 1432 1430 if (this->policies->find_first(this->policies, 1433 1431 (linked_list_match_t)policy_entry_equals, (void**)&found, policy) == SUCCESS) … … 1508 1506 PFKEY_EXT_ADD(msg, addr); 1509 1507 1510 pthread_mutex_unlock(&this->mutex);1508 this->mutex->unlock(this->mutex); 1511 1509 1512 1510 if (pfkey_send(this, msg, &out, &len) != SUCCESS) … … 1532 1530 } 1533 1531 1534 pthread_mutex_lock(&this->mutex);1532 this->mutex->lock(this->mutex); 1535 1533 1536 1534 /* we try to find the policy again and update the kernel index */ … … 1539 1537 DBG2(DBG_KNL, "unable to update index, the policy %R === %R %N is " 1540 1538 "already gone, ignoring", src_ts, dst_ts, policy_dir_names, direction); 1541 pthread_mutex_unlock(&this->mutex);1539 this->mutex->unlock(this->mutex); 1542 1540 free(out); 1543 1541 return SUCCESS; … … 1594 1592 } 1595 1593 1596 pthread_mutex_unlock(&this->mutex);1594 this->mutex->unlock(this->mutex); 1597 1595 1598 1596 return SUCCESS; … … 1622 1620 1623 1621 /* find a matching policy */ 1624 pthread_mutex_lock(&this->mutex);1622 this->mutex->lock(this->mutex); 1625 1623 if (this->policies->find_first(this->policies, 1626 1624 (linked_list_match_t)policy_entry_equals, (void**)&found, policy) != SUCCESS) … … 1629 1627 dst_ts, policy_dir_names, direction); 1630 1628 policy_entry_destroy(policy); 1631 pthread_mutex_unlock(&this->mutex);1629 this->mutex->unlock(this->mutex); 1632 1630 return NOT_FOUND; 1633 1631 } … … 1665 1663 PFKEY_EXT_ADD(msg, addr); 1666 1664 1667 pthread_mutex_unlock(&this->mutex);1665 this->mutex->unlock(this->mutex); 1668 1666 1669 1667 if (pfkey_send(this, msg, &out, &len) != SUCCESS) … … 1719 1717 1720 1718 /* find a matching policy */ 1721 pthread_mutex_lock(&this->mutex);1719 this->mutex->lock(this->mutex); 1722 1720 if (this->policies->find_first(this->policies, 1723 1721 (linked_list_match_t)policy_entry_equals, (void**)&found, policy) == SUCCESS) … … 1728 1726 DBG2(DBG_KNL, "policy still used by another CHILD_SA, not removed"); 1729 1727 policy_entry_destroy(policy); 1730 pthread_mutex_unlock(&this->mutex);1728 this->mutex->unlock(this->mutex); 1731 1729 return SUCCESS; 1732 1730 } … … 1741 1739 dst_ts, policy_dir_names, direction); 1742 1740 policy_entry_destroy(policy); 1743 pthread_mutex_unlock(&this->mutex);1741 this->mutex->unlock(this->mutex); 1744 1742 return NOT_FOUND; 1745 1743 } 1746 pthread_mutex_unlock(&this->mutex);1744 this->mutex->unlock(this->mutex); 1747 1745 1748 1746 memset(&request, 0, sizeof(request)); … … 1853 1851 close(this->socket_events); 1854 1852 this->policies->destroy_function(this->policies, (void*)policy_entry_destroy); 1853 this->mutex->destroy(this->mutex); 1854 this->mutex_pfkey->destroy(this->mutex_pfkey); 1855 1855 free(this); 1856 1856 } … … 1877 1877 /* private members */ 1878 1878 this->policies = linked_list_create(); 1879 pthread_mutex_init(&this->mutex, NULL); 1880 this->install_routes = lib->settings->get_bool(lib->settings, "charon.install_routes", TRUE); 1881 pthread_mutex_init(&this->mutex_pfkey, NULL); 1879 this->mutex = mutex_create(MUTEX_DEFAULT); 1880 this->mutex_pfkey = mutex_create(MUTEX_DEFAULT); 1881 this->install_routes = lib->settings->get_bool(lib->settings, 1882 "charon.install_routes", TRUE); 1882 1883 this->seq = 0; 1883 1884 trunk/src/charon/processing/jobs/callback_job.c
r4576 r4579 21 21 22 22 #include <daemon.h> 23 #include <utils/mutex.h> 23 24 24 25 typedef struct private_callback_job_t private_callback_job_t; … … 52 53 */ 53 54 pthread_t thread; 54 55 55 56 /** 56 57 * mutex to access jobs interna 57 58 */ 58 pthread_mutex_tmutex;59 59 mutex_t *mutex; 60 60 61 /** 61 62 * list of asociated child jobs … … 79 80 } 80 81 this->children->destroy(this->children); 82 this->mutex->destroy(this->mutex); 81 83 free(this); 82 84 } … … 92 94 private_callback_job_t *child; 93 95 94 pthread_mutex_lock(&this->parent->mutex);96 this->parent->mutex->lock(this->parent->mutex); 95 97 iterator = this->parent->children->create_iterator(this->parent->children, TRUE); 96 98 while (iterator->iterate(iterator, (void**)&child)) … … 103 105 } 104 106 iterator->destroy(iterator); 105 pthread_mutex_unlock(&this->parent->mutex);107 this->parent->mutex->unlock(this->parent->mutex); 106 108 } 107 109 } … … 114 116 pthread_t thread; 115 117 116 pthread_mutex_lock(&this->mutex);118 this->mutex->lock(this->mutex); 117 119 thread = this->thread; 118 120 119 121 /* terminate its children */ 120 122 this->children->invoke_offset(this->children, offsetof(callback_job_t, cancel)); 121 pthread_mutex_unlock(&this->mutex);123 this->mutex->unlock(this->mutex); 122 124 123 125 /* terminate thread */ … … 136 138 bool cleanup = FALSE; 137 139 138 pthread_mutex_lock(&this->mutex);140 this->mutex->lock(this->mutex); 139 141 this->thread = pthread_self(); 140 pthread_mutex_unlock(&this->mutex);142 this->mutex->unlock(this->mutex); 141 143 142 144 pthread_cleanup_push((void*)destroy, this); … … 183 185 184 186 /* private variables */ 185 pthread_mutex_init(&this->mutex, NULL);187 this->mutex = mutex_create(MUTEX_DEFAULT); 186 188 this->callback = cb; 187 189 this->data = data; … … 194 196 if (parent) 195 197 { 196 pthread_mutex_lock(&this->parent->mutex);198 this->parent->mutex->lock(this->parent->mutex); 197 199 this->parent->children->insert_last(this->parent->children, this); 198 pthread_mutex_unlock(&this->parent->mutex);200 this->parent->mutex->unlock(this->parent->mutex); 199 201 } 200 202 trunk/src/charon/processing/processor.c
r3742 r4579 25 25 26 26 #include <daemon.h> 27 #include <utils/mutex.h> 27 28 #include <utils/linked_list.h> 28 29 … … 62 63 * access to linked_list is locked through this mutex 63 64 */ 64 pthread_mutex_tmutex;65 mutex_t *mutex; 65 66 66 67 /** 67 68 * Condvar to wait for new jobs 68 69 */ 69 pthread_cond_t jobadded;70 condvar_t *job_added; 70 71 71 72 /** 72 73 * Condvar to wait for terminated threads 73 74 */ 74 pthread_cond_t threadterminated;75 condvar_t *thread_terminated; 75 76 }; 76 77 … … 86 87 if (pthread_create(&thread, NULL, (void*)process_jobs, this) != 0) 87 88 { 88 pthread_mutex_lock(&this->mutex);89 this->mutex->lock(this->mutex); 89 90 this->total_threads--; 90 pthread_cond_broadcast(&this->threadterminated);91 pthread_mutex_unlock(&this->mutex);91 this->thread_terminated->broadcast(this->thread_terminated); 92 this->mutex->unlock(this->mutex); 92 93 } 93 94 } … … 104 105 DBG2(DBG_JOB, "started worker thread, thread_ID: %06u", (int)pthread_self()); 105 106 106 pthread_mutex_lock(&this->mutex);107 this->mutex->lock(this->mutex); 107 108 while (this->desired_threads >= this->total_threads) 108 109 { … … 112 113 { 113 114 this->idle_threads++; 114 pthread_cond_wait(&this->jobadded, &this->mutex);115 this->job_added->wait(this->job_added, this->mutex); 115 116 this->idle_threads--; 116 117 continue; 117 118 } 118 119 this->list->remove_first(this->list, (void**)&job); 119 pthread_mutex_unlock(&this->mutex);120 this->mutex->unlock(this->mutex); 120 121 /* terminated threads are restarted, so we have a constant pool */ 121 122 pthread_cleanup_push((void*)restart, this); 122 123 job->execute(job); 123 124 pthread_cleanup_pop(0); 124 pthread_mutex_lock(&this->mutex);125 this->mutex->lock(this->mutex); 125 126 } 126 127 this->total_threads--; 127 pthread_cond_signal(&this->threadterminated);128 pthread_mutex_unlock(&this->mutex);128 this->thread_terminated->signal(this->thread_terminated); 129 this
