⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thread.h

📁 OpenVPN is a robust and highly flexible tunneling application that uses all of the encryption, authe
💻 H
字号:
/* *  OpenVPN -- An application to securely tunnel IP networks *             over a single UDP port, with support for SSL/TLS-based *             session authentication and key exchange, *             packet encryption, packet authentication, and *             packet compression. * *  Copyright (C) 2002-2004 James Yonan <jim@yonan.net> * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program (see the file COPYING included with this *  distribution); if not, write to the Free Software Foundation, Inc., *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#ifndef THREAD_H#define THREAD_H#include "basic.h"#include "common.h"/* * OpenVPN static mutex locks, by mutex type */#define L_UNUSED       0#define L_CTIME        1#define L_INET_NTOA    2#define L_MSG          3#define L_STRERR       4#define L_PUTENV       5#define L_PRNG         6#define L_GC_MALLOC    7#define L_GETTIMEOFDAY 8#define L_SCRIPT       9#define N_MUTEXES      10#ifdef USE_PTHREAD#define CACHE_LINE_SIZE 128/* * Improve SMP performance by making sure that each * mutex resides in its own cache line. */struct sparse_mutex{  pthread_mutex_t mutex;  uint8_t dummy [CACHE_LINE_SIZE - sizeof (pthread_mutex_t)];};typedef pthread_t openvpn_thread_t;extern bool pthread_initialized;extern struct sparse_mutex mutex_array[N_MUTEXES];#define MUTEX_DEFINE(lock) pthread_mutex_t lock#define MUTEX_PTR_DEFINE(lock) pthread_mutex_t *lockstatic inline boolopenvpn_thread_enabled (void){  return pthread_initialized;}static inline openvpn_thread_topenvpn_thread_self (void){  return pthread_initialized ? pthread_self() : 0;}static inline voidmutex_init (pthread_mutex_t *mutex){  if (mutex)    pthread_mutex_init (mutex, NULL);}static inline voidmutex_destroy (pthread_mutex_t *mutex){  if (mutex)    pthread_mutex_destroy (mutex);}static inline voidmutex_lock (pthread_mutex_t *mutex){  if (pthread_initialized && mutex)    pthread_mutex_lock (mutex);}static inline voidmutex_unlock (pthread_mutex_t *mutex){  if (pthread_initialized && mutex)    {      pthread_mutex_unlock (mutex);#if 1 /* JYFIXME: if race conditions exist, make them more likely to occur */      sleep (0);#endif    }}static inline voidmutex_cycle (pthread_mutex_t *mutex){  if (pthread_initialized && mutex)    {      pthread_mutex_unlock (mutex);      sleep (0);      pthread_mutex_lock (mutex);    }}static inline voidmutex_lock_static (int type){  mutex_lock (&mutex_array[type].mutex);}static inline voidmutex_unlock_static (int type){  mutex_unlock (&mutex_array[type].mutex);}static inline voidmutex_cycle_static (int type){  mutex_cycle (&mutex_array[type].mutex);}void openvpn_thread_init (void);void openvpn_thread_cleanup (void);openvpn_thread_t openvpn_thread_create (void *(*start_routine) (void *), void* arg);void openvpn_thread_join (openvpn_thread_t id);#else /* USE_PTHREAD */typedef int openvpn_thread_t;#define MUTEX_DEFINE(lock)#define MUTEX_PTR_DEFINE(lock)#define mutex_init(m)#define mutex_destroy(m)#define mutex_lock(m)#define mutex_unlock(m)#define mutex_cycle(m)static inline boolopenvpn_thread_enabled (void){  return false;}static inline openvpn_thread_topenvpn_thread_self (void){  return 0;}static inline voidopenvpn_thread_init (void){}static inline voidopenvpn_thread_cleanup (void){}static inline openvpn_thread_topenvpn_thread_create (void *(*start_routine) (void *), void* arg){  return 0;}static inline voidwork_thread_join (openvpn_thread_t id){}static inline voidmutex_lock_static (int type){}static inline voidmutex_unlock_static (int type){}static inline voidmutex_cycle_static (int type){}#endif /* USE_PTHREAD */#endif /* THREAD_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -