michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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: ** michael@0: ** Name: fileio.c michael@0: ** michael@0: ** Description: Program to copy one file to another. michael@0: ** michael@0: ** Modification History: michael@0: ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag. michael@0: ** The debug mode will print all of the printfs associated with this test. michael@0: ** The regress mode will be the default mode. Since the regress tool limits michael@0: ** the output to a one line status:PASS or FAIL,all of the printf statements michael@0: ** have been handled with an if (debug_mode) statement. michael@0: ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to michael@0: ** recognize the return code from tha main program. michael@0: ** 12-June-97 Revert to return code 0 and 1, remove debug option (obsolete). michael@0: ***********************************************************************/ michael@0: michael@0: /*********************************************************************** michael@0: ** Includes michael@0: ***********************************************************************/ michael@0: #include "prinit.h" michael@0: #include "prthread.h" michael@0: #include "prlock.h" michael@0: #include "prcvar.h" michael@0: #include "prmon.h" michael@0: #include "prmem.h" michael@0: #include "prio.h" michael@0: #include "prlog.h" michael@0: michael@0: #include michael@0: michael@0: #include "obsolete/prsem.h" michael@0: michael@0: michael@0: #define TBSIZE 1024 michael@0: michael@0: static PRUint8 tbuf[TBSIZE]; michael@0: michael@0: static PRFileDesc *t1, *t2; michael@0: michael@0: PRIntn failed_already=0; michael@0: PRIntn debug_mode; michael@0: static void InitialSetup(void) michael@0: { michael@0: PRUintn i; michael@0: PRInt32 nWritten, rv; michael@0: michael@0: t1 = PR_Open("t1.tmp", PR_CREATE_FILE | PR_RDWR, 0); michael@0: PR_ASSERT(t1 != NULL); michael@0: michael@0: for (i=0; i= 0) { michael@0: buf[i].nbytes = nbytes; michael@0: PR_PostSem(fullBufs); michael@0: i = (i + 1) % 2; michael@0: } michael@0: } while (nbytes > 0); michael@0: } michael@0: michael@0: static void PR_CALLBACK writer(void *arg) michael@0: { michael@0: PRUintn i = 0; michael@0: PRInt32 nbytes; michael@0: michael@0: do { michael@0: (void) PR_WaitSem(fullBufs); michael@0: nbytes = buf[i].nbytes; michael@0: if (nbytes > 0) { michael@0: nbytes = PR_Write((PRFileDesc*)arg, buf[i].data, nbytes); michael@0: PR_PostSem(emptyBufs); michael@0: i = (i + 1) % 2; michael@0: } michael@0: } while (nbytes > 0); michael@0: } michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PRThread *r, *w; michael@0: michael@0: michael@0: PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); michael@0: PR_STDIO_INIT(); michael@0: michael@0: emptyBufs = PR_NewSem(2); /* two empty buffers */ michael@0: michael@0: fullBufs = PR_NewSem(0); /* zero full buffers */ michael@0: michael@0: /* Create initial temp file setup */ michael@0: InitialSetup(); michael@0: michael@0: /* create the reader thread */ michael@0: michael@0: r = PR_CreateThread(PR_USER_THREAD, michael@0: reader, t1, michael@0: PR_PRIORITY_NORMAL, michael@0: PR_LOCAL_THREAD, michael@0: PR_JOINABLE_THREAD, michael@0: 0); michael@0: michael@0: w = PR_CreateThread(PR_USER_THREAD, michael@0: writer, t2, michael@0: PR_PRIORITY_NORMAL, michael@0: PR_LOCAL_THREAD, michael@0: PR_JOINABLE_THREAD, michael@0: 0); michael@0: michael@0: /* Do the joining for both threads */ michael@0: (void) PR_JoinThread(r); michael@0: (void) PR_JoinThread(w); michael@0: michael@0: /* Do the verification and clean up */ michael@0: VerifyAndCleanup(); michael@0: michael@0: PR_DestroySem(emptyBufs); michael@0: PR_DestroySem(fullBufs); michael@0: michael@0: PR_Cleanup(); michael@0: michael@0: if(failed_already) michael@0: { michael@0: printf("Fail\n"); michael@0: return 1; michael@0: } michael@0: else michael@0: { michael@0: printf("PASS\n"); michael@0: return 0; michael@0: } michael@0: michael@0: michael@0: }