Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sol-worker-thread.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Soletta (TM) Project
3  *
4  * Copyright (C) 2015 Intel Corporation. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #pragma once
20 
21 #include <stdbool.h>
22 #include <inttypes.h>
23 
24 #include "sol-common-buildopts.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
47 // TODO abstract locks? see eina_lock.h
48 struct sol_worker_thread;
50 
54 typedef struct sol_worker_thread_config {
55 #ifndef SOL_NO_API_VERSION
56 #define SOL_WORKER_THREAD_CONFIG_API_VERSION (1)
57 
58  uint16_t api_version;
59 #endif
60 
61  const void *data;
70  bool (*setup)(void *data);
77  void (*cleanup)(void *data);
84  bool (*iterate)(void *data);
93  void (*cancel)(void *data);
102  void (*finished)(void *data);
108  void (*feedback)(void *data);
110 
145 
167 void sol_worker_thread_cancel(struct sol_worker_thread *thread);
168 
180 bool sol_worker_thread_is_cancelled(const struct sol_worker_thread *thread);
181 
201 void sol_worker_thread_feedback(struct sol_worker_thread *thread);
202 
207 #ifdef __cplusplus
208 }
209 #endif
struct sol_worker_thread * sol_worker_thread_new(const struct sol_worker_thread_config *config)
Create and run a worker thread.
bool(* iterate)(void *data)
function to be called repeatedly from the worker thread until it returns false or sol_worker_thread_c...
Definition: sol-worker-thread.h:84
void(* finished)(void *data)
function to be called from the main thread after the worker thread is finished.
Definition: sol-worker-thread.h:102
void(* feedback)(void *data)
function to be called from the main thread after the worker thread calls sol_worker_thread_feedback()...
Definition: sol-worker-thread.h:108
bool(* setup)(void *data)
function to be called once from the worker thread, before all other thread functions.
Definition: sol-worker-thread.h:70
const void * data
the context data to give to all functions.
Definition: sol-worker-thread.h:61
struct sol_worker_thread sol_worker_thread
A worker thread handle.
Definition: sol-worker-thread.h:49
Worker thread functions and context data configuration.
Definition: sol-worker-thread.h:54
uint16_t api_version
must match SOL_WORKER_THREAD_CONFIG_API_VERSION in runtime
Definition: sol-worker-thread.h:58
void(* cancel)(void *data)
function to be called from the main thread before the worker thread is to be terminated.
Definition: sol-worker-thread.h:93
void(* cleanup)(void *data)
function to be called once from the worker thread, after all other thread functions.
Definition: sol-worker-thread.h:77
struct sol_worker_thread_config sol_worker_thread_config
Worker thread functions and context data configuration.
bool sol_worker_thread_is_cancelled(const struct sol_worker_thread *thread)
Check if a worker thread has been marked as cancelled.
void sol_worker_thread_cancel(struct sol_worker_thread *thread)
Cancel a worker thread.
void sol_worker_thread_feedback(struct sol_worker_thread *thread)
Schedule feedback from the worker to the main thread.