10e552da7Schristos /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
20e552da7Schristos *
30e552da7Schristos * Permission is hereby granted, free of charge, to any person obtaining a copy
40e552da7Schristos * of this software and associated documentation files (the "Software"), to
50e552da7Schristos * deal in the Software without restriction, including without limitation the
60e552da7Schristos * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
70e552da7Schristos * sell copies of the Software, and to permit persons to whom the Software is
80e552da7Schristos * furnished to do so, subject to the following conditions:
90e552da7Schristos *
100e552da7Schristos * The above copyright notice and this permission notice shall be included in
110e552da7Schristos * all copies or substantial portions of the Software.
120e552da7Schristos *
130e552da7Schristos * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
140e552da7Schristos * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
150e552da7Schristos * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
160e552da7Schristos * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
170e552da7Schristos * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
180e552da7Schristos * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
190e552da7Schristos * IN THE SOFTWARE.
200e552da7Schristos */
210e552da7Schristos
220e552da7Schristos #include "uv.h"
230e552da7Schristos #include "task.h"
240e552da7Schristos
250e552da7Schristos uv_thread_t main_thread_id;
260e552da7Schristos uv_thread_t subthreads[2];
270e552da7Schristos
check_thread(void * arg)280e552da7Schristos static void check_thread(void* arg) {
290e552da7Schristos uv_thread_t *thread_id = arg;
300e552da7Schristos uv_thread_t self_id = uv_thread_self();
31*5f2f4271Schristos #ifdef _WIN32
32*5f2f4271Schristos ASSERT_NOT_NULL(self_id);
33*5f2f4271Schristos #endif
340e552da7Schristos ASSERT(uv_thread_equal(&main_thread_id, &self_id) == 0);
350e552da7Schristos *thread_id = uv_thread_self();
360e552da7Schristos }
370e552da7Schristos
TEST_IMPL(thread_equal)380e552da7Schristos TEST_IMPL(thread_equal) {
390e552da7Schristos uv_thread_t threads[2];
400e552da7Schristos main_thread_id = uv_thread_self();
41*5f2f4271Schristos #ifdef _WIN32
42*5f2f4271Schristos ASSERT_NOT_NULL(main_thread_id);
43*5f2f4271Schristos #endif
440e552da7Schristos ASSERT(0 != uv_thread_equal(&main_thread_id, &main_thread_id));
450e552da7Schristos ASSERT(0 == uv_thread_create(threads + 0, check_thread, subthreads + 0));
460e552da7Schristos ASSERT(0 == uv_thread_create(threads + 1, check_thread, subthreads + 1));
470e552da7Schristos ASSERT(0 == uv_thread_join(threads + 0));
480e552da7Schristos ASSERT(0 == uv_thread_join(threads + 1));
490e552da7Schristos ASSERT(0 == uv_thread_equal(subthreads + 0, subthreads + 1));
500e552da7Schristos return 0;
510e552da7Schristos }
52