• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2014 Google, Inc.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #pragma once
20 
21 typedef struct future_t future_t;
22 
23 #define FUTURE_SUCCESS ((void*)1)
24 #define FUTURE_FAIL ((void*)0)
25 
26 // Constructs a new future_t object. Returns NULL on failure.
27 future_t* future_new(void);
28 
29 // Constructs a new future_t object with an immediate |value|. No waiting will
30 // occur in the call to |future_await| because the value is already present.
31 // Returns NULL on failure.
32 future_t* future_new_immediate(void* value);
33 
34 // Signals that the |future| is ready, passing |value| back to the context
35 // waiting for the result. Must only be called once for every future.
36 // |future| may not be NULL.
37 void future_ready(future_t* future, void* value);
38 
39 // Waits for the |future| to be ready. Returns the value set in |future_ready|.
40 // Frees the future before return. |future| may not be NULL.
41 void* future_await(future_t* async_result);
42