00001 /** @file 00002 00003 RecMutex definitions 00004 00005 @section license License 00006 00007 Licensed to the Apache Software Foundation (ASF) under one 00008 or more contributor license agreements. See the NOTICE file 00009 distributed with this work for additional information 00010 regarding copyright ownership. The ASF licenses this file 00011 to you under the Apache License, Version 2.0 (the 00012 "License"); you may not use this file except in compliance 00013 with the License. You may obtain a copy of the License at 00014 00015 http://www.apache.org/licenses/LICENSE-2.0 00016 00017 Unless required by applicable law or agreed to in writing, software 00018 distributed under the License is distributed on an "AS IS" BASIS, 00019 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 See the License for the specific language governing permissions and 00021 limitations under the License. 00022 */ 00023 00024 #include "ink_config.h" 00025 #include "I_RecMutex.h" 00026 00027 int 00028 rec_mutex_init(RecMutex * m, const char *name) 00029 { 00030 m->nthread_holding = 0; 00031 m->thread_holding = 0; 00032 return ink_mutex_init(&(m->the_mutex), name); 00033 } 00034 00035 int 00036 rec_mutex_destroy(RecMutex * m) 00037 { 00038 ink_assert(m->nthread_holding == 0); 00039 ink_assert(m->thread_holding == 0); 00040 return ink_mutex_destroy(&(m->the_mutex)); 00041 } 00042 00043 int 00044 rec_mutex_acquire(RecMutex * m) 00045 { 00046 00047 ink_thread this_thread = ink_thread_self(); 00048 00049 if (m->thread_holding != this_thread) { 00050 ink_mutex_acquire(&(m->the_mutex)); 00051 m->thread_holding = this_thread; 00052 } 00053 00054 m->nthread_holding++; 00055 return 0; 00056 } 00057 00058 int 00059 rec_mutex_release(RecMutex * m) 00060 { 00061 00062 if (m->nthread_holding != 0) { 00063 m->nthread_holding--; 00064 if (m->nthread_holding == 0) { 00065 m->thread_holding = 0; 00066 ink_mutex_release(&(m->the_mutex)); 00067 } 00068 } 00069 return 0; 00070 }