#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
 
#include <Ecore.h>
#include <Ecore_Getopt.h>
 
typedef struct
{
   int            msgs_received;
   int            max_msgs;
   Eina_Lock      mutex;
   Eina_Condition condition;
} App_Data;
 
typedef struct
{
} Thread_Data;
 
typedef struct
{
   char     *name;
   char     *base;
   Eina_Lock mutex;
} Feedback_Thread_Data;
 
typedef struct
{
   int        all_done;
} App_Msg;
 
static void
_local_data_free(void *data)
{
   Thread_Data *td = data;
   char *str;
 
     {
        printf("Freeing string: %s\n", str);
        free(str);
     }
   free(td);
}
 
static void
{
   Thread_Data *td;
   int i;
 
   if (!td)
     {
        td = calloc(1, sizeof(Thread_Data));
        if (!td)
          {
             return;
          }
     }
 
   for (i = 0; i < 10; i++)
     {
        char buf[200];
 
          {
             break;
          }
 
        snprintf(buf, sizeof(buf), "Thread %p: String number %d", th, i);
        sleep(1);
     }
}
 
static void
{
   time_t t;
   int i, count;
   Feedback_Thread_Data *ftd = NULL;
   App_Msg *msg;
   char *name;
 
   for (i = 0; i < count; i++)
     {
        char buf[32];
        snprintf(buf, sizeof(buf), "data%d", i);
        if (!ftd)
          continue;
        if (eina_lock_take_try(&ftd->mutex))
          break;
        else
          ftd = NULL;
     }
   if (!ftd)
     return;
 
   if (!it)
     goto the_end;
 
   msg = calloc(1, sizeof(App_Msg));
 
   t = time(NULL);
     {
        if (time(NULL) >= (t + 2))
          {
             break;
          }
     }
 
 
the_end:
   free(ftd->name);
   free(ftd->base);
   eina_lock_release(&ftd->mutex);
   eina_lock_free(&ftd->mutex);
   free(ftd);
}
 
static void
{
   App_Data *ad = data;
   App_Msg *msg;
 
   while (1)
     {
        int msgs;
        eina_condition_wait(&ad->condition);
        msgs = ad->msgs_received;
        eina_lock_release(&ad->mutex);
        if (msgs == ad->max_msgs)
          {
             msg = calloc(1, sizeof(App_Msg));
             msg->all_done = 1;
             return;
          }
     }
}
 
static void
_print_status(void)
{
   int active, pending_total, pending_feedback, pending_short, available;
 
 
   printf("Status:\n\t* Active threads: %d\n"
          "\t* Available threads: %d\n"
          "\t* Pending short jobs: %d\n"
          "\t* Pending feedback jobs: %d\n"
          "\t* Pending total: %d\n", active, available, pending_short,
          pending_feedback, pending_total);
}
 
static void
_feedback_job_msg_cb(
void *data, 
Ecore_Thread *th, 
void *msg_data)
 
{
   App_Data *ad = data;
   App_Msg *msg = msg_data;
   char *str;
 
   if (msg->all_done)
     {
        free(msg);
        return;
     }
 
   _print_status();
 
   if (!msg->list)
     printf("Received an empty list from thread %p\n", th);
   else
     {
        int i = 0;
        printf("Received %d elements from threads %p (printing first 5):\n",
               eina_list_count(msg->list), th);
          {
             if (i <= 5)
               printf("\t%s\n", str);
             free(str);
             i++;
          }
     }
 
   eina_lock_take(&ad->mutex);
   ad->msgs_received++;
   eina_condition_signal(&ad->condition);
   eina_lock_release(&ad->mutex);
 
   free(msg);
}
 
static void
{
   App_Data *ad = data;
 
   printf("Normal termination for thread %p.\n", th);
   if (th == ad->thread_3)
     ad->thread_3 = NULL;
}
 
static void
{
   App_Data *ad = data;
 
   printf("Thread %p got cancelled.\n", th);
   if (th == ad->thread_3)
     ad->thread_3 = NULL;
}
 
_cancel_timer_cb(void *data)
{
   App_Data *ad = data;
 
 
}
 
{
   _print_status();
 
}
 
   "ecore_thread_example",
   NULL,
   "0.0",
   "(C) 2011 Enlightenment",
   "Public domain?",
   "Example program for Ecore_Thread",
   0,
   {
   }
};
 
int
main(int argc, char *argv[])
{
   int i, max_threads = 0, max_msgs = 0;
   App_Data appdata;
   };
 
 
   printf("Initial max threads: %d\n", i);
 
   memset(&appdata, 0, sizeof(App_Data));
   appdata.max_msgs = 1;
 
     {
        printf("Argument parsing failed\n");
        return 1;
     }
 
   if (opt_quit)
     return 0;
 
   if (max_threads)
     {
     }
   if (max_msgs)
     appdata.max_msgs = max_msgs;
 
   if (!path_list)
     {
        Feedback_Thread_Data *ftd;
        ftd = calloc(1, sizeof(Feedback_Thread_Data));
        ftd->name = strdup("data0");
#ifdef _WIN32
        ftd->base = strdup("c:/windows/System32");
#else
        ftd->base = strdup("/usr/bin");
#endif
        eina_lock_new(&ftd->mutex);
        ftd = calloc(1, sizeof(Feedback_Thread_Data));
        ftd->name = strdup("data1");
#ifdef _WIN32
        ftd->base = strdup("c:/windows/Fonts");
#else
        ftd->base = strdup("/usr/lib");
#endif
        eina_lock_new(&ftd->mutex);
        ftd = calloc(1, sizeof(Feedback_Thread_Data));
        ftd->name = strdup("data2");
#ifdef _WIN32
        ftd->base = strdup("c:/windows/Help");
#else
        ftd->base = strdup("/usr/lib");
#endif
        eina_lock_new(&ftd->mutex);
     }
   else
     {
        Feedback_Thread_Data *ftd;
        char *str;
                                     (void *)(uintptr_t)eina_list_count(path_list), NULL,
        i = 0;
          {
             char buf[32];
             snprintf(buf, sizeof(buf), "data%d", i);
             ftd = calloc(1, sizeof(Feedback_Thread_Data));
             ftd->name = strdup(buf);
             ftd->base = strdup(str);
             eina_lock_new(&ftd->mutex);
             free(str);
             i++;
          }
     }
 
   eina_lock_new(&appdata.mutex);
   eina_condition_new(&appdata.condition, &appdata.mutex);
 
 
                             _thread_end_cb, _thread_cancel_cb, &appdata,
                                       _thread_cancel_cb, &appdata);
                             _thread_end_cb, _thread_cancel_cb, &appdata,
 
 
   _print_status();
 
 
   eina_condition_free(&appdata.condition);
   eina_lock_free(&appdata.mutex);
 
 
   return 0;
}
#define ECORE_GETOPT_VALUE_NONE
Definition for options that store a NULL value.
Definition Ecore_Getopt.h:1018
 
#define ECORE_GETOPT_VALUE_INT(val)
Definition for options that store a single value in a variable of type int.
Definition Ecore_Getopt.h:955
 
#define ECORE_GETOPT_VALUE_LIST(val)
Definition for options that store a single value in a variable of type list.
Definition Ecore_Getopt.h:1011
 
#define ECORE_GETOPT_APPEND_METAVAR(shortname, longname, help, metavar, type)
Definition for filling Ecore_Getopt_Desc table with an append action and a metavar.
Definition Ecore_Getopt.h:788
 
#define ECORE_GETOPT_VALUE_BOOL(val)
Definition for options that store a single value in a variable of type boolean.
Definition Ecore_Getopt.h:941
 
EAPI int ecore_getopt_parse(const Ecore_Getopt *parser, Ecore_Getopt_Value *values, int argc, char **argv)
Parses command line parameters.
Definition ecore_getopt.c:2032
 
#define ECORE_GETOPT_HELP(shortname, longname)
Definition for filling Ecore_Getopt_Desc table with a help action.
Definition Ecore_Getopt.h:859
 
#define ECORE_GETOPT_STORE_INT(shortname, longname, help)
Definition for macro that fill Ecore_Getopt_Desc table with an option of type int.
Definition Ecore_Getopt.h:279
 
#define ECORE_GETOPT_SENTINEL
Definition for filling Ecore_Getopt_Desc table with a sentinel to indicate the end of descriptions.
Definition Ecore_Getopt.h:927
 
@ ECORE_GETOPT_TYPE_STR
Value of type string.
Definition Ecore_Getopt.h:87
 
EAPI int ecore_shutdown(void)
Shuts down connections, signal handlers sockets etc.
Definition ecore.c:371
 
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition ecore.c:230
 
void ecore_main_loop_quit(void)
Quits the main loop once all the events currently on the queue have been processed.
Definition ecore_main.c:1321
 
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition ecore_main.c:1311
 
struct _Ecore_Thread Ecore_Thread
A handle for threaded jobs.
Definition Ecore_Common.h:1735
 
void * ecore_thread_global_data_find(const char *key)
Gets data stored in the hash shared by all threads.
Definition ecore_thread.c:1451
 
int ecore_thread_pending_get(void)
Gets the number of short jobs waiting for a thread to run.
Definition ecore_thread.c:1169
 
Eina_Bool ecore_thread_global_data_add(const char *key, void *value, Eina_Free_Cb cb, Eina_Bool direct)
Adds some data to a hash shared by all threads.
Definition ecore_thread.c:1373
 
Ecore_Thread * ecore_thread_run(Ecore_Thread_Cb func_blocking, Ecore_Thread_Cb func_end, Ecore_Thread_Cb func_cancel, const void *data)
Schedules a task to run in a parallel thread to avoid locking the main loop.
Definition ecore_thread.c:658
 
Eina_Bool ecore_thread_local_data_add(Ecore_Thread *thread, const char *key, void *value, Eina_Free_Cb cb, Eina_Bool direct)
Adds some data to a hash local to the thread.
Definition ecore_thread.c:1254
 
int ecore_thread_available_get(void)
Gets the number of threads available for running tasks.
Definition ecore_thread.c:1230
 
Eina_Bool ecore_thread_check(Ecore_Thread *thread)
Checks if a thread is pending cancellation.
Definition ecore_thread.c:892
 
Eina_Bool ecore_thread_global_data_del(const char *key)
Deletes from the shared hash the data corresponding to the given key.
Definition ecore_thread.c:1469
 
Eina_Bool ecore_thread_feedback(Ecore_Thread *thread, const void *msg_data)
Sends data from the worker thread to the main loop.
Definition ecore_thread.c:1037
 
Ecore_Thread * ecore_thread_feedback_run(Ecore_Thread_Cb func_heavy, Ecore_Thread_Notify_Cb func_notify, Ecore_Thread_Cb func_end, Ecore_Thread_Cb func_cancel, const void *data, Eina_Bool try_no_queue)
Launches a thread to run a task that can talk back to the main thread.
Definition ecore_thread.c:911
 
int ecore_thread_pending_feedback_get(void)
Gets the number of feedback jobs waiting for a thread to run.
Definition ecore_thread.c:1181
 
void * ecore_thread_local_data_find(Ecore_Thread *thread, const char *key)
Gets data stored in the hash local to the given thread.
Definition ecore_thread.c:1333
 
void ecore_thread_max_set(int num)
Sets the maximum number of threads allowed to run simultaneously.
Definition ecore_thread.c:1212
 
int ecore_thread_max_get(void)
Gets the maximum number of threads that can run simultaneously.
Definition ecore_thread.c:1205
 
Eina_Bool ecore_thread_local_data_del(Ecore_Thread *thread, const char *key)
Deletes from the thread's hash the data corresponding to the given key.
Definition ecore_thread.c:1354
 
int ecore_thread_active_get(void)
Gets the number of active threads running jobs.
Definition ecore_thread.c:1162
 
Eina_Bool ecore_thread_reschedule(Ecore_Thread *thread)
Asks for the function in the thread to be called again at a later time.
Definition ecore_thread.c:1149
 
Eina_Bool ecore_thread_cancel(Ecore_Thread *thread)
Cancels a running thread.
Definition ecore_thread.c:741
 
int ecore_thread_pending_total_get(void)
Gets the total number of pending jobs.
Definition ecore_thread.c:1193
 
Ecore_Timer * ecore_timer_add(double in, Ecore_Task_Cb func, const void *data)
Creates a timer to call the given function in the given period of time.
Definition ecore_timer.c:189
 
EINA_API Eina_Iterator * eina_file_ls(const char *dir)
Gets an iterator to list the content of a directory.
Definition eina_file_posix.c:633
 
EINA_API void eina_iterator_free(Eina_Iterator *iterator)
Frees an iterator.
Definition eina_iterator.c:98
 
#define EINA_ITERATOR_FOREACH(itr, data)
Definition for the macro to iterate over all elements easily.
Definition eina_iterator.h:448
 
EINA_API Eina_List * eina_list_append(Eina_List *list, const void *data)
Appends the given data to the given linked list.
Definition eina_list.c:584
 
#define EINA_LIST_FREE(list, data)
Definition for the macro to remove each list node while having access to each node's data.
Definition eina_list.h:1629
 
EINA_API void eina_stringshare_del(Eina_Stringshare *str)
Notes that the given string has lost an instance.
Definition eina_stringshare.c:533
 
EINA_API int eina_stringshare_strlen(Eina_Stringshare *str)
Notes that the given string must be shared.
Definition eina_stringshare.c:726
 
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition eina_types.h:539
 
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition eina_types.h:533
 
unsigned char Eina_Bool
Type to mimic a boolean.
Definition eina_types.h:527
 
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition eina_types.h:339
 
Structure that contains information on all command line options.
Definition Ecore_Getopt.h:212
 
structure of an iterator
Definition eina_iterator.h:159
 
Type for a generic double linked list.
Definition eina_list.h:318
 
Union listing the types of parameters that can take Getopt values.
Definition Ecore_Getopt.h:130