Skip to content

Commit 6827264

Browse files
committed
Accomplishment: Uvloop now compiles on Windows
1 parent 35b0fab commit 6827264

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

uvloop/includes/compat.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,16 @@ _Py_RestoreSignals(void)
154154
PyOS_setsig(SIGXFSZ, SIG_DFL);
155155
#endif
156156
}
157+
158+
#ifdef _WIN32
159+
void PyOS_BeforeFork() {
160+
return;
161+
}
162+
void PyOS_AfterFork_Parent() {
163+
return;
164+
}
165+
void PyOS_AfterFork_Child() {
166+
return;
167+
}
168+
169+
#endif

uvloop/includes/system.pxd

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,30 @@ cdef extern from "includes/fork_handler.h":
8181
void (*parent)(),
8282
void (*child)())
8383

84-
# TODO: windows needs statomic.h and a few other Things. Might need a reviewer for help.
84+
8585
cdef extern from * nogil:
86+
"""
87+
#ifdef _WIN32
88+
static inline uint64_t
89+
__win_atomic_fetch_add(uint64_t *ptr, uint64_t val){
90+
return *ptr = *(volatile uint64_t *)ptr + val;
91+
}
92+
93+
static inline uint64_t
94+
__win_atomic_fetch_sub(uint64_t *ptr, uint64_t val){
95+
return *ptr = *(volatile uint64_t *)ptr - val;
96+
}
97+
98+
#define __atomic_fetch_add(ptr, val, memorder) \
99+
__win_atomic_fetch_add(ptr, val)
100+
101+
#define __atomic_fetch_sub(ptr, val, memorder) \
102+
__win_atomic_fetch_sub(ptr, val)
103+
104+
/* We need ATOMIC RELAXED still */
105+
#define __ATOMIC_RELAXED 0
106+
#endif /* _WIN32 */
107+
"""
86108
uint64_t __atomic_fetch_add(uint64_t *ptr, uint64_t val, int memorder)
87109
uint64_t __atomic_fetch_sub(uint64_t *ptr, uint64_t val, int memorder)
88110

0 commit comments

Comments
 (0)