Back to index

lightning-sunbird  0.9+nobinonly
atomic.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037  
00038 #include "prio.h"
00039 #include "prprf.h"
00040 #include "pratom.h"
00041 
00042 PRIntn main(PRIntn argc, char **argv)
00043 {
00044     PRInt32 rv, oldval, test, result = 0;
00045     PRFileDesc *output = PR_GetSpecialFD(PR_StandardOutput);
00046 
00047     oldval = test = -2;
00048     rv = PR_AtomicIncrement(&test);
00049     result = result | ((rv == -1) ? 0 : 1);
00050     PR_fprintf(
00051         output, "PR_AtomicIncrement(%d) == %d: %s\n",
00052         oldval, rv, (rv == -1) ? "PASSED" : "FAILED");
00053     oldval = test;
00054     rv = PR_AtomicIncrement(&test);
00055     result = result | ((rv == 0) ? 0 : 1);
00056     PR_fprintf(
00057         output, "PR_AtomicIncrement(%d) == %d: %s\n",
00058         oldval, rv, (rv == 0) ? "PASSED" : "FAILED");
00059     oldval = test;
00060     rv = PR_AtomicIncrement(&test);
00061     result = result | ((rv == 1) ? 0 : 1);
00062     PR_fprintf(
00063         output, "PR_AtomicIncrement(%d) == %d: %s\n",
00064         oldval, rv, (rv == 1) ? "PASSED" : "FAILED");
00065 
00066     oldval = test = -2;
00067     rv = PR_AtomicAdd(&test,1);
00068     result = result | ((rv == -1) ? 0 : 1);
00069     PR_fprintf(
00070         output, "PR_AtomicAdd(%d,%d) == %d: %s\n",
00071         oldval, 1, rv, (rv == -1) ? "PASSED" : "FAILED");
00072     oldval = test;
00073     rv = PR_AtomicAdd(&test, 4);
00074     result = result | ((rv == 3) ? 0 : 1);
00075     PR_fprintf(
00076         output, "PR_AtomicAdd(%d,%d) == %d: %s\n",
00077         oldval, 4, rv, (rv == 3) ? "PASSED" : "FAILED");
00078     oldval = test;
00079     rv = PR_AtomicAdd(&test, -6);
00080     result = result | ((rv == -3) ? 0 : 1);
00081     PR_fprintf(
00082         output, "PR_AtomicAdd(%d,%d) == %d: %s\n",
00083         oldval, -6, rv, (rv == -3) ? "PASSED" : "FAILED");
00084 
00085     oldval = test = 2;
00086     rv = PR_AtomicDecrement(&test);
00087     result = result | ((rv == 1) ? 0 : 1);
00088     PR_fprintf(
00089         output, "PR_AtomicDecrement(%d) == %d: %s\n",
00090         oldval, rv, (rv == 1) ? "PASSED" : "FAILED");
00091     oldval = test;
00092     rv = PR_AtomicDecrement(&test);
00093     result = result | ((rv == 0) ? 0 : 1);
00094     PR_fprintf(
00095         output, "PR_AtomicDecrement(%d) == %d: %s\n",
00096         oldval, rv, (rv == 0) ? "PASSED" : "FAILED");
00097     oldval = test;
00098     rv = PR_AtomicDecrement(&test);
00099     result = result | ((rv == -1) ? 0 : 1);
00100     PR_fprintf(
00101         output, "PR_AtomicDecrement(%d) == %d: %s\n",
00102         oldval, rv, (rv == -1) ? "PASSED" : "FAILED");
00103 
00104     /* set to a different value */
00105     oldval = test = -2;
00106     rv = PR_AtomicSet(&test, 2);
00107     result = result | (((rv == -2) && (test == 2)) ? 0 : 1);
00108     PR_fprintf(
00109         output, "PR_AtomicSet(%d, %d) == %d: %s\n",
00110         oldval, 2, rv, ((rv == -2) && (test == 2)) ? "PASSED" : "FAILED");
00111 
00112     /* set to the same value */
00113     oldval = test = -2;
00114     rv = PR_AtomicSet(&test, -2);
00115     result = result | (((rv == -2) && (test == -2)) ? 0 : 1);
00116     PR_fprintf(
00117         output, "PR_AtomicSet(%d, %d) == %d: %s\n",
00118         oldval, -2, rv, ((rv == -2) && (test == -2)) ? "PASSED" : "FAILED");
00119 
00120     PR_fprintf(
00121         output, "Atomic operations test %s\n",
00122         (result == 0) ? "PASSED" : "FAILED");
00123     return result;
00124 }  /* main */
00125 
00126 /* atomic.c */