variato gestione funzioni di lock/unlock per incrementare le prestazioni

This commit is contained in:
lejubila
2017-09-18 18:55:52 +02:00
parent 6afdb24d82
commit 4b690b4b7f
2 changed files with 9 additions and 9 deletions

View File

@@ -6,6 +6,7 @@
- Fix problem with cron management on similar type cron - Fix problem with cron management on similar type cron
- Fix bug: in case of rain the weather data were not updated - Fix bug: in case of rain the weather data were not updated
- Fix bug: delete the temporary files for managing the socket server messages that were kept on the system - Fix bug: delete the temporary files for managing the socket server messages that were kept on the system
- Change manage of the lock/unlock function for encrase performance (do you need manualy remove the file /var/shm/piGarden.lock or /tmp/piGarden.lock)
## 0.4.4 - 17/06/2017 ## 0.4.4 - 17/06/2017
- Remove lock/unlock from init function for resove bug - Remove lock/unlock from init function for resove bug

View File

@@ -658,16 +658,12 @@ list_descendants ()
# #
function lock { function lock {
sleep 0.$((100 * $RANDOM / 32767)) | $SED 's/..$/.&/'
local max_time=10 local max_time=10
local current_time=$(($1 + 1)) local current_time=$(($1 + 1))
local lock_content=`cat "$LOCK_FILE" 2> /dev/null` if mkdir "${LOCK_FILE}" &>/dev/null; then
if [ -z $lock_content ]; then local foo=bar
lock_content="0" else
fi
if [ "$lock_content" -eq "1" ]; then
if [ "$current_time" -gt "$max_time" ]; then if [ "$current_time" -gt "$max_time" ]; then
log_write "Maximum locked time reached" log_write "Maximum locked time reached"
sleep $max_time sleep $max_time
@@ -679,19 +675,22 @@ function lock {
lock $current_time lock $current_time
return return
fi fi
echo "1" > "$LOCK_FILE"
} }
# #
# Chidue un lock # Chidue un lock
# #
function unlock { function unlock {
echo "0" > "$LOCK_FILE" rmdir "${LOCK_FILE}" &>/dev/null
} }
# #
# Invia l'identificativo univoco ad uso statistico di utilizzo # Invia l'identificativo univoco ad uso statistico di utilizzo
# #