Nspr api overview
This presentation is the property of its rightful owner.
Sponsored Links
1 / 12

NSPR API Overview PowerPoint PPT Presentation


  • 87 Views
  • Uploaded on
  • Presentation posted in: General

NSPR API Overview. Srinivas Lingutla Wan-Teh Chang Lawrence Hardiman. NSPR 2.0. Netscape Portable Runtime Provides OS/system-level services with a platform- independent API. General purpose platform for use by clients and servers Supported on a large number of platforms including

Download Presentation

NSPR API Overview

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Nspr api overview

NSPR API Overview

Srinivas Lingutla

Wan-Teh Chang

Lawrence Hardiman


Nspr 2 0

NSPR 2.0

  • Netscape Portable Runtime

  • Provides OS/system-level services with a platform- independent API.

  • General purpose platform for use by clients and servers

  • Supported on a large number of platforms including

    • - AIX, Digital Unix, HP-UX, Irix, Solaris, Win95, Windows NT, Linux

    • - Mac, Win 16, SunOS 4.x, NCR, SCO Unix, Netware, etc,.

  • Used in most products at Netscape


Basic services

Basic services

  • Libnspr

  • Threads and Synchronization

  • File and Network I/O

  • Memory Management

  • Time Management

  • Library Management

  • Support for 64-bit platforms

  • Atomic Operations

  • Environment Variables

  • Instrumentation

  • Process creation

  • List management

  • Debug aids


Miscellaneous libraries

Miscellaneous libraries

  • Libplc

    • String functions

    • Command line options processing

  • Libplds

    • Arenas

    • Hash tables

    • Events

  • Libnsps

    • Reader/Writer locks


Overview

Overview

  • C level API

  • All services exported through functions (a few are macros)

  • All exported symbols have the

    • PR prefix for libnspr

    • PL prefix for the auxiliary libraries

    • PS prefix for libnsps

  • All functions that allocate memory for the caller have a corresponding “free” function

    • Example: PR_smprintf/PR_smprintf_free

  • Call PR_GetError to get the NSPR error code when a function fails

  • Call PR_GetOSError to get the OS error code of the last failed system call in NSPR

  • All timeout values specified in PRIntervalTime units.


Nspr threads

NSPR Threads

  • Scheduling scope classification

  • LOCAL

    • Scheduled by NSPR

    • Implemented for use by the Client

    • User-level implementation, faster performance

  • GLOBAL

    • Scheduled by the system

    • Available on all platforms where native threads are present

    • Each NSPR thread maps to a native thread

    • User or kernel-level implementation


Thread models

Thread Models

  • GLOBAL threads only

    • - NSPR threads map to pthreads on

      • AIX 4.2 , Digital Unix 4.0 , HP-UX 11.0

      • Solaris 2.5.1, Irix 6.2, Linux 2.1

    • - NSPR threads map to Win32 threads on

      • WIN95

  • GLOBAL and LOCAL threads

    • Irix 6.2

    • Global threads map to sprocs

  • Local threads scheduled by NSPR

    • WinNT 4.0

    • Global threads map to Win32 threads

  • Local threads are NT Fibers scheduled by NSPR


Nspr thread apis

NSPR Thread APIs

  • Manipulating threads

  • PR_CreateThread( PRThreadType type,

    • void (*start)(void *),

    • void *arg,

    • PR_ThreadPriority priority,

    • PR_ThreadScope scope,

    • PR_ThreadState,

    • PRUint32 stackSize)

  • PR_JoinThread

  • PR_GetThreadPriority

  • PR_SetThreadPriority

  • PR_Interrupt

  • PR_ClearInterrupt

  • PR_Sleep


  • Nspr thread apis1

    NSPR Thread APIs

    • Thread Info

      • PR_GetCurrentThread

      • PR_GetThreadScope

      • PR_GetThreadType

      • PR_GetThreadState

    • Thread local storage

      • PR_NewThreadPrivateIndex

      • PR_SetThreadPrivate

      • PR_GetThreadPrivate


    Locks

    Locks

    • PRLock

    • Classic mutual exclusion locking

      • Non-reentrant

      • Not interruptible

      • Protect data, not code

      • Use locks for protection, not scheduling

      • Only hold locks for short periods

    • Lock management

      • PRLock *PR_NewLock(void)

      • PR_DestroyLock(PRLock *)

    • Lock usage

      • PR_Lock/PR_Unlock(PRLock *)


    Condition variables

    Condition variables

    • PRCondVar

    • Synchronization between threads - one or more threads can wait for a condition to occur and another thread can notify them when the condition occurs

    • PRCondVar * PR_NewCondVar(PRLock *)

    • PR_DestroyCondVar(PRCondVar *)

    • PR_WaitCondVar(PRCondVar *, PRIntervalTime)

      • PRLock is unlocked before blocking and reacquired before resuming

    • PR_NotifyCondVar/PR_NotifyAllCondVar(PRCondVar *)

      • Notification(s) lost when no thread is waiting


    Condition variables usage

    Condition variables - usage

    • Waiting

    • Correct method Incorrect

      • PR_Lock(..)PR_Lock(…)

      • while (!condition)if (!condition)

        • PR_WaitCondVar(..) PR_WaitCondVar(..)

      • …process data…process data

      • PR_Unlock(…)PR_Unlock(…)

    • Notification

      • PR_Lock(..)

      • ….process data

      • PR_NotifyCondVar(..)

      • PR_Unlock(…)


  • Login