From 6cb7e8dab67e8807aad79c3bdc8f96d78a5e5dbc Mon Sep 17 00:00:00 2001 From: Owen Shepherd Date: Thu, 8 Nov 2012 23:21:37 +0000 Subject: [PATCH] PDCLIB-15: fopen initializes stream lock; fclose releases --- functions/stdio/_PDCLIB_fdopen.c | 6 ++++++ functions/stdio/fclose.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/functions/stdio/_PDCLIB_fdopen.c b/functions/stdio/_PDCLIB_fdopen.c index 8556327..7b53952 100644 --- a/functions/stdio/_PDCLIB_fdopen.c +++ b/functions/stdio/_PDCLIB_fdopen.c @@ -39,6 +39,12 @@ struct _PDCLIB_file_t * _PDCLIB_fdopen( _PDCLIB_fd_t fd, /* no memory */ return NULL; } + + if(mtx_init(&rc->lock, mtx_recursive) != thrd_success) { + free(rc); + return NULL; + } + rc->status = mode; rc->handle = fd; /* Setting pointers into the memory block allocated above */ diff --git a/functions/stdio/fclose.c b/functions/stdio/fclose.c index d20cb3e..dbd7f6e 100644 --- a/functions/stdio/fclose.c +++ b/functions/stdio/fclose.c @@ -33,8 +33,13 @@ int fclose( struct _PDCLIB_file_t * stream ) return EOF; } } + + /* Release mutex*/ + mtx_destroy( &stream->lock ); + /* Close handle */ _PDCLIB_close( stream->handle ); + /* Remove stream from list */ if ( previous != NULL ) { -- 2.40.0