aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface/src
diff options
context:
space:
mode:
authorPatrik Nyblom <[email protected]>2010-09-10 12:19:30 +0200
committerPatrik Nyblom <[email protected]>2010-09-13 10:51:53 +0200
commitd9ad7fc091e850d9484e3f1fdf9ede22f9a18e04 (patch)
tree9e6a833aa20a436a3e2a2ffa99a4ff60f49db7fb /lib/erl_interface/src
parent5aa2a77fa90f791e0aec2af9de746a7af6c8d147 (diff)
downloadotp-d9ad7fc091e850d9484e3f1fdf9ede22f9a18e04.tar.gz
otp-d9ad7fc091e850d9484e3f1fdf9ede22f9a18e04.tar.bz2
otp-d9ad7fc091e850d9484e3f1fdf9ede22f9a18e04.zip
Teach Winsock initialization to be thread safe
Diffstat (limited to 'lib/erl_interface/src')
-rw-r--r--lib/erl_interface/src/connect/ei_connect.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/erl_interface/src/connect/ei_connect.c b/lib/erl_interface/src/connect/ei_connect.c
index e191f3fbf0..99ccba0686 100644
--- a/lib/erl_interface/src/connect/ei_connect.c
+++ b/lib/erl_interface/src/connect/ei_connect.c
@@ -366,16 +366,16 @@ static int initWinSock(void)
WORD wVersionRequested;
WSADATA wsaData;
int i;
- /* FIXME problem for threaded ? */
- static int initialized = 0;
+
+ static LONG volatile initialized = 0;
wVersionRequested = MAKEWORD(1, 1);
- if (!initialized) {
- initialized = 1;
+ if (InterlockedCompareExchange((LPLONG) &initialized,1L,0L) == 0L) {
/* FIXME not terminate, just a message?! */
if ((i = WSAStartup(wVersionRequested, &wsaData))) {
EI_TRACE_ERR1("ei_connect_init",
"ERROR: can't initialize windows sockets: %d",i);
+ initialized = 2L;
return 0;
}
@@ -383,10 +383,14 @@ static int initWinSock(void)
EI_TRACE_ERR0("initWinSock","ERROR: this version of windows "
"sockets not supported");
WSACleanup();
+ initialized = 2L;
return 0;
}
+ initialized = 3L;
+ } else while (initialized < 2) {
+ SwitchToThread();
}
- return 1;
+ return (int) (initialized - 2);
}
#endif