Hi,

the attached patch provides an interface to apr_thread_rwlock. Implementation 
and tests are very close to APR::ThreadMutex.

Torsten
Index: xs/maps/apr_types.map
===================================================================
--- xs/maps/apr_types.map	(revision 537156)
+++ xs/maps/apr_types.map	(working copy)
@@ -102,7 +102,7 @@
 struct apr_thread_mutex_t    | APR::ThreadMutex
 struct apr_thread_once_t     | UNDEFINED
 struct apr_thread_cond_t     | UNDEFINED
-struct apr_thread_rwlock_t   | UNDEFINED
+struct apr_thread_rwlock_t   | APR::ThreadRWLock
 
 #signal stuff
 apr_signum_t                 | UNDEFINED
Index: xs/maps/apr_functions.map
===================================================================
--- xs/maps/apr_functions.map	(revision 537156)
+++ xs/maps/apr_functions.map	(working copy)
@@ -397,9 +397,9 @@
  apr_thread_cond_pool_get
  apr_thread_cond_timedwait
 
--MODULE=APR::ThreadRWLock
- apr_thread_rwlock_create
- apr_thread_rwlock_destroy
+MODULE=APR::ThreadRWLock   PREFIX=apr_thread_rwlock_
+ SV *:apr_thread_rwlock_create | mpxs_ | SV *:classname, SV *:p_sv | new
+ void:apr_thread_rwlock_destroy | | | apr_thread_rwlock_DESTROY
  apr_thread_rwlock_rdlock
  apr_thread_rwlock_tryrdlock
  apr_thread_rwlock_trywrlock
Index: lib/ModPerl/TypeMap.pm
===================================================================
--- lib/ModPerl/TypeMap.pm	(revision 537156)
+++ lib/ModPerl/TypeMap.pm	(working copy)
@@ -413,6 +413,7 @@
 apr_lib.h
 apr_general.h
 apr_signal.h
+apr_thread_rwlock.h
 util_script.h
 };
 
--- /dev/null	2006-11-25 13:17:37.000000000 +0100
+++ xs/APR/ThreadRWLock/APR__ThreadRWLock.h	2007-05-11 15:40:32.000000000 +0200
@@ -0,0 +1,29 @@
+/* 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.
+ */
+
+#define apr_thread_rwlock_DESTROY apr_thread_rwlock_destroy
+
+static MP_INLINE
+SV *mpxs_apr_thread_rwlock_create(pTHX_ SV *classname, SV *p_sv)
+{
+    apr_pool_t *p = mp_xs_sv2_APR__Pool(p_sv);
+    apr_thread_rwlock_t *rwlock = NULL;
+    SV *rwlock_sv;
+    (void)apr_thread_rwlock_create(&rwlock, p);
+    rwlock_sv = sv_setref_pv(NEWSV(0, 0), "APR::ThreadRWLock", (void*)rwlock);
+    mpxs_add_pool_magic(rwlock_sv, p_sv);
+    return rwlock_sv;
+}
--- /dev/null	2006-11-25 13:17:37.000000000 +0100
+++ t/apr/threadrwlock.t	2007-05-15 11:43:42.000000000 +0200
@@ -0,0 +1,17 @@
+# WARNING: this file is generated, do not edit
+# generated on Tue May 15 11:43:42 2007
+# 01: /home/r2/work/mp2/trunk/trunk/Apache-Test/lib/Apache/TestConfig.pm:953
+# 02: /home/r2/work/mp2/trunk/trunk/Apache-Test/lib/Apache/TestConfig.pm:971
+# 03: /home/r2/work/mp2/trunk/trunk/Apache-Test/lib/Apache/TestConfigPerl.pm:136
+# 04: /home/r2/work/mp2/trunk/trunk/Apache-Test/lib/Apache/TestConfigPerl.pm:573
+# 05: /home/r2/work/mp2/trunk/trunk/Apache-Test/lib/Apache/TestConfig.pm:626
+# 06: /home/r2/work/mp2/trunk/trunk/Apache-Test/lib/Apache/TestConfig.pm:641
+# 07: /home/r2/work/mp2/trunk/trunk/Apache-Test/lib/Apache/TestConfig.pm:1621
+# 08: /home/r2/work/mp2/trunk/trunk/Apache-Test/lib/Apache/TestRun.pm:507
+# 09: /home/r2/work/mp2/trunk/trunk/Apache-Test/lib/Apache/TestRunPerl.pm:90
+# 10: /home/r2/work/mp2/trunk/trunk/Apache-Test/lib/Apache/TestRun.pm:725
+# 11: /home/r2/work/mp2/trunk/trunk/Apache-Test/lib/Apache/TestRun.pm:725
+# 12: /home/r2/work/mp2/trunk/trunk/t/TEST:22
+
+use Apache::TestRequest 'GET_BODY_ASSERT';
+print GET_BODY_ASSERT "/TestAPR__threadrwlock";
--- /dev/null	2006-11-25 13:17:37.000000000 +0100
+++ t/apr-ext/threadrwlock.t	2007-05-15 11:42:09.000000000 +0200
@@ -0,0 +1,11 @@
+#!perl -T
+
+use strict;
+use warnings FATAL => 'all';
+use Apache::Test;
+
+use TestAPRlib::threadrwlock;
+
+plan tests => TestAPRlib::threadrwlock::num_of_tests(), need_threads;
+
+TestAPRlib::threadrwlock::test();
--- /dev/null	2006-11-25 13:17:37.000000000 +0100
+++ t/response/TestAPR/threadrwlock.pm	2007-05-15 11:40:21.000000000 +0200
@@ -0,0 +1,24 @@
+package TestAPR::threadrwlock;
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestUtil;
+
+use Apache2::Const -compile => 'OK';
+
+use TestAPRlib::threadrwlock;
+
+sub handler {
+    my $r = shift;
+
+    my $tests = TestAPRlib::threadrwlock::num_of_tests();
+    plan $r, tests => $tests, need_threads;
+
+    TestAPRlib::threadrwlock::test();
+
+    Apache2::Const::OK;
+}
+
+1;
--- /dev/null	2006-11-25 13:17:37.000000000 +0100
+++ t/lib/TestAPRlib/threadrwlock.pm	2007-05-15 11:39:47.000000000 +0200
@@ -0,0 +1,53 @@
+package TestAPRlib::threadrwlock;
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestUtil;
+
+use APR::Const -compile => qw(EBUSY SUCCESS);
+use APR::Pool();
+
+sub num_of_tests {
+    return 7;
+}
+
+sub test {
+
+    require APR::ThreadRWLock;
+
+    my $pool = APR::Pool->new();
+    my $mutex = APR::ThreadRWLock->new($pool);
+
+    ok $mutex;
+
+    ok t_cmp($mutex->rdlock, APR::Const::SUCCESS,
+             'rdlock == APR::Const::SUCCESS');
+
+    ok t_cmp($mutex->unlock, APR::Const::SUCCESS,
+             'unlock == APR::Const::SUCCESS');
+
+    ok t_cmp($mutex->wrlock, APR::Const::SUCCESS,
+             'wrlock == APR::Const::SUCCESS');
+
+    ok t_cmp($mutex->unlock, APR::Const::SUCCESS,
+             'unlock == APR::Const::SUCCESS');
+
+    # out-of-scope pool
+    {
+        my $mutex = APR::ThreadRWLock->new(APR::Pool->new);
+        # try to overwrite the temp pool data
+        require APR::Table;
+        my $table = APR::Table::make(APR::Pool->new, 50);
+        $table->set($_ => $_) for 'aa'..'za';
+        # now test that we are still OK
+        ok t_cmp($mutex->rdlock, APR::Const::SUCCESS,
+                 'rdlock == APR::Const::SUCCESS');
+        ok t_cmp($mutex->unlock, APR::Const::SUCCESS,
+                 'unlock == APR::Const::SUCCESS');
+    }
+
+}
+
+1;

Attachment: pgp1A9kbdadvZ.pgp
Description: PGP signature

Reply via email to