2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 /***************************************************************************
19 * Description: Multi thread portability code for JK *
20 * Author: Gal Shachor <shachor@il.ibm.com> *
21 * Version: $Revision: 918711 $ *
22 ***************************************************************************/
27 #include "jk_global.h"
31 #define jk_gettid() ((jk_uint32_t)GetCurrentThreadId())
32 #elif defined(NETWARE) && !defined(__NOVELL_LIBC__)
33 #define getpid() ((int)GetThreadGroupID())
43 * Marks execution under MT compilation
49 typedef CRITICAL_SECTION JK_CRIT_SEC;
50 #define JK_INIT_CS(x, rc) InitializeCriticalSection(x); rc = JK_TRUE
51 #define JK_DELETE_CS(x, rc) DeleteCriticalSection(x); rc = JK_TRUE
52 #define JK_ENTER_CS(x, rc) EnterCriticalSection(x); rc = JK_TRUE
53 #define JK_LEAVE_CS(x, rc) LeaveCriticalSection(x); rc = JK_TRUE
56 #define _MT_CODE_PTHREAD
61 typedef pthread_mutex_t JK_CRIT_SEC;
62 #define JK_INIT_CS(x, rc)\
63 if(pthread_mutex_init(x, NULL)) rc = JK_FALSE; else rc = JK_TRUE
65 #define JK_DELETE_CS(x, rc)\
66 if(pthread_mutex_destroy(x)) rc = JK_FALSE; else rc = JK_TRUE
68 #define JK_ENTER_CS(x, rc)\
69 if(pthread_mutex_lock(x)) rc = JK_FALSE; else rc = JK_TRUE
71 #define JK_LEAVE_CS(x, rc)\
72 if(pthread_mutex_unlock(x)) rc = JK_FALSE; else rc = JK_TRUE
74 #if defined(AS400) || defined(NETWARE)
75 #define jk_pthread_t jk_uint32_t
76 #endif /* AS400 || NETWARE */
77 jk_pthread_t jk_gettid(void);
82 typedef void *JK_CRIT_SEC;
83 #define JK_INIT_CS(x, rc) rc = JK_TRUE
84 #define JK_DELETE_CS(x, rc) rc = JK_TRUE
85 #define JK_ENTER_CS(x, rc) rc = JK_TRUE
86 #define JK_LEAVE_CS(x, rc) rc = JK_TRUE
90 #if !defined(WIN32) && !defined(NETWARE)
95 #define USE_FLOCK_LK 0
98 #define USE_FLOCK_LK 1
103 #include <sys/file.h>
105 #define JK_ENTER_LOCK(x, rc) \
107 while ((rc = flock((x), LOCK_EX) < 0) && (errno == EINTR)); \
108 rc = rc == 0 ? JK_TRUE : JK_FALSE; \
111 #define JK_LEAVE_LOCK(x, rc) \
113 while ((rc = flock((x), LOCK_UN) < 0) && (errno == EINTR)); \
114 rc = rc == 0 ? JK_TRUE : JK_FALSE; \
117 #else /* !USE_FLOCK_LK */
119 #define JK_ENTER_LOCK(x, rc) \
122 _fl.l_type = F_WRLCK; \
123 _fl.l_whence = SEEK_SET; \
127 while ((rc = fcntl((x), F_SETLKW, &_fl) < 0) && (errno == EINTR)); \
128 rc = rc == 0 ? JK_TRUE : JK_FALSE; \
131 #define JK_LEAVE_LOCK(x, rc) \
134 _fl.l_type = F_UNLCK; \
135 _fl.l_whence = SEEK_SET; \
139 while ((rc = fcntl((x), F_SETLKW, &_fl) < 0) && (errno == EINTR)); \
140 rc = rc == 0 ? JK_TRUE : JK_FALSE; \
143 #endif /* USE_FLOCK_LK */
145 #else /* WIN32 || NETWARE */
146 #define JK_ENTER_LOCK(x, rc) rc = JK_TRUE
147 #define JK_LEAVE_LOCK(x, rc) rc = JK_TRUE
150 #endif /* _JK_MT_H */