]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Separated the public interfaces of the threading primitives.
authorTobias Brunner <tobias@strongswan.org>
Tue, 8 Dec 2009 15:53:01 +0000 (16:53 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 23 Dec 2009 16:01:53 +0000 (17:01 +0100)
50 files changed:
src/charon/bus/bus.c
src/charon/config/backend_manager.c
src/charon/config/peer_cfg.c
src/charon/credentials/credential_manager.c
src/charon/credentials/sets/cert_cache.c
src/charon/network/sender.c
src/charon/plugins/eap_radius/radius_client.c
src/charon/plugins/eap_sim_file/eap_sim_file_triplets.c
src/charon/plugins/kernel_klips/kernel_klips_ipsec.c
src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c
src/charon/plugins/kernel_netlink/kernel_netlink_net.c
src/charon/plugins/kernel_netlink/kernel_netlink_shared.c
src/charon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c
src/charon/plugins/kernel_pfroute/kernel_pfroute_net.c
src/charon/plugins/load_tester/load_tester_plugin.c
src/charon/plugins/nm/nm_creds.c
src/charon/plugins/resolve/resolve_handler.c
src/charon/plugins/stroke/stroke_attribute.c
src/charon/plugins/stroke/stroke_ca.c
src/charon/plugins/stroke/stroke_config.c
src/charon/plugins/stroke/stroke_cred.c
src/charon/plugins/stroke/stroke_socket.c
src/charon/plugins/unit_tester/tests/test_mutex.c
src/charon/processing/jobs/callback_job.c
src/charon/processing/processor.c
src/charon/processing/scheduler.c
src/charon/sa/authenticators/eap/eap_manager.c
src/charon/sa/connect_manager.c
src/charon/sa/ike_sa_manager.c
src/charon/sa/mediation_manager.c
src/charon/sa/trap_manager.c
src/libfast/dispatcher.c
src/libstrongswan/Makefile.am
src/libstrongswan/attributes/attribute_manager.c
src/libstrongswan/credentials/credential_factory.c
src/libstrongswan/credentials/keys/key_encoding.c
src/libstrongswan/crypto/crypto_factory.c
src/libstrongswan/database/database_factory.c
src/libstrongswan/fetcher/fetcher_manager.c
src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c
src/libstrongswan/plugins/mysql/mysql_database.c
src/libstrongswan/plugins/openssl/openssl_plugin.c
src/libstrongswan/plugins/sqlite/sqlite_database.c
src/libstrongswan/threading.h [deleted file]
src/libstrongswan/threading/condvar.c
src/libstrongswan/threading/condvar.h
src/libstrongswan/threading/mutex.c
src/libstrongswan/threading/mutex.h
src/libstrongswan/threading/rwlock.c
src/libstrongswan/threading/rwlock.h

index c2184234ba54f085e232a563cc2c739c8561c88d..d77797e92000d6ea51cdaf1dc5d7d1c089620911 100644 (file)
@@ -19,7 +19,7 @@
 #include <stdint.h>
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 ENUM(debug_names, DBG_DMN, DBG_LIB,
        "DMN",
index dabae342cee266c713042a72e0b73fde5735848d..938927cd4786a585811bc07d308592c5b88d69ad 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <daemon.h>
 #include <utils/linked_list.h>
-#include <threading.h>
+#include <threading/rwlock.h>
 
 
 typedef struct private_backend_manager_t private_backend_manager_t;
index cf5d00621da59b613177e1092384df03e13d6d95..9df14c9ae42198d5b89b8afcde8ba52600dbf494 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <daemon.h>
 
-#include <threading.h>
+#include <threading/mutex.h>
 #include <utils/linked_list.h>
 #include <utils/identification.h>
 
index 36d634c03671bdc34ca452b556c93d72837f56ae..1e851779c5aef5bb01c2f74829be07021fcddceb 100644 (file)
@@ -18,7 +18,7 @@
 #include "credential_manager.h"
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/rwlock.h>
 #include <utils/linked_list.h>
 #include <credentials/sets/cert_cache.h>
 #include <credentials/sets/auth_cfg_wrapper.h>
@@ -1140,7 +1140,7 @@ static bool verify_trust_chain(private_credential_manager_t *this,
                        {
                                auth->add(auth, AUTH_RULE_CA_CERT, issuer->get_ref(issuer));
                                DBG1(DBG_CFG, "  using trusted ca certificate \"%Y\"",
-                                                         issuer->get_subject(issuer));
+                                                         issuer->get_subject(issuer));
                                trusted = TRUE;
                        }
                        else
index 037f102fd7755b2bf14152f67d7464df567373dc..176accce22a94932e4c37ce207b02738f4ab758e 100644 (file)
@@ -19,7 +19,7 @@
 #include <sched.h>
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/rwlock.h>
 #include <utils/linked_list.h>
 
 /** cache size, a power of 2 for fast modulo */
index dc7b0624e608937198c4f84c57ff75eee1092e07..c644f1d4133932bef053566a9bf76e1d37417c19 100644 (file)
@@ -22,7 +22,7 @@
 #include <daemon.h>
 #include <network/socket.h>
 #include <processing/jobs/callback_job.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 
 typedef struct private_sender_t private_sender_t;
index 5d4779c65124e4a9b09fe935e85ef3fa4bbe5e34..e6d68c920a5b348656ddfeb7d69f76480e9ed959 100644 (file)
@@ -21,7 +21,7 @@
 #include <daemon.h>
 #include <utils/host.h>
 #include <utils/linked_list.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 /**
  * Default RADIUS server port, when not configured
index cda0c0ff4b2a98dabb725accd1adafe7c9f783c5..6b7d99fb7fb33d93c58c2afe1732b27db09240bb 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <daemon.h>
 #include <utils/linked_list.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 typedef struct private_eap_sim_file_triplets_t private_eap_sim_file_triplets_t;
 
index dfa79f4d7aef9fe2f5e9e41e5684b3a84c3fd8b7..29a77de8ba32d14410b1f99eb1ade8a960f352de 100644 (file)
@@ -30,7 +30,7 @@
 #include "kernel_klips_ipsec.h"
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/mutex.h>
 #include <processing/jobs/callback_job.h>
 #include <processing/jobs/acquire_job.h>
 #include <processing/jobs/rekey_child_sa_job.h>
index 691bab791890a276adb7518bff1f358bdab73738..c7f005a32c662a82a9ad81017912df0fe2ddee03 100644 (file)
@@ -36,7 +36,7 @@
 #include "kernel_netlink_shared.h"
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/mutex.h>
 #include <utils/hashtable.h>
 #include <processing/jobs/callback_job.h>
 #include <processing/jobs/acquire_job.h>
index 67e7c820f41126dc44065fb0f81ad65de8a45812..4447dc0966f75966f260dedc846911d4b1d9bc8d 100644 (file)
@@ -26,7 +26,7 @@
 #include "kernel_netlink_shared.h"
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/mutex.h>
 #include <utils/linked_list.h>
 #include <processing/jobs/callback_job.h>
 #include <processing/jobs/roam_job.h>
index e4bdbb1c5271c7786dbc4eb820cd77d5f34b3cef..b96186a3ab6e6a32efa4a90985bf4288ff5d2aca 100644 (file)
@@ -22,7 +22,7 @@
 #include "kernel_netlink_shared.h"
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 typedef struct private_netlink_socket_t private_netlink_socket_t;
 
index 98f7a57927f2b2e6601ec95a4949ebad91bc0334..8dc03b80b5a019c257d1cdcbf39646bce871aa05 100644 (file)
@@ -56,7 +56,7 @@
 
 #include <daemon.h>
 #include <utils/host.h>
-#include <threading.h>
+#include <threading/mutex.h>
 #include <processing/jobs/callback_job.h>
 #include <processing/jobs/acquire_job.h>
 #include <processing/jobs/migrate_job.h>
index 814fbad832b45420a46d6c203e97f73446ec06b3..9aee5392806c711d0722328cb9b689d6317dab5b 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <daemon.h>
 #include <utils/host.h>
-#include <threading.h>
+#include <threading/mutex.h>
 #include <utils/linked_list.h>
 #include <processing/jobs/callback_job.h>
 #include <processing/jobs/roam_job.h>
index de721e05d806f98f612e8ec0ec30d03151093535..9c6cc99745fdfa0be8d31561ff44622831dc0ba5 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <daemon.h>
 #include <processing/jobs/callback_job.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 typedef struct private_load_tester_plugin_t private_load_tester_plugin_t;
 
index 68ef61fce549f14f801c13353fef5f7985bf1bc1..193838e6b1d79a0f4f51a2941b8aa35420d5e0c0 100644 (file)
@@ -20,7 +20,7 @@
 #include <unistd.h>
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/rwlock.h>
 #include <credentials/certificates/x509.h>
 
 typedef struct private_nm_creds_t private_nm_creds_t;
index 7f7e0247413ecca8b63e731d024682dcfd5d405a..714c751a643ee97e59dde07eb1260ec35d6bde24 100644 (file)
@@ -18,7 +18,7 @@
 #include <unistd.h>
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 typedef struct private_resolve_handler_t private_resolve_handler_t;
 
index d013528231397f9ab104f06e198585e110852554..7a5ce683e9f07622855261eec9d6490c4648d78c 100644 (file)
@@ -18,7 +18,7 @@
 #include <daemon.h>
 #include <utils/linked_list.h>
 #include <utils/hashtable.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 #define POOL_LIMIT (sizeof(uintptr_t)*8)
 
index ebcd9ac3be95a034efd8386c6aba8ca2b23269a2..49146f18bdaff2fc714a4712e36587846972bd0b 100644 (file)
@@ -17,7 +17,7 @@
 #include "stroke_ca.h"
 #include "stroke_cred.h"
 
-#include <threading.h>
+#include <threading/rwlock.h>
 #include <utils/linked_list.h>
 #include <crypto/hashers/hasher.h>
 
index c03349ac962a57fd1752fcea26a5c649aec1a917..1f585f72b6af9d7caa3cc68e1eadc8aaf27f7215 100644 (file)
@@ -16,7 +16,7 @@
 #include "stroke_config.h"
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/mutex.h>
 #include <utils/lexparser.h>
 
 typedef struct private_stroke_config_t private_stroke_config_t;
index 91830985a92e44cf2066539ddfd11725243bee5d..bc0b2f6fcee31483ac4cf33b78ef35563467c8f4 100644 (file)
@@ -27,7 +27,7 @@
 #include <credentials/certificates/ac.h>
 #include <utils/linked_list.h>
 #include <utils/lexparser.h>
-#include <threading.h>
+#include <threading/rwlock.h>
 #include <daemon.h>
 
 /* configuration directories and files */
index f834f8e158519d491ee1fac94091a98c03eee129..6a599992e56e56497139b3884254ec6d7487d6e6 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <processing/jobs/callback_job.h>
 #include <daemon.h>
-#include <threading.h> /* for Mac OS X compatible accept */
+#include <threading/mutex.h> /* for Mac OS X compatible accept */
 
 #include "stroke_config.h"
 #include "stroke_control.h"
index 900b652157c39aa202c6b25b6c4ae21d5c4fa61a..77085cb2f1108871f6a911723a9dcd817383512c 100644 (file)
@@ -14,7 +14,7 @@
  */
 
 #include <library.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 #include <unistd.h>
 #include <sched.h>
index e4299af6b67e0cf6d0ebf8323fe3e317eccb9fa2..145481c0beadea8533f9721d6403e22ffaeae3e9 100644 (file)
@@ -18,7 +18,7 @@
 #include <pthread.h>
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 typedef struct private_callback_job_t private_callback_job_t;
 
index 248bba1453619739e59f7d842ea0fb627cb63944..620c01c9c906828170b32f25d3633fdbdea4a9e3 100644 (file)
@@ -22,7 +22,7 @@
 #include "processor.h"
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/mutex.h>
 #include <utils/linked_list.h>
 
 
index 36ccb14683acce30d35aa4e7f6b3ac7b854ceb7c..69c54900c8d3d2515e78ef52f9f68c59c18030ae 100644 (file)
@@ -23,7 +23,7 @@
 #include <daemon.h>
 #include <processing/processor.h>
 #include <processing/jobs/callback_job.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 /* the initial size of the heap */
 #define HEAP_SIZE_DEFAULT 64
index 3738cb948551426f431593b28add6ef258817017..f795183f083f1c535d335532bf3de21db7bb8a23 100644 (file)
@@ -16,7 +16,7 @@
 #include "eap_manager.h"
 
 #include <utils/linked_list.h>
-#include <threading.h>
+#include <threading/rwlock.h>
 
 typedef struct private_eap_manager_t private_eap_manager_t;
 typedef struct eap_entry_t eap_entry_t;
index e26c6c60c7e9965a68c9bccfd0df2cfaba783e5d..b78ba070d10c127ff3c05d1ae67376c5037652c5 100644 (file)
@@ -18,7 +18,7 @@
 #include <math.h>
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/mutex.h>
 #include <utils/linked_list.h>
 #include <crypto/hashers/hasher.h>
 
index bb8a4e0ab9b8d15804494fccf5b0d84535f7ccef..6eb9d14bb79153c716731bc3fb142b49e5f8e488 100644 (file)
@@ -22,7 +22,8 @@
 #include <daemon.h>
 #include <sa/ike_sa_id.h>
 #include <bus/bus.h>
-#include <threading.h>
+#include <threading/mutex.h>
+#include <threading/rwlock.h>
 #include <utils/linked_list.h>
 #include <crypto/hashers/hasher.h>
 
index 5161a71477bb3686c61a2757b9979baa5efb54e5..035f49053b73e0ea986022b0dbdaf499bd5f7ae1 100644 (file)
@@ -16,7 +16,7 @@
 #include "mediation_manager.h"
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/mutex.h>
 #include <utils/linked_list.h>
 #include <processing/jobs/mediation_job.h>
 
index edcba3a8b9940475ec88ade60ad8178aa8ced0e6..ed758995a485afcd64dbb0e679b803cb92bec746 100644 (file)
@@ -16,7 +16,7 @@
 #include "trap_manager.h"
 
 #include <daemon.h>
-#include <threading.h>
+#include <threading/rwlock.h>
 #include <utils/linked_list.h>
 
 
index a4d23bf7b6207ff371d295fa2f0d44ee2d094b04..05c11224bc7e98e171f42f0fdc4f93b4e35b26c5 100644 (file)
@@ -24,7 +24,7 @@
 #include <unistd.h>
 
 #include <debug.h>
-#include <threading.h>
+#include <threading/mutex.h>
 #include <utils/linked_list.h>
 #include <utils/hashtable.h>
 
index bdb6cdadc75d08642155c536484551e326034e95..d708eb93319d99e6f4c4963b599cc59b8cc4d681 100644 (file)
@@ -43,7 +43,6 @@ credentials/ietf_attributes/ietf_attributes.c credentials/ietf_attributes/ietf_a
 database/database.h database/database_factory.h database/database_factory.c \
 fetcher/fetcher.h fetcher/fetcher_manager.h fetcher/fetcher_manager.c \
 selectors/traffic_selector.c selectors/traffic_selector.h \
-threading.h \
 threading/mutex.h threading/mutex.c \
 threading/condvar.h threading/condvar.c \
 threading/rwlock.h threading/rwlock.c \
index 4b0c5092145343d138974fb8bab712b55941a18e..91fa1ebb558a4504ab958622c4f6b217ed825bcc 100644 (file)
@@ -17,7 +17,7 @@
 
 #include <debug.h>
 #include <utils/linked_list.h>
-#include <threading.h>
+#include <threading/rwlock.h>
 
 typedef struct private_attribute_manager_t private_attribute_manager_t;
 
index 7e94b9d14baf7d83e58bde1d7c4482c76df22282..ff2393f69bf4ff6dd58599d84594961609b3db8d 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <debug.h>
 #include <utils/linked_list.h>
-#include <threading.h>
+#include <threading/rwlock.h>
 #include <credentials/certificates/x509.h>
 
 ENUM(credential_type_names, CRED_PRIVATE_KEY, CRED_CERTIFICATE,
index b9bd89f606461edbb352c405e8c1fa086c3b14e2..89b25226c30bd42c19f79184a49c0f4d21714e09 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <utils/linked_list.h>
 #include <utils/hashtable.h>
-#include <threading.h>
+#include <threading/rwlock.h>
 
 typedef struct private_key_encoding_t private_key_encoding_t;
 
index 2181086466babd6dd4abdf7f3e65f62c2b21d865..46b50329d8b68ea5122950f5364ae03e904513c5 100644 (file)
@@ -16,7 +16,7 @@
 #include "crypto_factory.h"
 
 #include <debug.h>
-#include <threading.h>
+#include <threading/rwlock.h>
 #include <utils/linked_list.h>
 #include <crypto/crypto_tester.h>
 
index a0f50c80c1405e4de920059f4920e86265e47e86..3936565a1134a78dd44fc565c54c6f99939eb4ef 100644 (file)
@@ -16,7 +16,7 @@
 #include "database_factory.h"
 
 #include <utils/linked_list.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 typedef struct private_database_factory_t private_database_factory_t;
 
index fd3b0eef9ac018e5958628de02c6c62c6d2ae418..b73bfacf6578c729ed48bfa5e8b77cf71a28db59 100644 (file)
@@ -16,7 +16,7 @@
 #include "fetcher_manager.h"
 
 #include <debug.h>
-#include <threading.h>
+#include <threading/rwlock.h>
 #include <utils/linked_list.h>
 
 typedef struct private_fetcher_manager_t private_fetcher_manager_t;
index 66481da3892d843e634dedfd464a208c6c5944f3..8c9ea893b2b6038d8c995442a6aadba01b703c32 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <library.h>
 #include <debug.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 #include <errno.h>
 #include <gcrypt.h>
index f01321fb55c2ed1b2d40915368e4a85e6d2579e6..6c2a25b50e03b8a7cd2634a93a69f04d32a99e4c 100644 (file)
@@ -21,7 +21,7 @@
 #include "mysql_database.h"
 
 #include <debug.h>
-#include <threading.h>
+#include <threading/mutex.h>
 #include <utils/linked_list.h>
 
 /* Older mysql.h headers do not define it, but we need it. It is not returned
index 0cb526d8917d31c3042f1cf2c5e0a04c0c32d2b9..46446fc2572bf07eaf97c5053c7094555831ca36 100644 (file)
@@ -23,7 +23,7 @@
 #include "openssl_plugin.h"
 
 #include <library.h>
-#include <threading.h>
+#include <threading/mutex.h>
 #include "openssl_util.h"
 #include "openssl_crypter.h"
 #include "openssl_hasher.h"
index afe67f62a662e989fce5db794d47340aefe2740e..721f1a126c1ad5fafba4bf066988fccfcfe7cf5f 100644 (file)
@@ -19,7 +19,7 @@
 #include <unistd.h>
 #include <library.h>
 #include <debug.h>
-#include <threading.h>
+#include <threading/mutex.h>
 
 typedef struct private_sqlite_database_t private_sqlite_database_t;
 
diff --git a/src/libstrongswan/threading.h b/src/libstrongswan/threading.h
deleted file mode 100644 (file)
index 8b9f37f..0000000
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Copyright (C) 2008-2009 Tobias Brunner
- * Copyright (C) 2008 Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * for more details.
- */
-
-/**
- * @defgroup threading threading
- * @{ @ingroup libstrongswan
- */
-
-#ifndef THREADING_H_
-#define THREADING_H_
-
-typedef struct mutex_t mutex_t;
-typedef struct condvar_t condvar_t;
-typedef struct rwlock_t rwlock_t;
-typedef enum mutex_type_t mutex_type_t;
-typedef enum condvar_type_t condvar_type_t;
-typedef enum rwlock_type_t rwlock_type_t;
-
-#include <library.h>
-
-#ifdef __APPLE__
-/* on Mac OS X 10.5 several system calls we use are no cancellation points.
- * fortunately, select isn't one of them, so we wrap some of the others with
- * calls to select(2).
- */
-#include <sys/socket.h>
-#include <sys/select.h>
-
-#define WRAP_WITH_SELECT(func, socket, ...)\
-       fd_set rfds; FD_ZERO(&rfds); FD_SET(socket, &rfds);\
-       if (select(socket + 1, &rfds, NULL, NULL, NULL) <= 0) { return -1; }\
-       return func(socket, __VA_ARGS__)
-
-static inline int cancellable_accept(int socket, struct sockaddr *address,
-                                                                        socklen_t *address_len)
-{
-       WRAP_WITH_SELECT(accept, socket, address, address_len);
-}
-#define accept cancellable_accept
-static inline int cancellable_recvfrom(int socket, void *buffer, size_t length,
-                               int flags, struct sockaddr *address, socklen_t *address_len)
-{
-       WRAP_WITH_SELECT(recvfrom, socket, buffer, length, flags, address, address_len);
-}
-#define recvfrom cancellable_recvfrom
-#endif /* __APPLE__ */
-
-/**
- * Type of mutex.
- */
-enum mutex_type_t {
-       /** default mutex */
-       MUTEX_TYPE_DEFAULT      = 0,
-       /** allow recursive locking of the mutex */
-       MUTEX_TYPE_RECURSIVE    = 1,
-};
-
-/**
- * Type of condvar.
- */
-enum condvar_type_t {
-       /** default condvar */
-       CONDVAR_TYPE_DEFAULT    = 0,
-};
-
-/**
- * Type of read-write lock.
- */
-enum rwlock_type_t {
-       /** default condvar */
-       RWLOCK_TYPE_DEFAULT     = 0,
-};
-
-/**
- * Mutex wrapper implements simple, portable and advanced mutex functions.
- */
-struct mutex_t {
-
-       /**
-        * Acquire the lock to the mutex.
-        */
-       void (*lock)(mutex_t *this);
-
-       /**
-        * Release the lock on the mutex.
-        */
-       void (*unlock)(mutex_t *this);
-
-       /**
-        * Destroy a mutex instance.
-        */
-       void (*destroy)(mutex_t *this);
-};
-
-/**
- * Condvar wrapper to use in conjunction with mutex_t.
- */
-struct condvar_t {
-
-       /**
-        * Wait on a condvar until it gets signalized.
-        *
-        * @param mutex                 mutex to release while waiting
-        */
-       void (*wait)(condvar_t *this, mutex_t *mutex);
-
-       /**
-        * Wait on a condvar until it gets signalized, or times out.
-        *
-        * @param mutex                 mutex to release while waiting
-        * @param timeout               timeout im ms
-        * @return                              TRUE if timed out, FALSE otherwise
-        */
-       bool (*timed_wait)(condvar_t *this, mutex_t *mutex, u_int timeout);
-
-       /**
-        * Wait on a condvar until it gets signalized, or times out.
-        *
-        * The passed timeval should be calculated based on the time_monotonic()
-        * function.
-        *
-        * @param mutex                 mutex to release while waiting
-        * @param tv                    absolute time until timeout
-        * @return                              TRUE if timed out, FALSE otherwise
-        */
-       bool (*timed_wait_abs)(condvar_t *this, mutex_t *mutex, timeval_t tv);
-
-       /**
-        * Wake up a single thread in a condvar.
-        */
-       void (*signal)(condvar_t *this);
-
-       /**
-        * Wake up all threads in a condvar.
-        */
-       void (*broadcast)(condvar_t *this);
-
-       /**
-        * Destroy a condvar and free its resources.
-        */
-       void (*destroy)(condvar_t *this);
-};
-
-/**
- * Read-Write lock wrapper.
- */
-struct rwlock_t {
-
-       /**
-        * Acquire the read lock.
-        */
-       void (*read_lock)(rwlock_t *this);
-
-       /**
-        * Acquire the write lock.
-        */
-       void (*write_lock)(rwlock_t *this);
-
-       /**
-        * Try to acquire the write lock.
-        *
-        * Never blocks, but returns FALSE if the lock was already occupied.
-        *
-        * @return              TRUE if lock acquired
-        */
-       bool (*try_write_lock)(rwlock_t *this);
-
-       /**
-        * Release any acquired lock.
-        */
-       void (*unlock)(rwlock_t *this);
-
-       /**
-        * Destroy the read-write lock.
-        */
-       void (*destroy)(rwlock_t *this);
-};
-
-/**
- * Create a mutex instance.
- *
- * @param type         type of mutex to create
- * @return                     unlocked mutex instance
- */
-mutex_t *mutex_create(mutex_type_t type);
-
-/**
- * Create a condvar instance.
- *
- * @param type         type of condvar to create
- * @return                     condvar instance
- */
-condvar_t *condvar_create(condvar_type_t type);
-
-/**
- * Create a read-write lock instance.
- *
- * @param type         type of rwlock to create
- * @return                     unlocked rwlock instance
- */
-rwlock_t *rwlock_create(rwlock_type_t type);
-
-#endif /** THREADING_H_ @}*/
index 7ba1c07ec817912a8cb5beaf781ce4f5fe79192f..4c9589081b01c5ee7b179d19ede21ddcd3328d70 100644 (file)
 #include <time.h>
 #include <errno.h>
 
-#include <threading.h>
 #include <library.h>
 #include <debug.h>
 
 #include "condvar.h"
 #include "mutex.h"
 
+typedef struct private_condvar_t private_condvar_t;
+
+/**
+ * private data of condvar
+ */
+struct private_condvar_t {
+
+       /**
+        * public functions
+        */
+       condvar_t public;
+
+       /**
+        * wrapped pthread condvar
+        */
+       pthread_cond_t condvar;
+};
+
 /**
  * Implementation of condvar_t.wait.
  */
index 9b2966253c87247102ff0b3630a073f180b07ce7..48c949c7cee95449b11902b88940b6a74ca14872 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Tobias Brunner
+ * Copyright (C) 2008-2009 Tobias Brunner
  * Copyright (C) 2008 Martin Willi
  * Hochschule fuer Technik Rapperswil
  *
  * for more details.
  */
 
+/**
+ * @defgroup condvar condvar
+ * @{ @ingroup threading
+ */
+
 #ifndef THREADING_CONDVAR_H_
 #define THREADING_CONDVAR_H_
 
-typedef struct private_condvar_t private_condvar_t;
+typedef struct condvar_t condvar_t;
+typedef enum condvar_type_t condvar_type_t;
+
+#include "mutex.h"
+
+/**
+ * Type of condvar.
+ */
+enum condvar_type_t {
+       /** default condvar */
+       CONDVAR_TYPE_DEFAULT = 0,
+};
 
 /**
- * private data of condvar
+ * Condvar wrapper to use in conjunction with mutex_t.
  */
-struct private_condvar_t {
+struct condvar_t {
+
+       /**
+        * Wait on a condvar until it gets signalized.
+        *
+        * @param mutex                 mutex to release while waiting
+        */
+       void (*wait)(condvar_t *this, mutex_t *mutex);
+
+       /**
+        * Wait on a condvar until it gets signalized, or times out.
+        *
+        * @param mutex                 mutex to release while waiting
+        * @param timeout               timeout im ms
+        * @return                              TRUE if timed out, FALSE otherwise
+        */
+       bool (*timed_wait)(condvar_t *this, mutex_t *mutex, u_int timeout);
+
+       /**
+        * Wait on a condvar until it gets signalized, or times out.
+        *
+        * The passed timeval should be calculated based on the time_monotonic()
+        * function.
+        *
+        * @param mutex                 mutex to release while waiting
+        * @param tv                    absolute time until timeout
+        * @return                              TRUE if timed out, FALSE otherwise
+        */
+       bool (*timed_wait_abs)(condvar_t *this, mutex_t *mutex, timeval_t tv);
+
+       /**
+        * Wake up a single thread in a condvar.
+        */
+       void (*signal)(condvar_t *this);
 
        /**
-        * public functions
+        * Wake up all threads in a condvar.
         */
-       condvar_t public;
+       void (*broadcast)(condvar_t *this);
 
        /**
-        * wrapped pthread condvar
+        * Destroy a condvar and free its resources.
         */
-       pthread_cond_t condvar;
+       void (*destroy)(condvar_t *this);
 };
 
-#endif /* THREADING_CONDVAR_H_ */
+/**
+ * Create a condvar instance.
+ *
+ * @param type         type of condvar to create
+ * @return                     condvar instance
+ */
+condvar_t *condvar_create(condvar_type_t type);
+
+#endif /** THREADING_CONDVAR_H_ @} */
 
index a3d131a05f750b9fe86c731afd47e7892da8a054..6133822c30b5f9876b3ea4e245b200481cd4717e 100644 (file)
 #define _GNU_SOURCE
 #include <pthread.h>
 
-#include <threading.h>
 #include <library.h>
 #include <debug.h>
 
 #include "mutex.h"
 #include "lock_profiler.h"
 
+typedef struct private_mutex_t private_mutex_t;
+typedef struct private_r_mutex_t private_r_mutex_t;
+
+/**
+ * private data of mutex
+ */
+struct private_mutex_t {
+
+       /**
+        * public functions
+        */
+       mutex_t public;
+
+       /**
+        * wrapped pthread mutex
+        */
+       pthread_mutex_t mutex;
+
+       /**
+        * is this a recursiv emutex, implementing private_r_mutex_t?
+        */
+       bool recursive;
+
+       /**
+        * profiling info, if enabled
+        */
+       lock_profile_t profile;
+};
+
+/**
+ * private data of mutex, extended by recursive locking information
+ */
+struct private_r_mutex_t {
+
+       /**
+        * Extends private_mutex_t
+        */
+       private_mutex_t generic;
+
+       /**
+        * thread which currently owns mutex
+        */
+       pthread_t thread;
+
+       /**
+        * times we have locked the lock, stored per thread
+        */
+       pthread_key_t times;
+};
+
 /**
  * Implementation of mutex_t.lock.
  */
index 50c06604543183ada7b3e1f16720aea634396678..ca242f680fc0b9bbf8adde950579661cd525b4af 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Tobias Brunner
+ * Copyright (C) 2008-2009 Tobias Brunner
  * Copyright (C) 2008 Martin Willi
  * Hochschule fuer Technik Rapperswil
  *
  * for more details.
  */
 
+/**
+ * @defgroup mutex mutex
+ * @{ @ingroup threading
+ */
+
 #ifndef THREADING_MUTEX_H_
 #define THREADING_MUTEX_H_
 
-#include "lock_profiler.h"
+typedef struct mutex_t mutex_t;
+typedef enum mutex_type_t mutex_type_t;
 
-typedef struct private_mutex_t private_mutex_t;
-typedef struct private_r_mutex_t private_r_mutex_t;
+#include "condvar.h"
 
-/**
- * private data of mutex
+#ifdef __APPLE__
+/* on Mac OS X 10.5 several system calls we use are no cancellation points.
+ * fortunately, select isn't one of them, so we wrap some of the others with
+ * calls to select(2).
  */
-struct private_mutex_t {
+#include <sys/socket.h>
+#include <sys/select.h>
 
-       /**
-        * public functions
-        */
-       mutex_t public;
+#define WRAP_WITH_SELECT(func, socket, ...)\
+       fd_set rfds; FD_ZERO(&rfds); FD_SET(socket, &rfds);\
+       if (select(socket + 1, &rfds, NULL, NULL, NULL) <= 0) { return -1; }\
+       return func(socket, __VA_ARGS__)
 
-       /**
-        * wrapped pthread mutex
-        */
-       pthread_mutex_t mutex;
+static inline int cancellable_accept(int socket, struct sockaddr *address,
+                                                                        socklen_t *address_len)
+{
+       WRAP_WITH_SELECT(accept, socket, address, address_len);
+}
+#define accept cancellable_accept
+static inline int cancellable_recvfrom(int socket, void *buffer, size_t length,
+                               int flags, struct sockaddr *address, socklen_t *address_len)
+{
+       WRAP_WITH_SELECT(recvfrom, socket, buffer, length, flags, address, address_len);
+}
+#define recvfrom cancellable_recvfrom
+#endif /* __APPLE__ */
 
-       /**
-        * is this a recursiv emutex, implementing private_r_mutex_t?
-        */
-       bool recursive;
-
-       /**
-        * profiling info, if enabled
-        */
-       lock_profile_t profile;
+/**
+ * Type of mutex.
+ */
+enum mutex_type_t {
+       /** default mutex */
+       MUTEX_TYPE_DEFAULT      = 0,
+       /** allow recursive locking of the mutex */
+       MUTEX_TYPE_RECURSIVE    = 1,
 };
 
 /**
- * private data of mutex, extended by recursive locking information
+ * Mutex wrapper implements simple, portable and advanced mutex functions.
  */
-struct private_r_mutex_t {
+struct mutex_t {
 
        /**
-        * Extends private_mutex_t
+        * Acquire the lock to the mutex.
         */
-       private_mutex_t generic;
+       void (*lock)(mutex_t *this);
 
        /**
-        * thread which currently owns mutex
+        * Release the lock on the mutex.
         */
-       pthread_t thread;
+       void (*unlock)(mutex_t *this);
 
        /**
-        * times we have locked the lock, stored per thread
+        * Destroy a mutex instance.
         */
-       pthread_key_t times;
+       void (*destroy)(mutex_t *this);
 };
 
-#endif /* THREADING_MUTEX_H_ */
+/**
+ * Create a mutex instance.
+ *
+ * @param type         type of mutex to create
+ * @return                     unlocked mutex instance
+ */
+mutex_t *mutex_create(mutex_type_t type);
+
+#endif /** THREADING_MUTEX_H_ @} */
 
index bf59f50f1a59a24d287d8d16b1949f2c9dd82e83..ee9fb10be7190e2d7aa54cbb61be7559325553fc 100644 (file)
 #define _GNU_SOURCE
 #include <pthread.h>
 
-#include <threading.h>
 #include <library.h>
 #include <debug.h>
 
 #include "rwlock.h"
+#include "condvar.h"
+#include "mutex.h"
 #include "lock_profiler.h"
 
+typedef struct private_rwlock_t private_rwlock_t;
+
+/**
+ * private data of rwlock
+ */
+struct private_rwlock_t {
+
+       /**
+        * public functions
+        */
+       rwlock_t public;
+
+#ifdef HAVE_PTHREAD_RWLOCK_INIT
+
+       /**
+        * wrapped pthread rwlock
+        */
+       pthread_rwlock_t rwlock;
+
+#else
+
+       /**
+        * mutex to emulate a native rwlock
+        */
+       mutex_t *mutex;
+
+       /**
+        * condvar to handle writers
+        */
+       condvar_t *writers;
+
+       /**
+        * condvar to handle readers
+        */
+       condvar_t *readers;
+
+       /**
+        * number of waiting writers
+        */
+       u_int waiting_writers;
+
+       /**
+        * number of readers holding the lock
+        */
+       u_int reader_count;
+
+       /**
+        * current writer thread, if any
+        */
+       pthread_t writer;
+
+#endif /* HAVE_PTHREAD_RWLOCK_INIT */
+
+       /**
+        * profiling info, if enabled
+        */
+       lock_profile_t profile;
+};
+
+
 #ifdef HAVE_PTHREAD_RWLOCK_INIT
 
 /**
index 2f4330ffb311198eb48e82fc6cf5d9322a3ba06c..a86a241c5904264192c722d1d3521efd358d9521 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Tobias Brunner
+ * Copyright (C) 2008-2009 Tobias Brunner
  * Copyright (C) 2008 Martin Willi
  * Hochschule fuer Technik Rapperswil
  *
  * for more details.
  */
 
+/**
+ * @defgroup rwlock rwlock
+ * @{ @ingroup threading
+ */
+
 #ifndef THREADING_RWLOCK_H_
 #define THREADING_RWLOCK_H_
 
-#include "lock_profiler.h"
-
-typedef struct private_rwlock_t private_rwlock_t;
+typedef struct rwlock_t rwlock_t;
+typedef enum rwlock_type_t rwlock_type_t;
 
 /**
- * private data of rwlock
+ * Type of read-write lock.
  */
-struct private_rwlock_t {
-
-       /**
-        * public functions
-        */
-       rwlock_t public;
-
-#ifdef HAVE_PTHREAD_RWLOCK_INIT
-
-       /**
-        * wrapped pthread rwlock
-        */
-       pthread_rwlock_t rwlock;
-
-#else
-
-       /**
-        * mutex to emulate a native rwlock
-        */
-       mutex_t *mutex;
+enum rwlock_type_t {
+       /** default condvar */
+       RWLOCK_TYPE_DEFAULT = 0,
+};
 
-       /**
-        * condvar to handle writers
       */
-       condvar_t *writers;
+/**
+ * Read-Write lock wrapper.
+ */
+struct rwlock_t {
 
        /**
-        * condvar to handle readers
+        * Acquire the read lock.
         */
-       condvar_t *readers;
+       void (*read_lock)(rwlock_t *this);
 
        /**
-        * number of waiting writers
+        * Acquire the write lock.
         */
-       u_int waiting_writers;
+       void (*write_lock)(rwlock_t *this);
 
        /**
-        * number of readers holding the lock
+        * Try to acquire the write lock.
+        *
+        * Never blocks, but returns FALSE if the lock was already occupied.
+        *
+        * @return              TRUE if lock acquired
         */
-       u_int reader_count;
+       bool (*try_write_lock)(rwlock_t *this);
 
        /**
-        * current writer thread, if any
+        * Release any acquired lock.
         */
-       pthread_t writer;
-
-#endif /* HAVE_PTHREAD_RWLOCK_INIT */
+       void (*unlock)(rwlock_t *this);
 
        /**
-        * profiling info, if enabled
+        * Destroy the read-write lock.
         */
-       lock_profile_t profile;
+       void (*destroy)(rwlock_t *this);
 };
 
-#endif /* THREADING_THREADING_H_ */
+/**
+ * Create a read-write lock instance.
+ *
+ * @param type         type of rwlock to create
+ * @return                     unlocked rwlock instance
+ */
+rwlock_t *rwlock_create(rwlock_type_t type);
+
+#endif /** THREADING_RWLOCK_H_ @} */