1 / 12

NSPR API Overview

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

janeeva
Télécharger la présentation

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NSPR API Overview Srinivas Lingutla Wan-Teh Chang Lawrence Hardiman

  2. 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

  3. 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

  4. Miscellaneous libraries • Libplc • String functions • Command line options processing • Libplds • Arenas • Hash tables • Events • Libnsps • Reader/Writer locks

  5. 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.

  6. 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

  7. 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

  8. 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

  9. NSPR Thread APIs • Thread Info • PR_GetCurrentThread • PR_GetThreadScope • PR_GetThreadType • PR_GetThreadState • Thread local storage • PR_NewThreadPrivateIndex • PR_SetThreadPrivate • PR_GetThreadPrivate

  10. 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 *)

  11. 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

  12. 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(…)

More Related