annotate src/lock.c @ 183:c912e8288164 noffle

[svn] * src/client.c: Only bail out of fetching multiple articles if the connection fails. If we do get a status from the upstream server note it and see what is reported for the next article. Otherwise failure to retrieve one article will cause all successive article fetches to fail even through they would succeed if tried. * src/lock.c: Fix assert in lazy locking. If another noffle signalled us to release the lock at the next close, and then repeats the signal so that it arrives during LOCK_closeDatabases, the signal handler was trying to close the databases again.
author bears
date Tue, 15 May 2001 13:07:53 +0100
parents 7ba337dafb2c
children fed1334d766b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
1 /*
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
2 lock.c
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
3
183
c912e8288164 [svn] * src/client.c: Only bail out of fetching multiple articles if the
bears
parents: 167
diff changeset
4 $Id: lock.c 292 2001-05-15 12:07:53Z bears $
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
5 */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
6
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
7 #if HAVE_CONFIG_H
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
8 #include <config.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
9 #endif
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
10
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
11 #include <stdio.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
12 #include "lock.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
13 #include <errno.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
14 #include <ctype.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
15 #include <sys/types.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
16 #include <sys/stat.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
17 #include <fcntl.h>
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
18 #include <signal.h>
54
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
19
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
20 #if TIME_WITH_SYS_TIME
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
21 #include <sys/time.h>
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
22 #include <time.h>
54
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
23 #else
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
24 #if HAVE_SYS_TIME_H
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
25 #include <sys/time.h>
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
26 #else
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
27 #include <time.h>
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
28 #endif
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
29 #endif
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
30
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
31 #include <unistd.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
32 #include "configfile.h"
167
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 165
diff changeset
33 #include "content.h"
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
34 #include "log.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
35 #include "database.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
36 #include "group.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
37 #include "request.h"
54
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
38 #include "portable.h"
167
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 165
diff changeset
39 #include "server.h"
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
40 #include "util.h"
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
41
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
42 struct Lock
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
43 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
44 const char *name;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
45 int lockFd;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
46 Str lockFile;
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
47 Bool doLazyLocking;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
48 volatile Bool lazyClose;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
49 volatile Bool lazyLockBusy;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
50 };
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
51
167
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 165
diff changeset
52 static struct Lock globalLock = { "global", -1, "", TRUE, FALSE, FALSE };
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 165
diff changeset
53 static struct Lock fetchLock = { "fetch", -1, "", FALSE, FALSE, FALSE };
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
54
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
55 static sig_t oldHandler = NULL;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
56
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
57 /* Block/unblock SIGUSR1. */
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
58 static Bool
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
59 blockSignal( Bool block )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
60 {
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
61 sigset_t sigs;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
62
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
63 sigemptyset(&sigs);
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
64 sigaddset(&sigs, SIGUSR1);
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
65
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
66 for(;;)
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
67 {
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
68 if ( sigprocmask( block ? SIG_BLOCK : SIG_UNBLOCK, &sigs, NULL ) != 0 )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
69 {
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
70 if ( errno != EINTR )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
71 {
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
72 Log_err( "Can't block/unblock signal" );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
73 return FALSE;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
74 }
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
75 }
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
76 else
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
77 return TRUE;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
78 }
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
79 /* NOTREACHED */
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
80 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
81
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
82 /* Check the global lock held. */
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
83 static Bool
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
84 gotLock( struct Lock *lock )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
85 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
86 return ( lock->lockFd != -1 );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
87 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
88
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
89 static void
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
90 lockWaitAlarm( int sig )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
91 {
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
92 UNUSED( sig );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
93
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
94 return;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
95 }
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
96
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
97 static Bool
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
98 waitLock( struct Lock *lock, enum LockRequestWait wait )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
99 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
100 int fd;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
101 struct flock l;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
102
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
103 ASSERT( ! gotLock( lock ) );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
104 Log_dbg( "Waiting for lock %s ...", lock->name );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
105 if ( lock->lockFile[ 0 ] == '\0' )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
106 snprintf( lock->lockFile, MAXCHAR, "%s/lock/%s",
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
107 Cfg_spoolDir(), lock->name );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
108 if ( ( fd = open( lock->lockFile, O_WRONLY | O_CREAT, 0644 ) ) < 0 )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
109 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
110 Log_err( "Cannot open %s (%s)", lock->lockFile, strerror( errno ) );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
111 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
112 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
113 l.l_type = F_WRLCK;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
114 l.l_start = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
115 l.l_whence = SEEK_SET;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
116 l.l_len = 0;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
117 if ( wait == LOCK_WAIT )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
118 {
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
119 sig_t oldAlarmHandler;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
120 unsigned oldAlarm;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
121
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
122 oldAlarmHandler = Utl_installSignalHandler( SIGALRM, lockWaitAlarm );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
123 oldAlarm = alarm( 1 );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
124 for(;;)
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
125 {
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
126 alarm( 1 );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
127 if ( fcntl( fd, F_SETLKW, &l ) < 0 )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
128 if ( errno != EINTR )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
129 {
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
130 Utl_installSignalHandler( SIGALRM, oldAlarmHandler );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
131 alarm( oldAlarm );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
132 Log_err( "Cannot lock %s: %s", lock->lockFile,
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
133 strerror( errno ) );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
134 close( lock->lockFd );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
135 return FALSE;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
136 }
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
137 else
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
138 {
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
139 /* Send SIGUSR1 to the process holding the lock. */
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
140 if ( fcntl( fd, F_GETLK, &l) == 0 && l.l_type != F_UNLCK )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
141 if ( kill( l.l_pid, SIGUSR1 ) < 0 )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
142 Log_err( "Can't signal process %d: %s", l.l_pid,
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
143 strerror( errno ) );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
144 }
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
145 else
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
146 break;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
147 }
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
148 Utl_installSignalHandler( SIGALRM, oldAlarmHandler );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
149 alarm( oldAlarm );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
150 }
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
151 else
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
152 {
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
153 if ( fcntl( fd, F_SETLK, &l ) < 0 )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
154 {
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
155 close( lock->lockFd );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
156 return FALSE;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
157 }
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
158 }
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
159
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
160 lock->lockFd = fd;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
161 Log_dbg( "Lock successful" );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
162 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
163 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
164
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
165 static void
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
166 releaseLock( struct Lock *lock )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
167 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
168 struct flock l;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
169
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
170 ASSERT( gotLock( lock ) );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
171 l.l_type = F_UNLCK;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
172 l.l_start = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
173 l.l_whence = SEEK_SET;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
174 l.l_len = 0;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
175 if ( fcntl( lock->lockFd, F_SETLK, &l ) < 0 )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
176 Log_err( "Cannot release %s: %s", lock->lockFile,
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
177 strerror( errno ) );
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
178 close( lock->lockFd );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
179 lock->lockFd = -1;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
180 Log_dbg( "Releasing lock" );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
181 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
182
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
183 static Bool
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
184 openDatabases( void )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
185 {
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
186 globalLock.lazyClose = FALSE;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
187 if ( ! waitLock( &globalLock, LOCK_WAIT ) )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
188 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
189 Log_err( "Could not get write lock" );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
190 return FALSE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
191 }
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
192 if ( ! Db_open() )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
193 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
194 Log_err( "Could not open database" );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
195 releaseLock( &globalLock );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
196 return FALSE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
197 }
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
198 if ( ! Grp_open() )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
199 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
200 Log_err( "Could not open groupinfo" );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
201 Db_close();
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
202 releaseLock( &globalLock );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
203 return FALSE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
204 }
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
205 if ( ! Req_open() )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
206 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
207 Log_err( "Could not initialize request database" );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
208 Grp_close();
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
209 Db_close();
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
210 releaseLock( &globalLock );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
211 return FALSE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
212 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
213
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
214 globalLock.lazyClose = globalLock.doLazyLocking;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
215 globalLock.lazyLockBusy = TRUE;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
216 return TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
217 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
218
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
219 static void
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
220 closeDatabases( void )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
221 {
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
222 Grp_close();
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
223 Db_close();
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
224 Req_close();
167
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 165
diff changeset
225 Server_flushCache();
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
226 releaseLock( &globalLock );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
227 globalLock.lazyLockBusy = FALSE;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
228 globalLock.lazyClose = FALSE;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
229 }
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
230
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
231 static void
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
232 lockSignal( int sig )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
233 {
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
234 UNUSED( sig );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
235
183
c912e8288164 [svn] * src/client.c: Only bail out of fetching multiple articles if the
bears
parents: 167
diff changeset
236 /*
c912e8288164 [svn] * src/client.c: Only bail out of fetching multiple articles if the
bears
parents: 167
diff changeset
237 * If we hold the lock right now, flag it to be released next close.
c912e8288164 [svn] * src/client.c: Only bail out of fetching multiple articles if the
bears
parents: 167
diff changeset
238 * Otherwise, if we are holding it lazily, release it.
c912e8288164 [svn] * src/client.c: Only bail out of fetching multiple articles if the
bears
parents: 167
diff changeset
239 */
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
240 if ( globalLock.lazyLockBusy )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
241 globalLock.lazyClose = FALSE;
183
c912e8288164 [svn] * src/client.c: Only bail out of fetching multiple articles if the
bears
parents: 167
diff changeset
242 else if ( gotLock( &globalLock ) )
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
243 closeDatabases();
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
244 return;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
245 }
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
246
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
247 /* Open all databases and set global lock. */
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
248 Bool
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
249 Lock_openDatabases( void )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
250 {
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
251 Bool res;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
252
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
253 /* First time - need to initialise signal handler? */
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
254 if ( oldHandler == NULL )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
255 oldHandler = Utl_installSignalHandler( SIGUSR1, lockSignal );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
256
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
257 if ( ! blockSignal( TRUE ) )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
258 return FALSE;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
259
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
260 if ( ! globalLock.lazyClose )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
261 res = openDatabases();
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
262 else
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
263 res = TRUE;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
264
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
265 globalLock.lazyLockBusy = res;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
266
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
267 if ( ! blockSignal( FALSE ) )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
268 return FALSE;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
269
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
270 return res;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
271 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
272
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
273 /* Close all databases and release global lock. */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
274 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
275 Lock_closeDatabases( void )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
276 {
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
277 blockSignal( TRUE );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
278
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
279 if ( ! globalLock.lazyClose )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
280 closeDatabases();
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
281 else
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
282 globalLock.lazyLockBusy = FALSE;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
283
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
284 blockSignal( FALSE );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
285 }
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
286
183
c912e8288164 [svn] * src/client.c: Only bail out of fetching multiple articles if the
bears
parents: 167
diff changeset
287 /* Sync all databases to disc. Maintain global lock status. */
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
288 void
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
289 Lock_syncDatabases( void )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
290 {
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
291 Bool wasOpen;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
292
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
293 if ( gotLock( &globalLock ) )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
294 {
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
295 blockSignal( TRUE );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
296
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
297 wasOpen = globalLock.lazyLockBusy;
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
298 closeDatabases();
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
299 if ( wasOpen )
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
300 openDatabases();
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
301
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
302 blockSignal( FALSE );
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
303 }
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
304 }
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
305
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
306 /* Check the global lock held. */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
307 Bool
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
308 Lock_gotLock( void )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
309 {
165
8ea6b5ddc5a5 [svn] * src/lock.h,src/lock.c,src/noffle.c: Add lazy lock release. Only release
bears
parents: 127
diff changeset
310 return globalLock.lazyLockBusy;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
311 }
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
312
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
313 /* Get fetch lock. */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
314 Bool
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
315 Lock_getFetchLock( enum LockRequestWait wait )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
316 {
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
317 return waitLock( &fetchLock, wait );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
318 }
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
319
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
320 /* Release fetch lock. */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
321 void
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
322 Lock_releaseFetchLock( void )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
323 {
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
324 releaseLock( &fetchLock );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
325 }
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
326
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
327 /* Check the fetch lock held. */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
328 Bool
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
329 Lock_fetchLock( void )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
330 {
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
331 return gotLock( &fetchLock );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
332 }
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 54
diff changeset
333