pfMergeBuffer, uswsetlock, and usunsetlock

New Message Reply Date view Thread view Subject view Author view

Anita Kishore (kishore++at++electrogig.com)
Tue, 30 Jan 1996 16:42:24 -0800


Has anyone tried to use IRIX IPC lock and unlock along with the DBASE process?
My DBASE process hangs at pfMergeBuffer() if the APP and DBASE, both are
using locks asynchronously. Runs fine if I don't let either one of the
processes
use lock/unlock. I have attached a small program which illustrates this.

Is this a bug with pfMergeBuffer() or am I not using IPC calls correctly?

thanks for any help

-anita

--------------------------------------------------------------------
Anita Kishore
kishore++at++electrogig.com
--------------------------------------------------------------------

the .iv file is: (called globe.iv)

#Inventor V2.0 ascii

Separator {
    LightModel {
            model BASE_COLOR
    }
    Complexity { value .5 }
    Material { transparency 0.1 }
    Translation{ translation 36 36 -128 }
    DEF video_node Sphere { radius 35. }
}

Uncomment the lock and unlock functions in the simulation loop to see
the problem.

// program to check if starting performer in a forked process
// causes the DBASE process's pfMergeBuffer to hang
// RESULT : fork and sproc, both work fine!

// Also check if using IRIX IPC causes any trouble

#include <stdlib.h>
#include <sys/types.h>
#include <ulocks.h>
#include <unistd.h>
#include <Performer/pf.h>

typedef struct
{
    int test;
} testStruct;

pfScene **scene;
testStruct *shared;
ulock_t *theLock;
usptr_t *arena;

void startPF();
void pageDBase(void *data);
void createSharedData();
void lock();
void unlock();
void removeSharedData();

int main(int argc, char *argv[])
{

    createSharedData();

/*
    if ( fork() == 0 )
        startPF();
*/

    sproc(startPF, PR_SALL);
    wait(0);

    removeSharedData();

    return 0;

}

void createSharedData()
{
    char *arenafile = "/usr/tmp/testarena";

    usconfig( CONF_LOCKTYPE, US_NODEBUG );
    if ( (arena = usinit(arenafile)) == NULL)
    {
        printf("Unable to create shared arena\n");
        exit(1);
    }
    unlink(arenafile);

    if ( (shared = usmalloc(sizeof(testStruct), arena)) == NULL)
    {
        printf("Unable to allocate space in shared arena\n");
        exit(1);
    }
    shared->test = 0;

    if ( (theLock = (ulock_t*) usnewlock(arena)) == NULL)
    {
        printf("Unable to obtain a new lock\n");
        exit(1);
    }
}

void removeSharedData()
{
    if( theLock ) usfreelock( theLock, arena);
    usfree(shared, arena);
    if (arena) usdetach(arena);
}

void lock()
{
    int ret = uswsetlock( theLock, 0 );
    if (ret == -1) printf("Unable to lock\n");
}

void unlock()
{
    int ret = usunsetlock( theLock );
}

void startPF()
{

    pfPipe *p;
    pfChannel *chan;
    pfCoord view;
    pfPipeWindow *pw;
    int i = 0;

    pfInit();
    scene = (pfScene **) pfMalloc(sizeof(pfScene *), pfGetSharedArena());

    pfConfig();

    *scene = pfNewScene();
    p = pfGetPipe(0);
        pw = pfNewPWin(p);
        pfPWinType(pw, PFWIN_TYPE_X);
        pfPWinName(pw, "Dynamic scene Updation");
        pfPWinOriginSize(pw, 100, 100, 720, 486);
        pfOpenPWin(pw);

        chan = pfNewChan(p);
        pfChanScene(chan, *scene);
        pfChanNearFar(chan, 1.0f, 10000.0f);
        pfChanFOV(chan, 120.0f, -1.0f);
        pfSetVec3(view.hpr, 0, 0, 0);
        pfSetVec3(view.xyz, 0.0f, -50.0f, 60.0f);
        pfChanView(chan, view.xyz, view.hpr);

        pfDBaseFunc(pageDBase);

        while (i++ <= 50)
        {
                pfSync();

                // remove the commented lock and unlock below to see the results
                //lock();
                //unlock();

                pfFrame();
        }
        pfExit();
     
}

void pageDBase(void *data)
{
        static int i = 0;
        static pfBuffer *buf = NULL;
        pfGroup *grp;

    if ( i==15 )
    {
        printf("Inserting nodes\n");

        if (buf == NULL)
        {
            buf = pfNewBuffer();
            pfSelectBuffer(buf);
        }

        lock();

        //grp = (pfGroup *)pfdLoadFile("/disk4/people/kishore/performer/data/globeAnim.iv");
        grp = (pfGroup *)pfdLoadFile("globe.iv");
        pfBufferAddChild(*scene, grp);
        pfMergeBuffer();

        unlock();
    }
    i++;

    pfDBase();

}

#--
#-- definitions
#--

#-- force Make to use a known shell
SHELL = /bin/sh

#-- provide a list of alternate locations for file searches
UNIQUE = .

#-- alternate locatins for included files
INCLUDE = \
        -I${UNIQUE} \
        -I/usr/include/Performer

#-- some libraries lack .so versions; so use optimized .a's instead

#SRCLIBOPT= _ogl
SRCLIBOPT= _igl

LIBGL1 = -lgl
#LIBGL1 = -lGL

PERFORMER = \
        -lpfdu${SRCLIBOPT} \
        -lpfutil${SRCLIBOPT} \
        -lpf${SRCLIBOPT}

#-- IRIX 4.x uses shared gl {gl_s} library {System-V Make lacks #if tests}
LIBGL2 = ${LIBGL1:.4=_s}
LIBGL = ${LIBGL2:.5=}

# .ptu (Performer Terrain Utility)
# This loader requires linking with the ImageVision Libraries(IL)!
# Shoud you want to use the Performer Terrain Utility loader (.ptu)
# then install the image library and un-comment the following two
# definitions of LIBIL and LIBCIL.
#LIBIL = -lil
#LIBCIL = -lcil

SYSTEM = \
        -lInventor \
        -lmpc \
        -limage \
        -lfm \
        ${LIBGL} \
        -lX11 \
        -lm \
        -lfpe \
        ${LIBIL} \
        ${LIBCIL} \
        -lC

LIBRARIES = \
        ${PERFORMER} ${SYSTEM}

#-- select c-compiler options
CFLAGS = -xansi -g -D__STDC__ ${INCLUDE} ${COPT} -Xcpluscomm \
                 -DPF_C_API=1 -DPF_CPLUSPLUS_API=0 \
                 -DIRISGL \
                 -DPF_MAJOR_VERSION=2

#-DIRISGL

#-- base name of program
TARGET = dbase5

#-- dummy assignment in case pmake is used
EXT=
LIBOPT=
MAJOR=

#-- object files from which target built {some are in the common directory}
OBJECTS = \
        dbase5.o

${TARGET}: ${OBJECTS}
        ${CC} ${CFLAGS} -o $++at++ ${OBJECTS} ${LIBRARIES}

#-- objects are built from either unique or common files
dbase5.o: ${UNIQUE}/dbase5.c
        ${CC} ${CFLAGS} -c $?


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:19 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.