Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
1b047c45
Commit
1b047c45
authored
May 24, 2011
by
Alexey Borzenkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get rid of vfd_init(), alloc CRITICAL_SECTION dynamically instead
parent
5af13bbe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
16 deletions
+17
-16
gevent/core_.pyx
gevent/core_.pyx
+0
-3
gevent/libev.pxd
gevent/libev.pxd
+0
-1
gevent/libev_vfd.h
gevent/libev_vfd.h
+17
-12
No files found.
gevent/core_.pyx
View file @
1b047c45
...
...
@@ -4,9 +4,6 @@ cimport libev
from
python
cimport
*
libev
.
vfd_init
()
__all__
=
[
'get_version'
,
'get_header_version'
,
'supported_backends'
,
...
...
gevent/libev.pxd
View file @
1b047c45
cdef
extern
from
"libev_vfd.h"
:
void
vfd_init
()
long
vfd_get
(
int
)
int
vfd_open
(
long
)
except
-
1
void
vfd_free
(
int
)
...
...
gevent/libev_vfd.h
View file @
1b047c45
...
...
@@ -26,15 +26,27 @@ static PyObject* vfd_map = NULL; /* map OS handle -> virtual fd */
static
vfd_entry
*
vfd_entries
=
NULL
;
/* list of virtual fd entries */
#ifdef WITH_THREAD
static
CRITICAL_SECTION
vfd_lock
;
#define VFD_LOCK_INIT InitializeCriticalSection(&vfd_lock)
#define VFD_LOCK_ENTER EnterCriticalSection(&vfd_lock)
#define VFD_LOCK_LEAVE LeaveCriticalSection(&vfd_lock)
static
CRITICAL_SECTION
*
volatile
vfd_lock
=
NULL
;
static
CRITICAL_SECTION
*
vfd_make_lock
()
{
if
(
vfd_lock
==
NULL
)
{
/* must use malloc and not PyMem_Malloc here */
CRITICAL_SECTION
*
lock
=
malloc
(
sizeof
(
CRITICAL_SECTION
));
InitializeCriticalSection
(
lock
);
if
(
InterlockedCompareExchangePointer
(
&
vfd_lock
,
lock
,
NULL
)
!=
NULL
)
{
/* another thread initialized lock first */
DeleteCriticalSection
(
lock
);
free
(
lock
);
}
}
return
vfd_lock
;
}
#define VFD_LOCK_ENTER EnterCriticalSection(vfd_make_lock())
#define VFD_LOCK_LEAVE LeaveCriticalSection(vfd_lock)
#define VFD_GIL_DECLARE PyGILState_STATE ___save
#define VFD_GIL_ENSURE ___save = PyGILState_Ensure()
#define VFD_GIL_RELEASE PyGILState_Release(___save)
#else
#define VFD_LOCK_INIT
#define VFD_LOCK_ENTER
#define VFD_LOCK_LEAVE
#define VFD_GIL_DECLARE
...
...
@@ -42,11 +54,6 @@ static CRITICAL_SECTION vfd_lock;
#define VFD_GIL_RELEASE
#endif
static
void
vfd_init
()
{
VFD_LOCK_INIT
;
}
/*
* Given a virtual fd returns an OS handle or -1
* This function is speed critical, so it cannot use GIL
...
...
@@ -188,7 +195,6 @@ done:
* using runtime fds in libev. Note that it will leak
* fds, because there's no way of closing them safely
*/
#define vfd_init() do {} while(0)
#define vfd_get(fd) _get_osfhandle((fd))
#define vfd_open(fd) _open_osfhandle((fd), 0)
#define vfd_free(fd)
...
...
@@ -197,7 +203,6 @@ done:
/*
* On non-win32 platforms vfd_* are noop macros
*/
#define vfd_init() do {} while(0)
#define vfd_get(fd) (fd)
#define vfd_open(fd) ((int)(fd))
#define vfd_free(fd)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment