Deleted Added
full compact
thr_once.c (220888) thr_once.c (287556)
1/*
2 * Copyright (c) 2005, David Xu <davidxu@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
1/*
2 * Copyright (c) 2005, David Xu <davidxu@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/lib/libthr/thread/thr_once.c 220888 2011-04-20 14:19:34Z rstone $
26 * $FreeBSD: head/lib/libthr/thread/thr_once.c 287556 2015-09-08 08:41:07Z kib $
27 *
28 */
29
30#include "namespace.h"
31#include <pthread.h>
32#include "un-namespace.h"
33
34#include "thr_private.h"

--- 28 unchanged lines hidden (view full) ---

63{
64 struct pthread *curthread;
65 int state;
66
67 _thr_check_init();
68
69 for (;;) {
70 state = once_control->state;
27 *
28 */
29
30#include "namespace.h"
31#include <pthread.h>
32#include "un-namespace.h"
33
34#include "thr_private.h"

--- 28 unchanged lines hidden (view full) ---

63{
64 struct pthread *curthread;
65 int state;
66
67 _thr_check_init();
68
69 for (;;) {
70 state = once_control->state;
71 if (state == ONCE_DONE)
71 if (state == ONCE_DONE) {
72 atomic_thread_fence_acq();
72 return (0);
73 return (0);
74 }
73 if (state == ONCE_NEVER_DONE) {
75 if (state == ONCE_NEVER_DONE) {
74 if (atomic_cmpset_acq_int(&once_control->state, state, ONCE_IN_PROGRESS))
76 if (atomic_cmpset_int(&once_control->state, state, ONCE_IN_PROGRESS))
75 break;
76 } else if (state == ONCE_IN_PROGRESS) {
77 break;
78 } else if (state == ONCE_IN_PROGRESS) {
77 if (atomic_cmpset_acq_int(&once_control->state, state, ONCE_WAIT))
79 if (atomic_cmpset_int(&once_control->state, state, ONCE_WAIT))
78 _thr_umtx_wait_uint(&once_control->state, ONCE_WAIT, NULL, 0);
79 } else if (state == ONCE_WAIT) {
80 _thr_umtx_wait_uint(&once_control->state, state, NULL, 0);
81 } else
82 return (EINVAL);
83 }
84
85 curthread = _get_curthread();

--- 14 unchanged lines hidden ---
80 _thr_umtx_wait_uint(&once_control->state, ONCE_WAIT, NULL, 0);
81 } else if (state == ONCE_WAIT) {
82 _thr_umtx_wait_uint(&once_control->state, state, NULL, 0);
83 } else
84 return (EINVAL);
85 }
86
87 curthread = _get_curthread();

--- 14 unchanged lines hidden ---