2 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef _OSMEMORYNOTIFICATION_H_
25 #define _OSMEMORYNOTIFICATION_H_
27 #include <sys/cdefs.h>
30 ** OSMemoryNotification.h
32 ** Kernel-generated notification mechanism to alert registered tasks when physical memory
33 ** pressure reaches certain thresholds. Notifications are triggered in both directions
34 ** so clients can manage their memory usage more and less aggressively.
43 ** Opaque type for notification object
46 typedef struct _OSMemoryNotification
* OSMemoryNotificationRef
;
49 ** Threshold values for notifications
53 OSMemoryNotificationLevelAny
= -1,
54 OSMemoryNotificationLevelNormal
= 0,
55 OSMemoryNotificationLevelWarning
= 1,
56 OSMemoryNotificationLevelUrgent
= 2,
57 OSMemoryNotificationLevelCritical
= 3
58 } OSMemoryNotificationLevel
;
61 ** Creation routines. Returns the created OSMemoryNotificationRef in the note param.
62 ** returns: 0 on success
63 ** ENOMEM if insufficient memory or resources exists to create the notification object
64 ** EINVAL if the threshold is not a valid notification level
67 int OSMemoryNotificationCreate(OSMemoryNotificationRef
*note
);
70 ** returns: 0 on success
71 ** EINVAL if the notification is not an initialized notification object
74 int OSMemoryNotificationDestroy(OSMemoryNotificationRef note
);
77 ** Block waiting for notification
78 ** returns: 0 on success, with the level that triggered the notification in the level param
79 ** EINVAL if the notification object is invalid
80 ** ETIMEDOUT if abstime passes before notification occurs
82 int OSMemoryNotificationWait(OSMemoryNotificationRef note
, OSMemoryNotificationLevel
*level
);
83 int OSMemoryNotificationTimedWait(OSMemoryNotificationRef note
, OSMemoryNotificationLevel
*level
, const struct timeval
*abstime
);
86 ** Simple polling interface to detect current memory pressure level
89 OSMemoryNotificationLevel
OSMemoryNotificationCurrentLevel(void);
92 ** External notify(3) string for manual notification setup
95 extern const char *kOSMemoryNotificationName
;
99 #endif /* _OSMEMORYNOTIFICATION_H_ */