/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* usr/src/OPENSOLARIS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your
* own identifying information: Portions Copyright [yyyy]
* [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* The "cascade" test case is a multiprocess/multithread batten-passing model
* using lock primitives alone for synchronisation. Threads are arranged in a
* ring. Each thread has two locks of its own on which it blocks, and is able
* to manipulate the two locks belonging to the thread which follows it in the
* ring.
*
* The number of threads (nthreads) is specified by the generic libMicro -P/-T
* options. With nthreads == 1 (the default) the uncontended case can be timed.
*
* The main logic is generic and allows any simple blocking API to be tested.
* The API-specific component is clearly indicated.
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include "libmicro.h"
typedef struct {
int ts_once;
int ts_id;
int ts_us1;
int ts_them1;
} tsd_t;
static int nthreads;
/*
* API-specific code BEGINS here
*/
static int opts = 0;
static int nlocks;
int
{
lm_tsdsize = sizeof (tsd_t);
lm_defN = "cscd_mutex";
" [-s] (force PTHREAD_PROCESS_SHARED)\n"
"notes: thread cascade using pthread_mutexes\n");
return (0);
}
/*ARGSUSED*/
int
{
switch (opt) {
case 's':
opts = 1;
break;
default:
return (-1);
}
return (0);
}
int
{
int i;
int e = 0;
/*LINTED*/
nlocks * sizeof (pthread_mutex_t),
-1, 0L);
if (locks == MAP_FAILED) {
return (1);
}
(void) pthread_mutexattr_init(&ma);
(void) pthread_mutexattr_setpshared(&ma,
} else {
(void) pthread_mutexattr_setpshared(&ma,
}
for (i = 0; i < nlocks; i++) {
}
return (e);
}
int
{
}
int
{
}
/*
* API-specific code ENDS here
*/
int
{
int e = 0;
/* lock index asignment for us and them */
/* straight-thru connection to them */
} else {
/* cross-over connection to them */
}
}
/* block their first move */
return (e);
}
int
{
int i;
int e = 0;
/* wait to be unblocked (id == 0 will not block) */
for (i = 0; i < lm_optB; i += 2) {
/* allow them to block us again */
/* block their next + 1 move */
/* unblock their next move */
/* wait for them to unblock us */
/* repeat with locks reversed */
}
/* finish batch with nothing blocked */
return (0);
}