From: Simone Piccardi Date: Mon, 6 Jan 2003 22:46:42 +0000 (+0000) Subject: Correzioni alle funzioni di locking X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=commitdiff_plain;h=e77571fc3b2e3083b4f819a9626d2be454456fab;hp=2c87ecb104050dd0cd78865a5390d8635b989b1a Correzioni alle funzioni di locking --- diff --git a/ipc.tex b/ipc.tex index bf63e66..6cb8cc4 100644 --- a/ipc.tex +++ b/ipc.tex @@ -3387,23 +3387,17 @@ leggermente pi \footnotesize \centering \begin{minipage}[c]{15cm} \begin{lstlisting}{} -/* - * Function CreateMutex: Create a mutex using file locking. - */ +/* Function CreateMutex: Create a mutex using file locking. */ int CreateMutex(const char *path_name) { return open(path_name, O_EXCL|O_CREAT); } -/* - * Function UnlockMutex: unlock a file. - */ +/* Function UnlockMutex: unlock a file. */ int FindMutex(const char *path_name) { return open(path_name, O_RDWR); } -/* - * Function LockMutex: lock mutex using file locking. - */ +/* Function LockMutex: lock mutex using file locking. */ int LockMutex(int fd) { struct flock lock; /* file lock structure */ @@ -3416,9 +3410,7 @@ int LockMutex(int fd) /* do locking */ return fcntl(fd, F_SETLKW, &lock); } -/* - * Function UnlockMutex: unlock a file. - */ +/* Function UnlockMutex: unlock a file. */ int UnlockMutex(int fd) { struct flock lock; /* file lock structure */ @@ -3430,16 +3422,12 @@ int UnlockMutex(int fd) /* do locking */ return fcntl(fd, F_SETLK, &lock); } -/* - * Function RemoveMutex: remove a mutex (unlinking the lock file). - */ +/* Function RemoveMutex: remove a mutex (unlinking the lock file). */ int RemoveMutex(const char *path_name) { return unlink(path_name); } -/* - * Function ReadMutex: read a mutex status. - */ +/* Function ReadMutex: read a mutex status. */ int ReadMutex(int fd) { int res; @@ -3463,11 +3451,14 @@ int ReadMutex(int fd) \label{fig:ipc_flock_mutex} \end{figure} -Il codice per implementare un mutex utilizzando il file -locking\index{file!locking} è riportato in \figref{fig:ipc_flock_mutex}; a -differenza del precedente caso in cui si sono usati i semafori le funzioni -questa volta sono sufficienti due funzioni, \func{LockMutex} e -\func{UnlockMutex}, usate rispettivamente per acquisire e rilasciare il mutex. +Il codice delle varie funzioni definite per implementare un mutex utilizzando +il file locking\index{file!locking} è riportato in +\figref{fig:ipc_flock_mutex}; si è mantenuta una struttura analoga a quelle +viste in precedenza, anche se le due interfacce non possono essere +completamente equivalenti, specie per quanto riguarda la rimozione del mutex. + + + La prima funzione (\texttt{\small 1--22}) serve per acquisire il mutex. Anzitutto si apre (\texttt{\small 9--11}), creandolo se non esiste, il file