]> pd.if.org Git - pdclib.old/commitdiff
PDCLIB-15: fopen initializes stream lock; fclose releases
authorOwen Shepherd <owen.shepherd@e43.eu>
Thu, 8 Nov 2012 23:21:37 +0000 (23:21 +0000)
committerOwen Shepherd <owen.shepherd@e43.eu>
Thu, 8 Nov 2012 23:21:37 +0000 (23:21 +0000)
functions/stdio/_PDCLIB_fdopen.c
functions/stdio/fclose.c

index 85563270fa5029c7d4dbe73971c8bb273f375f30..7b539528f8a91b97c791b582aece80998962e94b 100644 (file)
@@ -39,6 +39,12 @@ struct _PDCLIB_file_t * _PDCLIB_fdopen( _PDCLIB_fd_t fd,
         /* no memory */\r
         return NULL;\r
     }\r
+\r
+    if(mtx_init(&rc->lock, mtx_recursive) != thrd_success) {\r
+        free(rc);\r
+        return NULL;\r
+    }\r
+\r
     rc->status = mode;\r
     rc->handle = fd;\r
     /* Setting pointers into the memory block allocated above */\r
index d20cb3e90a95a5c5d82b4967ff383fff9e95b7ca..dbd7f6eebbf12199ea8d7a80bbaf566f11035115 100644 (file)
@@ -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 )
             {