Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

rwlocks.h

Go to the documentation of this file.
00001 /*
00002  * Active Router Transport Protocol (ARTP) implementation
00003  * Copyright (c) 2004, Tomas Rebok
00004  * All rights reserved.
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the "BSD License" which is
00008  * distributed with the software in the file LICENSE.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the BSD
00013  * License for more details.
00014  */
00015 
00023 #ifndef ARTP_RWLOCKS_H
00024 #define ARTP_RWLOCKS_H   1
00025 
00026 
00030 #define RW_INIT(x, y, z, wsem, rsem, wcount, rcount) {\
00031     if ((pthread_mutex_init(&x, NULL) != 0)\
00032             || (pthread_mutex_init(&y, NULL) != 0)\
00033             || (pthread_mutex_init(&z, NULL) != 0)\
00034             || (pthread_mutex_init(&wsem, NULL) != 0)\
00035             || (pthread_mutex_init(&rsem, NULL) != 0))\
00036         return E_MEMORY_FAIL;\
00037     wcount = 0;\
00038     rcount = 0;\
00039 }
00040 
00041 
00047 #define READERS_LOCK(x, y, z, wsem, rsem, wcount, rcount) {\
00048     pthread_mutex_lock(&z);\
00049         pthread_mutex_lock(&rsem);\
00050             pthread_mutex_lock(&x);\
00051                 (rcount)++;\
00052                 if ((rcount) == 1)\
00053                     pthread_mutex_lock(&wsem);\
00054             pthread_mutex_unlock(&x);\
00055         pthread_mutex_unlock(&rsem);\
00056     pthread_mutex_unlock(&z);\
00057 }
00058 
00059 
00064 #define READERS_UNLOCK(x, y, z, wsem, rsem, wcount, rcount) {\
00065     pthread_mutex_lock(&x);\
00066         (rcount)--;\
00067         if ((rcount) == 0)\
00068             pthread_mutex_unlock(&wsem);\
00069     pthread_mutex_unlock(&x);\
00070 }
00071 
00072 
00078 #define WRITERS_LOCK(x, y, z, wsem, rsem, wcount, rcount) {\
00079     pthread_mutex_lock(&y);\
00080         (wcount)++;\
00081         if ((wcount) == 1)\
00082             pthread_mutex_lock(&rsem);\
00083     pthread_mutex_unlock(&y);\
00084     pthread_mutex_lock(&wsem);\
00085 }
00086 
00087 
00092 #define WRITERS_UNLOCK(x, y, z, wsem, rsem, wcount, rcount) {\
00093     pthread_mutex_unlock(&wsem);\
00094     pthread_mutex_lock(&y);\
00095         (wcount)--;\
00096         if ((wcount) == 0)\
00097             pthread_mutex_unlock(&rsem);\
00098     pthread_mutex_unlock(&y);\
00099 }
00100 
00101 
00102 #endif
00103 
00104 /* vim: set ts=4 : */

Generated on Fri May 21 07:50:24 2004 for Active Router Transport Protocol (ARTP) by doxygen1.2.15