michael@0: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * This test program demonstrates that PR_ExitMonitor needs to add a michael@0: * reference to the PRMonitor object before unlocking the internal michael@0: * mutex. michael@0: */ michael@0: michael@0: #include "prlog.h" michael@0: #include "prmon.h" michael@0: #include "prthread.h" michael@0: michael@0: #include michael@0: #include michael@0: michael@0: /* Protected by the PRMonitor 'mon' in the main function. */ michael@0: static PRBool done = PR_FALSE; michael@0: michael@0: static void ThreadFunc(void *arg) michael@0: { michael@0: PRMonitor *mon = (PRMonitor *)arg; michael@0: PRStatus rv; michael@0: michael@0: PR_EnterMonitor(mon); michael@0: done = PR_TRUE; michael@0: rv = PR_Notify(mon); michael@0: PR_ASSERT(rv == PR_SUCCESS); michael@0: rv = PR_ExitMonitor(mon); michael@0: PR_ASSERT(rv == PR_SUCCESS); michael@0: } michael@0: michael@0: int main() michael@0: { michael@0: PRMonitor *mon; michael@0: PRThread *thread; michael@0: PRStatus rv; michael@0: michael@0: mon = PR_NewMonitor(); michael@0: if (!mon) { michael@0: fprintf(stderr, "PR_NewMonitor failed\n"); michael@0: exit(1); michael@0: } michael@0: michael@0: thread = PR_CreateThread(PR_USER_THREAD, ThreadFunc, mon, michael@0: PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, michael@0: PR_JOINABLE_THREAD, 0); michael@0: if (!thread) { michael@0: fprintf(stderr, "PR_CreateThread failed\n"); michael@0: exit(1); michael@0: } michael@0: michael@0: PR_EnterMonitor(mon); michael@0: while (!done) { michael@0: rv = PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT); michael@0: PR_ASSERT(rv == PR_SUCCESS); michael@0: } michael@0: rv = PR_ExitMonitor(mon); michael@0: PR_ASSERT(rv == PR_SUCCESS); michael@0: michael@0: /* michael@0: * Do you agree it should be safe to destroy 'mon' now? michael@0: * See bug 844784 comment 27. michael@0: */ michael@0: PR_DestroyMonitor(mon); michael@0: michael@0: rv = PR_JoinThread(thread); michael@0: PR_ASSERT(rv == PR_SUCCESS); michael@0: michael@0: printf("PASS\n"); michael@0: return 0; michael@0: }