Return-Path: X-Original-To: apmail-subversion-commits-archive@minotaur.apache.org Delivered-To: apmail-subversion-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3DCDD40F4 for ; Fri, 1 Jul 2011 19:04:52 +0000 (UTC) Received: (qmail 91876 invoked by uid 500); 1 Jul 2011 19:04:52 -0000 Delivered-To: apmail-subversion-commits-archive@subversion.apache.org Received: (qmail 91842 invoked by uid 500); 1 Jul 2011 19:04:51 -0000 Mailing-List: contact commits-help@subversion.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@subversion.apache.org Delivered-To: mailing list commits@subversion.apache.org Received: (qmail 91835 invoked by uid 99); 1 Jul 2011 19:04:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jul 2011 19:04:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jul 2011 19:04:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1F18623888CE for ; Fri, 1 Jul 2011 19:04:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1142026 - in /subversion/branches/svn_mutex/subversion: include/private/svn_mutex.h libsvn_subr/svn_mutex.c Date: Fri, 01 Jul 2011 19:04:30 -0000 To: commits@subversion.apache.org From: stefan2@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110701190430.1F18623888CE@eris.apache.org> Author: stefan2 Date: Fri Jul 1 19:04:29 2011 New Revision: 1142026 URL: http://svn.apache.org/viewvc?rev=1142026&view=rev Log: Introduce the svn_mutex API and implement it * subversion/include/private/svn_mutex.h new private API header * subversion/libsvn_subr/svn_mutex.c implement the new API Added: subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h subversion/branches/svn_mutex/subversion/libsvn_subr/svn_mutex.c Added: subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h URL: http://svn.apache.org/viewvc/subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h?rev=1142026&view=auto ============================================================================== --- subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h (added) +++ subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h Fri Jul 1 19:04:29 2011 @@ -0,0 +1,82 @@ +/** + * @copyright + * ==================================================================== + * 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. + * ==================================================================== + * @endcopyright + * + * @file svn_mutex.h + * @brief Strutures and functions for mutual exclusion + */ + +#ifndef SVN_MUTEX_H +#define SVN_MUTEX_H + +#include +#include "svn_error.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * This is a simple wrapper around @c apr_thread_mutex_t and will be a + * valid identifier even if APR does not support threading. + */ +typedef struct svn_mutex__t +{ +#if APR_HAS_THREADS + + /** A mutex for synchronization between threads. It may be NULL, in + * which case no synchronization will take place. The latter is useful, + * if implement some functionality where synchronization is optional. + */ + apr_thread_mutex_t *mutex; + +#endif +} svn_mutex__t; + +/** Initialize the @a *mutex with a lifetime defined by @a pool, if + * @a enable_mutex is TRUE and with @c NULL otherwise. If @a enable_mutex + * is set but threading is not supported by APR, this function returns an + * @c APR_ENOTIMPL error. + */ +svn_error_t * +svn_mutex__init(svn_mutex__t *mutex, + svn_boolean_t enable_mutex, + apr_pool_t *pool); + +/** Acquire the @a mutex, if that has been enabled in @ref svn_mutex__init. + * Make sure to call @ref svn_mutex__unlock some time later in the same + * thread to release the mutex again. Recursive locking are not supported. + */ +svn_error_t * +svn_mutex__lock(svn_mutex__t mutex); + +/** Release the @a mutex, previously acquired using @ref svn_mutex__lock + * that has been enabled in @ref svn_mutex__init. + */ +svn_error_t * +svn_mutex__unlock(svn_mutex__t mutex, + svn_error_t *err); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* SVN_MUTEX_H */ \ No newline at end of file Added: subversion/branches/svn_mutex/subversion/libsvn_subr/svn_mutex.c URL: http://svn.apache.org/viewvc/subversion/branches/svn_mutex/subversion/libsvn_subr/svn_mutex.c?rev=1142026&view=auto ============================================================================== --- subversion/branches/svn_mutex/subversion/libsvn_subr/svn_mutex.c (added) +++ subversion/branches/svn_mutex/subversion/libsvn_subr/svn_mutex.c Fri Jul 1 19:04:29 2011 @@ -0,0 +1,80 @@ +/* + * svn_mutex.c: in-memory caching for Subversion + * + * ==================================================================== + * 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 "svn_private_config.h" +#include "private/svn_mutex.h" + +svn_error_t * +svn_mutex__init(svn_mutex__t *mutex, + svn_boolean_t enable_mutex, + apr_pool_t *pool) +{ +#if APR_HAS_THREADS + mutex->mutex = NULL; + if (enable_mutex) + { + apr_status_t status = + apr_thread_mutex_create(&mutex->mutex, + APR_THREAD_MUTEX_DEFAULT, + pool); + if (status) + return svn_error_wrap_apr(status, _("Can't create mutex")); + } +#else + if (enable_mutex) + return svn_error_wrap_apr(APR_ENOTIMPL, _("APR doesn't support threads")); +#endif + + return SVN_NO_ERROR; +} + +svn_error_t * +svn_mutex__lock(svn_mutex__t mutex) +{ +#if APR_HAS_THREADS + if (mutex.mutex) + { + apr_status_t status = apr_thread_mutex_lock(mutex.mutex); + if (status) + return svn_error_wrap_apr(status, _("Can't lock mutex")); + } +#endif + + return SVN_NO_ERROR; +} + +svn_error_t * +svn_mutex__unlock(svn_mutex__t mutex, + svn_error_t *err) +{ +#if APR_HAS_THREADS + if (mutex.mutex) + { + apr_status_t status = apr_thread_mutex_unlock(mutex.mutex); + if (status && !err) + return svn_error_wrap_apr(status, _("Can't unlock mutex")); + } +#endif + + return err; +}