summaryrefslogtreecommitdiffstats
path: root/src/semaphore.h
diff options
context:
space:
mode:
authorMartin Nagy <mnagy@redhat.com>2009-03-30 13:01:56 +0200
committerMartin Nagy <mnagy@redhat.com>2009-03-30 13:08:32 +0200
commita148a9f5f2659c60a534f82d0ec8736f90afa223 (patch)
tree2244198110d012ec0afa16a1a3eee64ee4057061 /src/semaphore.h
parentdd3b35c40b5709f8ea3ded23d4bb5fb4a9320352 (diff)
downloadldap_driver-a148a9f5f2659c60a534f82d0ec8736f90afa223.tar.gz
ldap_driver-a148a9f5f2659c60a534f82d0ec8736f90afa223.tar.xz
ldap_driver-a148a9f5f2659c60a534f82d0ec8736f90afa223.zip
Prepare the tree for conversion to autoconf.
All source files are now moved to src/ and the old Makefile is removed.
Diffstat (limited to 'src/semaphore.h')
-rw-r--r--src/semaphore.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/semaphore.h b/src/semaphore.h
new file mode 100644
index 0000000..d417443
--- /dev/null
+++ b/src/semaphore.h
@@ -0,0 +1,45 @@
+/* Authors: Martin Nagy <mnagy@redhat.com>
+ *
+ * Copyright (C) 2008 Red Hat
+ * see file 'COPYING' for use and warranty information
+ *
+ * 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; version 2 only
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _LD_SEMAPHORE_H_
+#define _LD_SEMAPHORE_H_
+
+#include <isc/condition.h>
+#include <isc/mutex.h>
+
+/*
+ * Semaphore can be "acquired" multiple times. However, it has a maximum
+ * number of times someone can acquire him. If a semaphore is already acquired
+ * more times than allowed, it will block until other thread release its,
+ */
+struct semaphore {
+ int value; /* Maximum number of times you can LOCK()) */
+ isc_mutex_t mutex; /* Mutex protecting this whole struct. */
+ isc_condition_t cond; /* Condition used for waiting on release. */
+};
+
+typedef struct semaphore semaphore_t;
+
+/* Public functions. */
+isc_result_t semaphore_init(semaphore_t *sem, int value);
+void semaphore_destroy(semaphore_t *sem);
+void semaphore_wait(semaphore_t *sem);
+void semaphore_signal(semaphore_t *sem);
+
+#endif /* !_LD_SEMAPHORE_H_ */