From 50b4d44ba8e29401f44548a9751f52020f72d91d Mon Sep 17 00:00:00 2001 From: oetiker Date: Thu, 16 Oct 2008 21:05:51 +0000 Subject: [PATCH] move rrd_lock into rrd_open where the general rrd_file ops are located. -- Daniel Pocock git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1612 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/src/rrd_open.c | 35 +++++++++++++++++++++++++++++++++++ program/src/rrd_update.c | 35 ----------------------------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/program/src/rrd_open.c b/program/src/rrd_open.c index f262413b..e407acc1 100644 --- a/program/src/rrd_open.c +++ b/program/src/rrd_open.c @@ -351,6 +351,41 @@ void mincore_print( } #endif /* defined DEBUG && DEBUG > 1 */ +/* + * get exclusive lock to whole file. + * lock gets removed when we close the file + * + * returns 0 on success + */ +int rrd_lock( + rrd_file_t *file) +{ + int rcstat; + + { +#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) + struct _stat st; + + if (_fstat(file->fd, &st) == 0) { + rcstat = _locking(file->fd, _LK_NBLCK, st.st_size); + } else { + rcstat = -1; + } +#else + struct flock lock; + + lock.l_type = F_WRLCK; /* exclusive write lock */ + lock.l_len = 0; /* whole file */ + lock.l_start = 0; /* start of file */ + lock.l_whence = SEEK_SET; /* end of file */ + + rcstat = fcntl(file->fd, F_SETLK, &lock); +#endif + } + + return (rcstat); +} + /* drop cache except for the header and the active pages */ void rrd_dontneed( diff --git a/program/src/rrd_update.c b/program/src/rrd_update.c index 5e26055a..108dcbb0 100644 --- a/program/src/rrd_update.c +++ b/program/src/rrd_update.c @@ -616,41 +616,6 @@ int _rrd_update( return -1; } -/* - * get exclusive lock to whole file. - * lock gets removed when we close the file - * - * returns 0 on success - */ -int rrd_lock( - rrd_file_t *file) -{ - int rcstat; - - { -#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) - struct _stat st; - - if (_fstat(file->fd, &st) == 0) { - rcstat = _locking(file->fd, _LK_NBLCK, st.st_size); - } else { - rcstat = -1; - } -#else - struct flock lock; - - lock.l_type = F_WRLCK; /* exclusive write lock */ - lock.l_len = 0; /* whole file */ - lock.l_start = 0; /* start of file */ - lock.l_whence = SEEK_SET; /* end of file */ - - rcstat = fcntl(file->fd, F_SETLK, &lock); -#endif - } - - return (rcstat); -} - /* * Allocate some important arrays used, and initialize the template. * -- 2.30.2