thr_fsync.c revision 103388
1200581Srdivacky/*
2200581Srdivacky * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
3200581Srdivacky * All rights reserved.
4200581Srdivacky *
5200581Srdivacky * Redistribution and use in source and binary forms, with or without
6200581Srdivacky * modification, are permitted provided that the following conditions
7200581Srdivacky * are met:
8200581Srdivacky * 1. Redistributions of source code must retain the above copyright
9200581Srdivacky *    notice, this list of conditions and the following disclaimer.
10200581Srdivacky * 2. Redistributions in binary form must reproduce the above copyright
11200581Srdivacky *    notice, this list of conditions and the following disclaimer in the
12200581Srdivacky *    documentation and/or other materials provided with the distribution.
13200581Srdivacky * 3. All advertising materials mentioning features or use of this software
14249423Sdim *    must display the following acknowledgement:
15221345Sdim *	This product includes software developed by John Birrell.
16200581Srdivacky * 4. Neither the name of the author nor the names of any co-contributors
17200581Srdivacky *    may be used to endorse or promote products derived from this software
18200581Srdivacky *    without specific prior written permission.
19200581Srdivacky *
20212904Sdim * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
21263508Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22212904Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23200581Srdivacky * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24263508Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25218893Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26263508Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27263508Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28218893Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29218893Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30218893Sdim * SUCH DAMAGE.
31218893Sdim *
32218893Sdim * $FreeBSD: head/lib/libkse/thread/thr_fsync.c 103388 2002-09-16 08:45:36Z mini $
33218893Sdim */
34218893Sdim#include <unistd.h>
35221345Sdim#include <pthread.h>
36221345Sdim#include "thr_private.h"
37221345Sdim
38221345Sdim__weak_reference(__fsync, fsync);
39221345Sdim
40221345Sdimint
41218893Sdim_fsync(int fd)
42218893Sdim{
43263508Sdim	int	ret;
44263508Sdim
45212904Sdim	if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
46263508Sdim		ret = __sys_fsync(fd);
47263508Sdim		_FD_UNLOCK(fd, FD_RDWR);
48263508Sdim	}
49263508Sdim	return (ret);
50221345Sdim}
51221345Sdim
52221345Sdimint
53263508Sdim__fsync(int fd)
54221345Sdim{
55263508Sdim	int	ret;
56263508Sdim
57212904Sdim	_thread_enter_cancellation_point();
58212904Sdim	ret = _fsync(fd);
59263508Sdim	_thread_leave_cancellation_point();
60263508Sdim
61263508Sdim	return ret;
62263508Sdim}
63212904Sdim