summaryrefslogtreecommitdiffstats
path: root/test/globalmutexchild.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:11:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:11:38 +0000
commitbc7e963c37d9c8d1c854ac960df241cfa34e3dc5 (patch)
treeaa35d7414ce9f1326abf6f723f6dfa5b0aa08b1d /test/globalmutexchild.c
parentInitial commit. (diff)
downloadapr-upstream.tar.xz
apr-upstream.zip
Adding upstream version 1.7.2.upstream/1.7.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/globalmutexchild.c')
-rw-r--r--test/globalmutexchild.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/globalmutexchild.c b/test/globalmutexchild.c
new file mode 100644
index 0000000..4b8737b
--- /dev/null
+++ b/test/globalmutexchild.c
@@ -0,0 +1,64 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "testglobalmutex.h"
+#include "apr_pools.h"
+#include "apr_file_io.h"
+#include "apr_general.h"
+#include "apr_global_mutex.h"
+#include "apr_strings.h"
+#include "apr.h"
+
+#if APR_HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+
+int main(int argc, const char * const argv[])
+{
+ apr_pool_t *p;
+ int i = 0;
+ apr_lockmech_e mech;
+ apr_global_mutex_t *global_lock;
+ apr_status_t rv;
+
+ apr_initialize();
+ atexit(apr_terminate);
+
+ apr_pool_create(&p, NULL);
+ if (argc >= 2) {
+ mech = (apr_lockmech_e)apr_strtoi64(argv[1], NULL, 0);
+ }
+ else {
+ mech = APR_LOCK_DEFAULT;
+ }
+ rv = apr_global_mutex_create(&global_lock, LOCKNAME, mech, p);
+ if (rv != APR_SUCCESS) {
+ exit(-rv);
+ }
+ apr_global_mutex_child_init(&global_lock, LOCKNAME, p);
+
+ while (1) {
+ apr_global_mutex_lock(global_lock);
+ if (i == MAX_ITER) {
+ apr_global_mutex_unlock(global_lock);
+ exit(i);
+ }
+ i++;
+ apr_global_mutex_unlock(global_lock);
+ }
+ exit(0);
+}