00001 /** @file 00002 00003 A brief file description 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 //------------------------------------------------------------------------- 00025 // Read-Write Lock -- Code from Stevens' Unix Network Programming - 00026 // Interprocess Communications. This is the simple implementation and 00027 // will not work if used in conjunction with ink_thread_cancel(). 00028 //------------------------------------------------------------------------- 00029 00030 #ifndef _INK_RWLOCK_H_ 00031 #define _INK_RWLOCK_H_ 00032 00033 #include "ink_mutex.h" 00034 #include "ink_thread.h" 00035 00036 #define RW_MAGIC 0x19283746 00037 00038 struct ink_rwlock 00039 { 00040 ink_mutex rw_mutex; /* basic lock on this struct */ 00041 ink_cond rw_condreaders; /* for reader threads waiting */ 00042 ink_cond rw_condwriters; /* for writer threads waiting */ 00043 int rw_magic; /* for error checking */ 00044 int rw_nwaitreaders; /* the number waiting */ 00045 int rw_nwaitwriters; /* the number waiting */ 00046 int rw_refcount; 00047 }; 00048 00049 int ink_rwlock_init(ink_rwlock * rw); 00050 int ink_rwlock_destroy(ink_rwlock * rw); 00051 int ink_rwlock_rdlock(ink_rwlock * rw); 00052 int ink_rwlock_wrlock(ink_rwlock * rw); 00053 int ink_rwlock_unlock(ink_rwlock * rw); 00054 00055 #endif