source: svn/trunk/newcon3bcm2_21bu/nexus/lib/os/include/b_os_lib.h

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 33.3 KB
Line 
1/***************************************************************************
2*     (c)2004-2009 Broadcom Corporation
3
4*  This program is the proprietary software of Broadcom Corporation and/or its licensors,
5*  and may only be used, duplicated, modified or distributed pursuant to the terms and
6*  conditions of a separate, written license agreement executed between you and Broadcom
7*  (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
8*  no license (express or implied), right to use, or waiver of any kind with respect to the
9*  Software, and Broadcom expressly reserves all rights in and to the Software and all
10*  intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
11*  HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
12*  NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. 
13*   
14*  Except as expressly set forth in the Authorized License,
15*   
16*  1.     This program, including its structure, sequence and organization, constitutes the valuable trade
17*  secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
18*  and to use this information only in connection with your use of Broadcom integrated circuit products.
19*   
20*  2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
21*  AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
22*  WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
23*  THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
24*  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
25*  LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
26*  OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
27*  USE OR PERFORMANCE OF THE SOFTWARE.
28
29*  3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
30*  LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
31*  EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
32*  USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
33*  THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
34*  ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
35*  LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
36*  ANY LIMITED REMEDY.
37*
38* $brcm_Workfile: b_os_lib.h $
39* $brcm_Revision: 5 $
40* $brcm_Date: 7/6/09 1:14p $
41*
42* Description:
43*   API name: OS
44*    Library routines for OS abstraction
45*
46* Revision History:
47*
48* $brcm_Log: /nexus/lib/os/include/b_os_lib.h $
49*
50* 5   7/6/09 1:14p jgarrett
51* PR 55572: Adding option for thread termination
52*
53* 4   6/4/08 11:20a rjlewis
54* PR40352: can't be void when instantiated.
55*
56* 3   3/31/08 1:13p jgarrett
57* PR 41043: Adding time routines
58*
59* 2   3/10/08 8:54p jgarrett
60* PR 40306: Adding mutex lock assertion
61*
62* 1   3/10/08 1:59p jgarrett
63* PR 40306: Adding osLib
64*
65***************************************************************************/
66#ifndef B_OS_LIB_H__
67#define B_OS_LIB_H__
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73#include "bstd.h"
74#include "b_os_time.h"
75
76/***************************************************************************
77Summary:
78Generic Error Codes
79
80Description:
81These error codes will match those returned by nexus (NEXUS_Error) and
82magnum (BERR_Code).  These may be used throughout application libraries
83for consistency.
84***************************************************************************/
85typedef unsigned B_Error;
86
87/**
88Summary:
89Standard Nexus error codes.
90**/
91#define B_ERROR_SUCCESS              0  /* success (always zero) */
92#define B_ERROR_NOT_INITIALIZED      1  /* parameter not initialized */
93#define B_ERROR_INVALID_PARAMETER    2  /* parameter is invalid */
94#define B_ERROR_OUT_OF_MEMORY        3  /* out of heap memory */
95#define B_ERROR_TIMEOUT              5  /* reached timeout limit */
96#define B_ERROR_OS_ERROR             6  /* generic OS error */
97#define B_ERROR_LEAKED_RESOURCE      7  /* resource being freed has attached resources that haven't been freed */
98#define B_ERROR_NOT_SUPPORTED        8  /* requested feature is not supported */
99#define B_ERROR_UNKNOWN              9  /* unknown */
100
101/***************************************************************************
102Summary:
103Initialize the OS Library
104
105Description:
106It is permissible to call this routine multiple times.  Internally, a
107reference count will be maintained.
108***************************************************************************/
109B_Error B_Os_Init(void);
110
111/***************************************************************************
112Summary:
113Un-Initialize the OS Library
114
115Description:
116This routine must be called once per call to B_Os_Init
117***************************************************************************/
118B_Error B_Os_Uninit(void);
119
120/***************************************************************************
121Summary:
122Mutex Handle
123***************************************************************************/
124typedef struct B_Mutex *B_MutexHandle;
125
126/***************************************************************************
127Summary:
128Event Handle
129***************************************************************************/
130typedef void *B_EventHandle;
131
132/***************************************************************************
133Summary:
134Event Group Handle
135***************************************************************************/
136typedef void *B_EventGroupHandle;
137
138/***************************************************************************
139Summary:
140Message Queue Handle
141***************************************************************************/
142typedef struct B_MessageQueue *B_MessageQueueHandle;
143
144/***************************************************************************
145Summary:
146Thread Handle
147***************************************************************************/
148typedef struct B_Thread *B_ThreadHandle;
149
150/***************************************************************************
151Summary:
152Thread Main Loop Function
153***************************************************************************/
154typedef void (*B_ThreadFunc)(void *pParam);
155
156/***************************************************************************
157Summary:
158Scheduler Handle
159
160Description:
161A Scheduler is a higher-level OS construct.  A scheduler is responsible for
162dispatching synchronized timer and event callbacks using a single thread.
163***************************************************************************/
164typedef struct B_Scheduler *B_SchedulerHandle;
165
166/***************************************************************************
167Summary:
168Scheduler Event Callback Prototype
169***************************************************************************/
170typedef void (*B_EventCallback)(void *pContext);
171
172/***************************************************************************
173Summary:
174Scheduler Event Callback Handle
175***************************************************************************/
176typedef struct B_SchedulerEvent *B_SchedulerEventId;
177
178/***************************************************************************
179Summary:
180Scheduler Timer Callback Prototype
181***************************************************************************/
182typedef void (*B_TimerCallback)(void *pContext);
183
184/***************************************************************************
185Summary:
186Scheduler Timer Handle
187***************************************************************************/
188typedef struct B_SchedulerTimer *B_SchedulerTimerId;
189
190/***************************************************************************
191Summary:
192Scheduler Callback Handle
193***************************************************************************/
194typedef struct B_SchedulerCallback *B_SchedulerCallbackHandle;
195
196/***************************************************************************
197Summary:
198Scheduler Callback Function Prototype
199***************************************************************************/
200typedef void (*B_SchedulerCallbackFunction)(void *pParam1, int param2);
201
202/***************************************************************************
203Shortcuts for event timeouts
204***************************************************************************/
205#define B_WAIT_NONE (0)             /* Avoid blocking while waiting for events */
206#define B_WAIT_FOREVER (-1)         /* Block forever waiting for events */
207
208/***************************************************************************
209Summary:
210Allocate Memory (malloc equivalent)
211***************************************************************************/
212#ifdef BDBG_DEBUG_BUILD
213#define B_Os_Malloc(numBytes) B_Os_Malloc_tagged((numBytes), __FUNCTION__, __LINE__)
214#else
215#define B_Os_Malloc(numBytes) B_Os_Malloc_tagged((numBytes), NULL, 0)
216#endif
217void *B_Os_Malloc_tagged(
218    size_t numBytes,
219    const char *pFunction,
220    int line
221    );
222
223/***************************************************************************
224Summary:
225Free Memory (free equivalent)
226***************************************************************************/
227#ifdef BDBG_DEBUG_BUILD
228#define B_Os_Free(pMemory) B_Os_Free_tagged((pMemory), __FUNCTION__, __LINE__)
229#else
230#define B_Os_Free(pMemory) B_Os_Free_tagged((pMemory), NULL, 0)
231#endif
232void B_Os_Free_tagged(
233    void *pMemory,
234    const char *pFunction,
235    int line
236    );
237
238/***************************************************************************
239Summary:
240Allocate and Clear memory (calloc equivalent)
241***************************************************************************/
242#ifdef BDBG_DEBUG_BUILD
243#define B_Os_Calloc(numMembers, numBytes) B_Os_Calloc_tagged((numMembers), (numBytes), __FUNCTION__, __LINE__)
244#else
245#define B_Os_Calloc(numMembers, numBytes) B_Os_Calloc_tagged((numMembers), (numBytes), NULL, 0)
246#endif
247void *B_Os_Calloc_tagged(
248    size_t numMembers, 
249    size_t memberSize,
250    const char *pFunction,
251    int line
252    );
253
254/***************************************************************************
255Summary:
256Re-Allocate memory (realloc equivalent)
257***************************************************************************/
258#ifdef BDBG_DEBUG_BUILD
259#define B_Os_Realloc(pMemory, numBytes) B_Os_Realloc_tagged((pMemory), (numBytes), __FUNCTION__, __LINE__)
260#else
261#define B_Os_Realloc(pMemory, numBytes) B_Os_Realloc_tagged((pMemory), (numBytes), NULL, 0)
262#endif
263void *B_Os_Realloc_tagged(
264    void *pMemory, 
265    size_t numBytes,
266    const char *pFunction,
267    int line
268    );
269
270/***************************************************************************
271Summary:
272Mutex settings.  Currently a placeholder.
273***************************************************************************/
274typedef struct { int notused; } B_MutexSettings;
275
276/***************************************************************************
277Summary:
278Get default mutex settings.
279***************************************************************************/
280void B_Mutex_GetDefaultSettings(
281    B_MutexSettings *pSettings  /* [out] */
282    );
283
284/***************************************************************************
285Summary:
286Create a mutex using the specified settings.
287***************************************************************************/
288B_MutexHandle B_Mutex_Create(
289    const B_MutexSettings *pSettings   /* Pass NULL for defaults */
290    );
291
292/***************************************************************************
293Summary:
294Destroy a mutex
295***************************************************************************/
296void B_Mutex_Destroy(
297    B_MutexHandle mutex
298    );
299
300/***************************************************************************
301Summary:
302Lock a mutex
303***************************************************************************/
304void B_Mutex_Lock(
305    B_MutexHandle mutex
306    );
307
308/***************************************************************************
309Summary:
310Try to lock a mutex.
311
312Description:
313This will attempt to lock the mutex without blocking.  If the mutex is
314available, it will be locked and B_Error_eSuccess will be returned.  If
315the mutex is unavailable, B_Error_eTimeout will be returned.
316***************************************************************************/
317B_Error B_Mutex_TryLock(
318    B_MutexHandle mutex
319    );
320
321/***************************************************************************
322Summary:
323Unlock a mutex.
324
325Description:
326Mutexes must be unlocked by the same thread that successfully called
327B_Mutex_Lock or B_Mutex_TryLock.
328***************************************************************************/
329void B_Mutex_Unlock(
330    B_MutexHandle mutex
331    );
332
333/***************************************************************************
334Summary:
335Verify that a mutex is locked by the calling thread
336
337Description:
338This can be used to facilitate debugging
339***************************************************************************/
340#define B_MUTEX_ASSERT_LOCKED(mutex) BDBG_ASSERT(true == B_Mutex_P_IsLocked((mutex)))
341bool B_Mutex_P_IsLocked(
342    B_MutexHandle mutex
343    );
344
345/***************************************************************************
346Summary:
347Event settings.  Currently a placeholder.
348***************************************************************************/
349typedef struct { int notused; } B_EventSettings;
350
351/***************************************************************************
352Summary:
353Get default event settings.
354***************************************************************************/
355void B_Event_GetDefaultSettings(
356    B_EventSettings *pSettings  /* [out] */
357    );
358
359/***************************************************************************
360Summary:
361Create an event
362***************************************************************************/
363B_EventHandle B_Event_Create(
364    const B_EventSettings *pSettings    /* Pass NULL for defaults */
365    );
366
367/***************************************************************************
368Summary:
369Destroy an event
370***************************************************************************/
371void B_Event_Destroy(
372    B_EventHandle event
373    );
374
375/***************************************************************************
376Summary:
377Set an event
378***************************************************************************/
379void B_Event_Set(
380    B_EventHandle event
381    );
382
383/***************************************************************************
384Summary:
385Wait for an event to be set
386
387Description:
388This routine will wait for the specified event to be set.  If the event
389was set, B_Error_eSuccess will be returned.  If the event was not set,
390B_Error_eTimeout will be returned.
391***************************************************************************/
392B_Error B_Event_Wait(
393    B_EventHandle event, 
394    int timeoutMsec         /* Timeout in milliseconds.  Pass B_WAIT_FOREVER to wait
395                               forever or B_WAIT_NONE to avoid blocking */
396    );
397
398/***************************************************************************
399Summary:
400Clear an event if it has been set
401***************************************************************************/
402void B_Event_Reset(
403    B_EventHandle event
404    );
405
406/***************************************************************************
407Summary:
408Event Group Settings.  Currently a placeholder.
409***************************************************************************/
410typedef void B_EventGroupSettings;
411
412/***************************************************************************
413Summary:
414Get default event group settings
415***************************************************************************/
416void B_EventGroup_GetDefaultSettings(
417    B_EventGroupSettings *pSettings     /* [out] */
418    );
419
420/***************************************************************************
421Summary:
422Create an event group
423***************************************************************************/
424B_EventGroupHandle B_EventGroup_Create(
425    const B_EventGroupSettings *pSettings
426    );
427
428/***************************************************************************
429Summary:
430Destroy an event group
431***************************************************************************/
432void B_EventGroup_Destroy(
433    B_EventGroupHandle group
434    );
435
436/***************************************************************************
437Summary:
438Add an event to the group
439***************************************************************************/
440B_Error B_EventGroup_AddEvent(
441    B_EventGroupHandle group, 
442    B_EventHandle event
443    );
444
445/***************************************************************************
446Summary:
447Remove an event from the group
448***************************************************************************/
449B_Error B_EventGroup_RemoveEvent(
450    B_EventGroupHandle group, 
451    B_EventHandle event
452    );
453
454/***************************************************************************
455Summary:
456Wait for any event in the group to be set.
457
458Description:
459This routine will wait for the specified event to be set.  If the event
460was set, B_Error_eSuccess will be returned.  If the event was not set,
461B_Error_eTimeout will be returned.
462***************************************************************************/
463B_Error B_EventGroup_Wait(
464    B_EventGroupHandle group, 
465    int timeoutMsec,                    /* Timeout in milliseconds.  Pass B_WAIT_FOREVER to wait
466                                           forever or B_WAIT_NONE to avoid blocking */
467    B_EventHandle *pTriggeredEvents,    /* Triggered events handles will be copied into this array */
468    unsigned maxTriggeredEvents,        /* Size of triggered event array */
469    unsigned *pNumTriggeredEvents       /* [out] Number of triggered events */
470    );
471
472/***************************************************************************
473Summary:
474Delay a thread for the specified time
475
476Description:
477This will busy-wait a thread for the specified time without yielding.
478***************************************************************************/
479void B_Thread_Delay(
480    int microseconds
481    );
482
483/***************************************************************************
484Summary:
485Suspend a thread for the specified time
486
487Description:
488This will yield the CPU for the specified time.  May round up to the nearest
489OS scheduler tick value.
490***************************************************************************/
491void B_Thread_Sleep(
492    int milliseconds
493    );
494
495/***************************************************************************
496Summary:
497Thread Settings
498***************************************************************************/
499typedef struct B_ThreadSettings
500{
501    int priority;   /* 0 = maximum, 100=minimum */
502    int stackSize;  /* In bytes, 0 will use an OS default */
503    bool terminate; /* If true, B_Thread_Destroy will terminate the thread.
504                       Otherwise, B_Thread_Destroy will wait for the thread
505                       to exit from some external signal. */
506} B_ThreadSettings;
507
508/***************************************************************************
509Summary:
510Get Default Thread Settings
511***************************************************************************/
512void B_Thread_GetDefaultSettings(
513    B_ThreadSettings *pSettings     /* [out] */
514    );
515
516/***************************************************************************
517Summary:
518Create a thread using the specified settings
519***************************************************************************/
520B_ThreadHandle B_Thread_Create(
521    const char *pName,                  /* Thread Name - Optional */
522    B_ThreadFunc threadFunction,        /* Thread Main Routine */
523    void *pThreadParam,                 /* Parameter provided to threadFunction */
524    const B_ThreadSettings *pSettings   /* Pass NULL for defaults */
525    );
526
527/***************************************************************************
528Summary:
529Destroy a thread. 
530
531Description:
532This will signal the thread to exit and will wait for the thread to
533terminate before returning.
534***************************************************************************/
535void B_Thread_Destroy(
536    B_ThreadHandle thread
537    );
538
539/***************************************************************************
540Summary:
541Get a handle to the currently executing thread
542
543Description:
544This will return NULL if the thread was not created with B_Thread_Create
545***************************************************************************/
546B_ThreadHandle B_Thread_GetSelf(void);   
547
548/***************************************************************************
549Summary:
550Get a handle to the currently executing thread
551
552Description:
553This will return a thread ID for any thread, not just those created by
554B_Thread_Create.  This is useful for bprofile.
555***************************************************************************/
556B_Error B_Thread_GetId(
557    B_ThreadHandle thread,  /* Pass NULL for the current thread */
558    int *pId
559    );
560
561/***************************************************************************
562Summary:
563Get the name of a specified thread for debugging.
564
565Description:
566This will return the name of a thread specified, and will return
567an error for those threads not created with B_ThreadCreate.
568***************************************************************************/
569B_Error B_Thread_GetName(
570    B_ThreadHandle thread,  /* Pass NULL for current thread */
571    char *pName,            /* Pointer to array for name */
572    int maxNameLen          /* Size of name array */
573    );
574
575/***************************************************************************
576Summary:
577Get the name of a specified thread for debugging.
578
579Description:
580This will return the name of a thread specified, and will return
581an error for those threads not created with B_ThreadCreate.  This is useful
582for bprofile.
583***************************************************************************/
584B_Error B_Thread_GetNameFromId(
585    int id,         /* ID returned by B_Thread_GetId */
586    char *pName,    /* Pointer to array for name */
587    int maxNameLen  /* Size of name array */
588    );
589
590/***************************************************************************
591Summary:
592Scheduler settings.  Currently a placeholder.
593***************************************************************************/
594typedef void B_SchedulerSettings;
595
596/***************************************************************************
597Summary:
598Get Default Scheduler Settings
599***************************************************************************/
600void B_Scheduler_GetDefaultSettings(
601    B_SchedulerSettings *pSettings      /* [out] */
602    );
603
604/***************************************************************************
605Summary:
606Craete a scheduler
607***************************************************************************/
608B_SchedulerHandle B_Scheduler_Create(
609    const B_SchedulerSettings *pSettings
610    );
611
612/***************************************************************************
613Summary:
614Destroy a scheduler
615***************************************************************************/
616void B_Scheduler_Destroy(
617    B_SchedulerHandle scheduler
618    );
619
620/***************************************************************************
621Summary:
622Register an event with a scheduler
623
624Description:
625This will cause the scheduler to call the sepecified EventCallback function
626when the specified event has been set.  Prior to calling the callback,
627the specified mutex will be automatically locked.  After the callback
628returns, the mutex will be unlocked.
629***************************************************************************/
630B_SchedulerEventId B_Scheduler_RegisterEvent(
631    B_SchedulerHandle scheduler, 
632    B_MutexHandle mutex,                        /* Mutex to lock prior to calling callback */
633    B_EventHandle event,                        /* Event that will trigger the callback */
634    B_EventCallback callback,                   /* Callback routine to execute when event is set */
635    void *pContext                              /* Value passed to callback routine */
636    );
637
638/***************************************************************************
639Summary:
640Un-Register an event from the scheduler
641***************************************************************************/
642void B_Scheduler_UnregisterEvent(
643    B_SchedulerHandle scheduler, 
644    B_SchedulerEventId eventId
645    );
646
647/***************************************************************************
648Summary:
649Schedule a timer
650
651Description:
652This will start a timer that will lock the specified mutex and call the
653specified callback routine when the timer expires.  Timers are one-shot,
654and they must be rescheduled to repeat.  Re-scheduling the timer from the
655callback itself is allowed.  After the timer expires, the TimerId value
656returned becomes invalid and should be discarded.
657***************************************************************************/
658B_SchedulerTimerId B_Scheduler_StartTimer(
659    B_SchedulerHandle scheduler, 
660    B_MutexHandle mutex,                    /* Mutex to lock prior to calling callback */
661    int timeoutMsec,                        /* Timer expiration time in msec */
662    B_TimerCallback callback,               /* Callback to call when timer expires */
663    void *pContext                          /* Value passed to callback routine */
664    );
665
666/***************************************************************************
667Summary:
668Cancel a timer
669
670Description:
671This will cancel a timer that was previously started.  If the timer has
672already expired, this call is safe.  If the callback has actually been
673called, this will generate a warning message.  If the timer has expired and
674the callback is pending on the mutex, the timer will be discarded and no
675warning will occur.
676***************************************************************************/
677void B_Scheduler_CancelTimer(
678    B_SchedulerHandle scheduler, 
679    B_SchedulerTimerId timerId
680    );
681
682/***************************************************************************
683Summary:
684Run a scheduler
685
686Description:
687This routine will drive the scheduler execution.  It will not return until
688B_Scheduler_Stop is called. 
689***************************************************************************/
690void B_Scheduler_Run(
691    B_SchedulerHandle scheduler
692    );
693
694/***************************************************************************
695Summary:
696Stop a scheduler
697
698Description:
699This routine will stop the scheduler execution.  After this is called,
700B_Scheduler_Run will return.  This routine can be called by any thread,
701including the scheduler thread itself.  It is not synchronized, so this call
702may return before B_Scheduler_Run returns.
703***************************************************************************/
704void B_Scheduler_Stop(
705    B_SchedulerHandle scheduler
706    );
707
708
709/***************************************************************************
710Summary:
711Settings for a scheduler callback instance
712***************************************************************************/
713typedef void B_SchedulerCallbackSettings; /* Placeholder */
714
715/***************************************************************************
716Summary:
717Get default settings for a scheduler callback instance
718***************************************************************************/
719void B_SchedulerCallback_GetDefaultSettings(
720    B_SchedulerCallbackSettings *pSettings  /* [out] */
721    );
722
723/***************************************************************************
724Summary:
725Register an asynchronous callback
726
727Description:
728This will cancel a timer that was previously started.  If the timer has
729already expired, this call is safe.  If the callback has actually been
730called, this will generate a warning message.  If the timer has expired and
731the callback is pending on the mutex, the timer will be discarded and no
732warning will occur.
733***************************************************************************/
734B_SchedulerCallbackHandle B_SchedulerCallback_Create(
735    B_SchedulerHandle scheduler,
736    void *pInstanceHandle,                          /* Pass the handle to the application object's instance here */
737    const B_SchedulerCallbackSettings *pSettings    /* Pass NULL for defaults */
738    );
739
740/***************************************************************************
741Summary:
742Set the function to be used in an asynchronous callback
743***************************************************************************/
744B_Error B_SchedulerCallback_SetFunction(
745    B_SchedulerCallbackHandle callbackHandle,
746    B_SchedulerCallbackFunction callbackFunction,   /* Function to be called */
747    void *pParam1,                                  /* First function parameter */
748    int param2                                      /* Second function parameter */
749    );
750
751/***************************************************************************
752Summary:
753Fire an asynchronous callback
754
755Description:
756This will schedule the callback to be executed when the scheduler becomes
757idle.  If the same callback is fired multiple times before it is able to
758be called, only a single application callback will be made.
759***************************************************************************/
760void B_SchedulerCallback_Fire(
761    B_SchedulerCallbackHandle callback
762    );
763
764/***************************************************************************
765Summary:
766Destroying an asynchronous callback
767***************************************************************************/
768void B_SchedulerCallback_Destroy(
769    B_SchedulerCallbackHandle callback
770    );
771
772/***************************************************************************
773Summary:
774Cancel all pending callbacks for this object instance
775
776Description:
777Because of the asynchronous nature of scheduler callbacks, race conditions
778can occur when closing objects that have pending callbacks.  In order to
779guarantee that all pending callbacks have been stopped for an instance,
780this function should be called as part of closing the object instance.
781
782NOTE: It is important to call this routine before acquiring your instance's
783mutex to avoid a race condition where a callback into your module may still
784be pending due to contention on the module's mutex.  As an example:
785
786void B_Object_Close(B_ObjectHandle handle)
787{
788   BDBG_ASSERT(NULL != handle);
789
790   B_Scheduler_StopCallbacks(handle->scheduler); 
791
792   // Now it's guaranteed that no callbacks are pending.
793
794   B_Mutex_Lock(handle->mutex);
795
796   // Actually clean up now
797}
798***************************************************************************/
799void B_Scheduler_StopCallbacks(
800    B_SchedulerHandle scheduler,
801    void *pInstanceHandle
802    );
803
804/***************************************************************************
805Summary:
806Get current system time
807
808Description:
809The value returned in this call is only useful in the B_Time_Add and
810B_Time_Diff routines, it is not meant for direct access to a system time
811value.
812***************************************************************************/
813void B_Time_Get(
814    B_Time *pTime
815    );
816
817/***************************************************************************
818Summary:
819Return the delta between two time values in milliseconds
820***************************************************************************/
821long B_Time_Diff(
822    const B_Time *pFuture, 
823    const B_Time *pPast
824    );
825
826/***************************************************************************
827Summary:
828Add a specified number of milliseconds to a time value
829***************************************************************************/
830void B_Time_Add(
831    B_Time *pTime, 
832    long deltaMsec
833    );
834
835/***************************************************************************
836Summary:
837Message Queue Settings
838***************************************************************************/
839typedef struct B_MessageQueueSettings
840{
841    size_t maxMessageSize;  /* Maximum size of an individual message */
842    size_t maxMessages;     /* Maximum messages in the queue at a time */
843} B_MessageQueueSettings;
844
845/***************************************************************************
846Summary:
847Get Default Message Queue Settings
848***************************************************************************/
849void B_MessageQueue_GetDefaultSettings(
850    B_MessageQueueSettings *pSettings   /* [out] */
851    );
852
853/***************************************************************************
854Summary:
855Create a message queue
856***************************************************************************/
857B_MessageQueueHandle B_MessageQueue_Create(
858    const B_MessageQueueSettings *pSettings
859    );
860
861/***************************************************************************
862Summary:
863Destroy a message queue
864***************************************************************************/
865void B_MessageQueue_Destroy(
866    B_MessageQueueHandle handle
867    );
868
869/***************************************************************************
870Summary:
871Post (Send) a message to a queue
872
873Description:
874This function will return B_ERROR_SUCCESS if the message was sent
875successfully or B_ERROR_TIMEOUT if the message queue is full.
876***************************************************************************/
877B_Error B_MessageQueue_Post(
878    B_MessageQueueHandle handle,
879    const void *pMessageData,
880    size_t messageSize
881    );
882
883/***************************************************************************
884Summary:
885Receive a message from a queue
886
887Description:
888This function will return B_ERROR_SUCCESS if a message was successfully
889received or B_ERROR_TIMEOUT if the specified timeout value was reached.
890***************************************************************************/
891B_Error B_MessageQueue_Wait(
892    B_MessageQueueHandle handle,
893    void *pMessageBuffer,
894    size_t messageBufferSize,
895    size_t *pMessageSizeReceived,
896    int timeoutMsec                 /* Values B_WAIT_NONE and B_WAIT_FOREVER may be used */
897    );
898
899#ifdef __cplusplus
900}
901#endif
902
903#endif /* #ifndef B_OS_LIB_H__ */
904
Note: See TracBrowser for help on using the repository browser.