Deleted Added
full compact
thr_once.c (287556) thr_once.c (287557)
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 287556 2015-09-08 08:41:07Z kib $
26 * $FreeBSD: head/lib/libthr/thread/thr_once.c 287557 2015-09-08 08:48:53Z kib $
27 *
28 */
29
30#include "namespace.h"
31#include <pthread.h>
32#include "un-namespace.h"
33
34#include "thr_private.h"

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

45 * The pthread_once() function is not a cancellation point. However,
46 * if init_routine is a cancellation point and is canceled, the effect
47 * on once_control shall be as if pthread_once() was never called.
48 */
49
50static void
51once_cancel_handler(void *arg)
52{
27 *
28 */
29
30#include "namespace.h"
31#include <pthread.h>
32#include "un-namespace.h"
33
34#include "thr_private.h"

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

45 * The pthread_once() function is not a cancellation point. However,
46 * if init_routine is a cancellation point and is canceled, the effect
47 * on once_control shall be as if pthread_once() was never called.
48 */
49
50static void
51once_cancel_handler(void *arg)
52{
53 pthread_once_t *once_control = arg;
53 pthread_once_t *once_control;
54
54
55 if (atomic_cmpset_rel_int(&once_control->state, ONCE_IN_PROGRESS, ONCE_NEVER_DONE))
55 once_control = arg;
56 if (atomic_cmpset_rel_int(&once_control->state, ONCE_IN_PROGRESS,
57 ONCE_NEVER_DONE))
56 return;
57 atomic_store_rel_int(&once_control->state, ONCE_NEVER_DONE);
58 _thr_umtx_wake(&once_control->state, INT_MAX, 0);
59}
60
61int
62_pthread_once(pthread_once_t *once_control, void (*init_routine) (void))
63{

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

68
69 for (;;) {
70 state = once_control->state;
71 if (state == ONCE_DONE) {
72 atomic_thread_fence_acq();
73 return (0);
74 }
75 if (state == ONCE_NEVER_DONE) {
58 return;
59 atomic_store_rel_int(&once_control->state, ONCE_NEVER_DONE);
60 _thr_umtx_wake(&once_control->state, INT_MAX, 0);
61}
62
63int
64_pthread_once(pthread_once_t *once_control, void (*init_routine) (void))
65{

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

70
71 for (;;) {
72 state = once_control->state;
73 if (state == ONCE_DONE) {
74 atomic_thread_fence_acq();
75 return (0);
76 }
77 if (state == ONCE_NEVER_DONE) {
76 if (atomic_cmpset_int(&once_control->state, state, ONCE_IN_PROGRESS))
78 if (atomic_cmpset_int(&once_control->state, state,
79 ONCE_IN_PROGRESS))
77 break;
78 } else if (state == ONCE_IN_PROGRESS) {
80 break;
81 } else if (state == ONCE_IN_PROGRESS) {
79 if (atomic_cmpset_int(&once_control->state, state, ONCE_WAIT))
80 _thr_umtx_wait_uint(&once_control->state, ONCE_WAIT, NULL, 0);
82 if (atomic_cmpset_int(&once_control->state, state,
83 ONCE_WAIT))
84 _thr_umtx_wait_uint(&once_control->state,
85 ONCE_WAIT, NULL, 0);
81 } else if (state == ONCE_WAIT) {
86 } else if (state == ONCE_WAIT) {
82 _thr_umtx_wait_uint(&once_control->state, state, NULL, 0);
87 _thr_umtx_wait_uint(&once_control->state, state,
88 NULL, 0);
83 } else
84 return (EINVAL);
85 }
86
87 curthread = _get_curthread();
88 THR_CLEANUP_PUSH(curthread, once_cancel_handler, once_control);
89 init_routine();
90 THR_CLEANUP_POP(curthread, 0);
89 } else
90 return (EINVAL);
91 }
92
93 curthread = _get_curthread();
94 THR_CLEANUP_PUSH(curthread, once_cancel_handler, once_control);
95 init_routine();
96 THR_CLEANUP_POP(curthread, 0);
91 if (atomic_cmpset_rel_int(&once_control->state, ONCE_IN_PROGRESS, ONCE_DONE))
97 if (atomic_cmpset_rel_int(&once_control->state, ONCE_IN_PROGRESS,
98 ONCE_DONE))
92 return (0);
93 atomic_store_rel_int(&once_control->state, ONCE_DONE);
94 _thr_umtx_wake(&once_control->state, INT_MAX, 0);
95 return (0);
96}
97
98void
99 return (0);
100 atomic_store_rel_int(&once_control->state, ONCE_DONE);
101 _thr_umtx_wake(&once_control->state, INT_MAX, 0);
102 return (0);
103}
104
105void
99_thr_once_init()
106_thr_once_init(void)
100{
101}
107{
108}