003 File Manager
Current Path:
/usr/src/contrib/libevent
usr
/
src
/
contrib
/
libevent
/
📁
..
📄
ChangeLog
(98.8 KB)
📄
ChangeLog-1.4
(16.96 KB)
📄
ChangeLog-2.0
(81.39 KB)
📄
Doxyfile
(9.97 KB)
📄
LICENSE
(4.42 KB)
📄
Makefile.am
(8.64 KB)
📄
Makefile.in
(143.63 KB)
📄
Makefile.nmake
(2.29 KB)
📁
WIN32-Code
📄
aclocal.m4
(41.44 KB)
📄
arc4random.c
(12.83 KB)
📄
autogen.sh
(431 B)
📄
buffer.c
(80.31 KB)
📄
buffer_iocp.c
(8.44 KB)
📄
bufferevent-internal.h
(18.05 KB)
📄
bufferevent.c
(25.49 KB)
📄
bufferevent_async.c
(17.75 KB)
📄
bufferevent_filter.c
(17.58 KB)
📄
bufferevent_openssl.c
(38.57 KB)
📄
bufferevent_pair.c
(9.6 KB)
📄
bufferevent_ratelim.c
(29.51 KB)
📄
bufferevent_sock.c
(18.37 KB)
📄
changelist-internal.h
(4.52 KB)
📁
compat
📄
compile
(7.16 KB)
📄
config.guess
(41.93 KB)
📄
config.h.in
(14.02 KB)
📄
config.sub
(35.14 KB)
📄
configure
(525.2 KB)
📄
configure.ac
(23.97 KB)
📄
defer-internal.h
(2.7 KB)
📄
depcomp
(23.01 KB)
📄
devpoll.c
(7.7 KB)
📄
epoll.c
(14.37 KB)
📄
epoll_sub.c
(2.33 KB)
📄
epolltable-internal.h
(40.4 KB)
📄
evbuffer-internal.h
(12.51 KB)
📄
evconfig-private.h
(1.33 KB)
📄
evconfig-private.h.in
(1.21 KB)
📄
evdns.c
(127.4 KB)
📄
event-internal.h
(16.85 KB)
📄
event.c
(100.49 KB)
📄
event_iocp.c
(7.52 KB)
📄
event_rpcgen.py
(54.33 KB)
📄
event_tagging.c
(14.3 KB)
📄
evmap-internal.h
(4.78 KB)
📄
evmap.c
(28.2 KB)
📄
evport.c
(11.72 KB)
📄
evrpc-internal.h
(5.58 KB)
📄
evrpc.c
(28.68 KB)
📄
evsignal-internal.h
(2.57 KB)
📄
evthread-internal.h
(13.99 KB)
📄
evthread.c
(13.42 KB)
📄
evthread_pthread.c
(4.84 KB)
📄
evthread_win32.c
(8.39 KB)
📄
evutil.c
(69 KB)
📄
evutil_rand.c
(5.08 KB)
📄
evutil_time.c
(16.69 KB)
📄
ht-internal.h
(28.5 KB)
📄
http-internal.h
(5.78 KB)
📄
http.c
(120.9 KB)
📁
include
📄
install-sh
(14.33 KB)
📄
iocp-internal.h
(7.52 KB)
📄
ipv6-internal.h
(2.46 KB)
📄
kqueue-internal.h
(1.94 KB)
📄
kqueue.c
(14.36 KB)
📄
libevent.pc.in
(317 B)
📄
libevent_core.pc.in
(281 B)
📄
libevent_extra.pc.in
(284 B)
📄
libevent_openssl.pc.in
(372 B)
📄
libevent_pthreads.pc.in
(384 B)
📄
listener.c
(20.83 KB)
📄
log-internal.h
(3.14 KB)
📄
log.c
(5.51 KB)
📄
ltmain.sh
(316.49 KB)
📁
m4
📄
make-event-config.sed
(588 B)
📄
minheap-internal.h
(6.78 KB)
📄
missing
(6.71 KB)
📄
mm-internal.h
(3.32 KB)
📄
openssl-compat.h
(974 B)
📄
poll.c
(7.99 KB)
📄
ratelim-internal.h
(4 KB)
📁
sample
📄
select.c
(8.5 KB)
📄
signal.c
(12.22 KB)
📄
strlcpy-internal.h
(366 B)
📄
strlcpy.c
(2.52 KB)
📁
test
📄
test-driver
(4.53 KB)
📄
time-internal.h
(3 KB)
📄
util-internal.h
(15.54 KB)
📄
whatsnew-2.0.txt
(25.73 KB)
📄
whatsnew-2.1.txt
(32.6 KB)
📄
win32select.c
(10.29 KB)
Editing: evthread_win32.c
/* * Copyright 2009-2012 Niels Provos and Nick Mathewson * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" #include "evconfig-private.h" #ifdef _WIN32 #ifndef _WIN32_WINNT /* Minimum required for InitializeCriticalSectionAndSpinCount */ #define _WIN32_WINNT 0x0403 #endif #include <winsock2.h> #define WIN32_LEAN_AND_MEAN #include <windows.h> #undef WIN32_LEAN_AND_MEAN #include <sys/locking.h> #endif struct event_base; #include "event2/thread.h" #include "mm-internal.h" #include "evthread-internal.h" #include "time-internal.h" #define SPIN_COUNT 2000 static void * evthread_win32_lock_create(unsigned locktype) { CRITICAL_SECTION *lock = mm_malloc(sizeof(CRITICAL_SECTION)); if (!lock) return NULL; if (InitializeCriticalSectionAndSpinCount(lock, SPIN_COUNT) == 0) { mm_free(lock); return NULL; } return lock; } static void evthread_win32_lock_free(void *lock_, unsigned locktype) { CRITICAL_SECTION *lock = lock_; DeleteCriticalSection(lock); mm_free(lock); } static int evthread_win32_lock(unsigned mode, void *lock_) { CRITICAL_SECTION *lock = lock_; if ((mode & EVTHREAD_TRY)) { return ! TryEnterCriticalSection(lock); } else { EnterCriticalSection(lock); return 0; } } static int evthread_win32_unlock(unsigned mode, void *lock_) { CRITICAL_SECTION *lock = lock_; LeaveCriticalSection(lock); return 0; } static unsigned long evthread_win32_get_id(void) { return (unsigned long) GetCurrentThreadId(); } #ifdef WIN32_HAVE_CONDITION_VARIABLES static void WINAPI (*InitializeConditionVariable_fn)(PCONDITION_VARIABLE) = NULL; static BOOL WINAPI (*SleepConditionVariableCS_fn)( PCONDITION_VARIABLE, PCRITICAL_SECTION, DWORD) = NULL; static void WINAPI (*WakeAllConditionVariable_fn)(PCONDITION_VARIABLE) = NULL; static void WINAPI (*WakeConditionVariable_fn)(PCONDITION_VARIABLE) = NULL; static int evthread_win32_condvar_init(void) { HANDLE lib; lib = GetModuleHandle(TEXT("kernel32.dll")); if (lib == NULL) return 0; #define LOAD(name) \ name##_fn = GetProcAddress(lib, #name) LOAD(InitializeConditionVariable); LOAD(SleepConditionVariableCS); LOAD(WakeAllConditionVariable); LOAD(WakeConditionVariable); return InitializeConditionVariable_fn && SleepConditionVariableCS_fn && WakeAllConditionVariable_fn && WakeConditionVariable_fn; } /* XXXX Even if we can build this, we don't necessarily want to: the functions * in question didn't exist before Vista, so we'd better LoadProc them. */ static void * evthread_win32_condvar_alloc(unsigned condflags) { CONDITION_VARIABLE *cond = mm_malloc(sizeof(CONDITION_VARIABLE)); if (!cond) return NULL; InitializeConditionVariable_fn(cond); return cond; } static void evthread_win32_condvar_free(void *cond_) { CONDITION_VARIABLE *cond = cond_; /* There doesn't _seem_ to be a cleaup fn here... */ mm_free(cond); } static int evthread_win32_condvar_signal(void *cond, int broadcast) { CONDITION_VARIABLE *cond = cond_; if (broadcast) WakeAllConditionVariable_fn(cond); else WakeConditionVariable_fn(cond); return 0; } static int evthread_win32_condvar_wait(void *cond_, void *lock_, const struct timeval *tv) { CONDITION_VARIABLE *cond = cond_; CRITICAL_SECTION *lock = lock_; DWORD ms, err; BOOL result; if (tv) ms = evutil_tv_to_msec_(tv); else ms = INFINITE; result = SleepConditionVariableCS_fn(cond, lock, ms); if (result) { if (GetLastError() == WAIT_TIMEOUT) return 1; else return -1; } else { return 0; } } #endif struct evthread_win32_cond { HANDLE event; CRITICAL_SECTION lock; int n_waiting; int n_to_wake; int generation; }; static void * evthread_win32_cond_alloc(unsigned flags) { struct evthread_win32_cond *cond; if (!(cond = mm_malloc(sizeof(struct evthread_win32_cond)))) return NULL; if (InitializeCriticalSectionAndSpinCount(&cond->lock, SPIN_COUNT)==0) { mm_free(cond); return NULL; } if ((cond->event = CreateEvent(NULL,TRUE,FALSE,NULL)) == NULL) { DeleteCriticalSection(&cond->lock); mm_free(cond); return NULL; } cond->n_waiting = cond->n_to_wake = cond->generation = 0; return cond; } static void evthread_win32_cond_free(void *cond_) { struct evthread_win32_cond *cond = cond_; DeleteCriticalSection(&cond->lock); CloseHandle(cond->event); mm_free(cond); } static int evthread_win32_cond_signal(void *cond_, int broadcast) { struct evthread_win32_cond *cond = cond_; EnterCriticalSection(&cond->lock); if (broadcast) cond->n_to_wake = cond->n_waiting; else ++cond->n_to_wake; cond->generation++; SetEvent(cond->event); LeaveCriticalSection(&cond->lock); return 0; } static int evthread_win32_cond_wait(void *cond_, void *lock_, const struct timeval *tv) { struct evthread_win32_cond *cond = cond_; CRITICAL_SECTION *lock = lock_; int generation_at_start; int waiting = 1; int result = -1; DWORD ms = INFINITE, ms_orig = INFINITE, startTime, endTime; if (tv) ms_orig = ms = evutil_tv_to_msec_(tv); EnterCriticalSection(&cond->lock); ++cond->n_waiting; generation_at_start = cond->generation; LeaveCriticalSection(&cond->lock); LeaveCriticalSection(lock); startTime = GetTickCount(); do { DWORD res; res = WaitForSingleObject(cond->event, ms); EnterCriticalSection(&cond->lock); if (cond->n_to_wake && cond->generation != generation_at_start) { --cond->n_to_wake; --cond->n_waiting; result = 0; waiting = 0; goto out; } else if (res != WAIT_OBJECT_0) { result = (res==WAIT_TIMEOUT) ? 1 : -1; --cond->n_waiting; waiting = 0; goto out; } else if (ms != INFINITE) { endTime = GetTickCount(); if (startTime + ms_orig <= endTime) { result = 1; /* Timeout */ --cond->n_waiting; waiting = 0; goto out; } else { ms = startTime + ms_orig - endTime; } } /* If we make it here, we are still waiting. */ if (cond->n_to_wake == 0) { /* There is nobody else who should wake up; reset * the event. */ ResetEvent(cond->event); } out: LeaveCriticalSection(&cond->lock); } while (waiting); EnterCriticalSection(lock); EnterCriticalSection(&cond->lock); if (!cond->n_waiting) ResetEvent(cond->event); LeaveCriticalSection(&cond->lock); return result; } int evthread_use_windows_threads(void) { struct evthread_lock_callbacks cbs = { EVTHREAD_LOCK_API_VERSION, EVTHREAD_LOCKTYPE_RECURSIVE, evthread_win32_lock_create, evthread_win32_lock_free, evthread_win32_lock, evthread_win32_unlock }; struct evthread_condition_callbacks cond_cbs = { EVTHREAD_CONDITION_API_VERSION, evthread_win32_cond_alloc, evthread_win32_cond_free, evthread_win32_cond_signal, evthread_win32_cond_wait }; #ifdef WIN32_HAVE_CONDITION_VARIABLES struct evthread_condition_callbacks condvar_cbs = { EVTHREAD_CONDITION_API_VERSION, evthread_win32_condvar_alloc, evthread_win32_condvar_free, evthread_win32_condvar_signal, evthread_win32_condvar_wait }; #endif evthread_set_lock_callbacks(&cbs); evthread_set_id_callback(evthread_win32_get_id); #ifdef WIN32_HAVE_CONDITION_VARIABLES if (evthread_win32_condvar_init()) { evthread_set_condition_callbacks(&condvar_cbs); return 0; } #endif evthread_set_condition_callbacks(&cond_cbs); return 0; }
Upload File
Create Folder