win32: add spinlock implementation for Windows.
This commit is contained in:
parent
39f48f37d6
commit
15ad356faa
@ -1,13 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* zzuf - general purpose fuzzer
|
* zzuf - general purpose fuzzer
|
||||||
* Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
|
* Copyright © 2006—2015 Sam Hocevar <sam@hocevar.net>
|
||||||
* All Rights Reserved
|
|
||||||
*
|
*
|
||||||
* This program is free software. It comes without any warranty, to
|
* This program is free software. It comes without any warranty, to
|
||||||
* the extent permitted by applicable law. You can redistribute it
|
* the extent permitted by applicable law. You can redistribute it
|
||||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
* to Public License, Version 2, as published by the WTFPL Task Force.
|
||||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
* See http://www.wtfpl.net/ for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -30,6 +29,9 @@
|
|||||||
# include <regex.h>
|
# include <regex.h>
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
#if _WIN32
|
||||||
|
# include <Windows.h>
|
||||||
|
#endif
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@ -70,18 +72,33 @@ static int *fds, static_fds[STATIC_FILES];
|
|||||||
static int maxfd, nfiles;
|
static int maxfd, nfiles;
|
||||||
|
|
||||||
/* Spinlock. This variable protects the fds variable. */
|
/* Spinlock. This variable protects the fds variable. */
|
||||||
|
#if _WIN32
|
||||||
|
static volatile LONG fd_spinlock = 0;
|
||||||
|
#elif __GNUC__ || __clang__
|
||||||
static volatile int fd_spinlock = 0;
|
static volatile int fd_spinlock = 0;
|
||||||
|
#else
|
||||||
|
# error "No known atomic operations for this platform"
|
||||||
|
#endif
|
||||||
|
|
||||||
static void fd_lock(void)
|
static void fd_lock(void)
|
||||||
{
|
{
|
||||||
while (__sync_lock_test_and_set(&fd_spinlock, 1))
|
#if _WIN32
|
||||||
;
|
do {}
|
||||||
|
while (InterlockedExchange(&fd_spinlock, 1));
|
||||||
|
#elif __GNUC__ || __clang__
|
||||||
|
do {}
|
||||||
|
while (__sync_lock_test_and_set(&fd_spinlock, 1));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fd_unlock(void)
|
static void fd_unlock(void)
|
||||||
{
|
{
|
||||||
__sync_synchronize();
|
#if _WIN32
|
||||||
|
InterlockedExchange(&fd_spinlock, 0);
|
||||||
|
#elif __GNUC__ || __clang__
|
||||||
fd_spinlock = 0;
|
fd_spinlock = 0;
|
||||||
|
__sync_synchronize();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create lock. This lock variable is used to disable file descriptor
|
/* Create lock. This lock variable is used to disable file descriptor
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user