summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/stdio/sopenw.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-03-11 00:48:35 +0100
committercinap_lenrek <cinap_lenrek@gmx.de>2013-03-11 00:48:35 +0100
commit48b0c10681bb4e0785fa9f737d287531d06fecb7 (patch)
tree568f7cdd23400f1e781b82aa044ad39748ff9d78 /sys/src/ape/lib/ap/stdio/sopenw.c
parent530a2bc5e99ad83c46ce015544cf30173c145bcc (diff)
ape/stdio: make fopen() quasi threadsafe for python
python uses processes sharing memory. it requires at least fopen() to be called by multiple threads at once so we introduce _IO_newfile() which allocates the FILE structure slot under a lock.
Diffstat (limited to 'sys/src/ape/lib/ap/stdio/sopenw.c')
-rw-r--r--sys/src/ape/lib/ap/stdio/sopenw.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/sys/src/ape/lib/ap/stdio/sopenw.c b/sys/src/ape/lib/ap/stdio/sopenw.c
index d13634333..4973da357 100644
--- a/sys/src/ape/lib/ap/stdio/sopenw.c
+++ b/sys/src/ape/lib/ap/stdio/sopenw.c
@@ -5,8 +5,9 @@
FILE *_IO_sopenw(void){
FILE *f;
- for(f=_IO_stream;f!=&_IO_stream[FOPEN_MAX];f++) if(f->state==CLOSED) break;
- if(f==&_IO_stream[FOPEN_MAX]) return NULL;
+
+ if((f=_IO_newfile())==NULL)
+ return NULL;
f->buf=f->rp=f->wp=0;
f->state=OPEN;
f->flags=STRING;