Commit Graph

142 Commits

Author SHA1 Message Date
Cedric BAIL 90b57c2ed0 * ecore: improve speed by reusing pipe and allocated structure.
SVN revision: 54896
2010-11-23 18:32:17 +00:00
Cedric BAIL 6f5333d336 * ecore: small cleanup.
SVN revision: 54893
2010-11-23 16:52:18 +00:00
Cedric BAIL c381181854 * ecore: revert comment.
This code is here to prevent the premature death of thread when
	apps killall of them, before recreating them again. This avoid
	call to pthread_create and increase throughput. The only information
	that I couldn't determine pragmatically is the timing. So that's
	the time the main loop has to create another Ecore_Thread, before
	needing to call pthread_create again.


SVN revision: 54633
2010-11-17 16:26:08 +00:00
Carsten Haitzler a27ab1e696 see comment.
SVN revision: 54549
2010-11-14 09:00:24 +00:00
Cedric BAIL e61f8560ea * ecore: break Ecore_Thread API once and for all to make it consistent.
SVN revision: 54502
2010-11-12 13:28:19 +00:00
Cedric BAIL ea2cfb0d31 * ecore: always check for func_cancel being not NULL before using it.
Reported by Hugo Camboulive <hugo.camboulive@gmail.com>.


SVN revision: 53851
2010-10-25 09:39:00 +00:00
Vincent Torri 640dc89d1b [ecore] fix compilation when pthread is not available
SVN revision: 53777
2010-10-22 17:39:25 +00:00
Vincent Torri a17c58d0b0 improve doc layout
SVN revision: 53509
2010-10-17 07:03:28 +00:00
Cedric BAIL 94fb47d168 * ecore: improve and fix ecore_thread destruction.
SVN revision: 53411
2010-10-14 16:45:48 +00:00
Cedric BAIL 25e84c7f3d * ecore: fix possible race. It also make ecore_thread_run
match ecore_thread_feedback_run better.

	NOTE: I know it breaks API/ABI compatibility for that call,
	but that's the only sane solution I could found.


SVN revision: 53370
2010-10-13 17:45:07 +00:00
Cedric BAIL 00c7021fcb * ecore: turn on and off eina threads support when needed.
SVN revision: 53364
2010-10-13 16:44:15 +00:00
Eduardo de Barros Lima 2f1827d132 Ecore: No need to #define _GNU_SOURCE
SVN revision: 53162
2010-10-07 20:40:33 +00:00
Cedric BAIL 6b5c401b1f * ecore: fix typo.
SVN revision: 53098
2010-10-06 13:01:35 +00:00
Cedric BAIL d617b8574d * ecore: refcount send and received notify to prevent leak on
ecore_thread_cancel.


SVN revision: 53096
2010-10-06 11:48:45 +00:00
Cedric BAIL 05262d2120 * ecore: remove thread from the correct list.
SVN revision: 53029
2010-10-04 15:24:34 +00:00
Vincent Torri 16263f52cc tab--
SVN revision: 52918
2010-09-30 06:09:20 +00:00
Lucas De Marchi 85599b20eb Use eina_sched_prio_drop()
SVN revision: 52652
2010-09-23 20:39:40 +00:00
Cedric BAIL b462783cae * ecore: oops, forgot that change.
SVN revision: 52580
2010-09-22 11:09:44 +00:00
Cedric BAIL 8036a32918 * ecore: rename ecore_long_run to ecore_thread_feedback_run.
SVN revision: 52573
2010-09-22 09:47:55 +00:00
Mike Blumenkrantz f3a2858f37 remove unused variable
SVN revision: 52529
2010-09-21 02:16:40 +00:00
Mike Blumenkrantz 130f5bec81 doxy error fixes
SVN revision: 52512
2010-09-20 20:33:50 +00:00
Lucas De Marchi 71cba7da35 Fix typos
"he->the" where appropriate



SVN revision: 52493
2010-09-20 17:09:13 +00:00
Carsten Haitzler 773c57ea1a warning--
SVN revision: 52453
2010-09-19 03:09:09 +00:00
Lucas De Marchi 325e08065d Fix priority dropping
Lowering priority was wrong. Some bugs:

1) You don't lower the priority by setting the scheduler policy to some
   of the real-time ones (SCHED_RR or SCHER_FIFO). If you do so, you are
   actually increasing the priority of the workers and your main thread
   you be preempted and stalled until the workers complete their job.
   Fortunately this will only happen if your programming is running as
   root, as normal users (without CAP_SYS_NICE) are unable to set
   priority to real-time values.

2) setpriority() and getpriority() are not part of pthread and you can't
   use the id returned by pthread. Manpage explicitly says so on
   pthread_self(3):
   "The  thread ID returned by pthread_self() is not the same thing as the
       kernel thread ID returned by a call to gettid(2)."

   Since glibc does not have a gettid, here we are using
   syscall(SYS_gettid)

This patch was tested with the program below. Compile and run:
   $ gcc p_hello2.c -o p_hello2 -lpthread
   $ ./p_hello2 10

You'll see that the main thread remains with its priority and threads
created by the main thread change their own niceness.

#include <errno.h>
#include <pthread.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>

/* Lower priority of current thread.
 *
 * It's used by worker threads so they use up "bg cpu" as it was really intended
 * to work. If current thread is running with real-time priority, we decrease
 * our priority by 5. This is done in a portable way.  Otherwise we are
 * running with SCHED_OTHER policy and there's no portable way to set the nice
 * level on current thread. In Linux, it does work and it's the only one that is
 * implemented.
 */
static void
_ecore_thread_pri_drop(void)
{
   struct sched_param param;
   int pol, prio, ret;
   pid_t tid;
   pthread_t pthread_id;

   pthread_id = pthread_self();
   ret = pthread_getschedparam(pthread_id, &pol, &param);
   if (ret)
     {
        fprintf(stderr, "Unable to query sched parameters\n");
        return;
     }

   if (pol == SCHED_RR || pol == SCHED_FIFO)
     {
        prio = sched_get_priority_max(pol);
        param.sched_priority += 5;
        if (prio > 0 && param.sched_priority > prio)
           param.sched_priority = prio;

        pthread_setschedparam(pthread_id, pol, &param);
     }
#ifdef __linux__
   else
     {
        tid = syscall(SYS_gettid);
        errno = 0;
        prio = getpriority(PRIO_PROCESS, tid);
        if (errno == 0)
          {
             prio += 5;
             if (prio > 19)
                prio = 19;

             setpriority(PRIO_PROCESS, tid, prio);
          }
     }
 #endif
}

/*
 * p_hello.c -- a hello program (in pthread)
 */
#define MAX_THREAD 1000

typedef struct {
    int id;
} parm;

void *hello(void *arg)
{
    parm *p=(parm *)arg;
    pid_t tid;
    int prio;
    tid =  syscall(SYS_gettid);
    printf("[%d] Hello from node %d\n", tid, p->id);
    pthread_yield();

    printf("[%d] tid=%lu\n", tid);

    _ecore_thread_pri_drop();

    prio = getpriority(PRIO_PROCESS, tid);
    printf("[%d] New nice value: %d\n", tid, prio);
    return (NULL);
}

void main(int argc, char* argv[]) {
    int n,i;
    pthread_t *threads;
    pthread_attr_t pthread_custom_attr;
    parm *p;

    pid_t tid;
    int prio;

    if (argc != 2)
    {
        printf ("Usage: %s n\n  where n is no. of threads\n",argv[0]);
        exit(1);
    }

    n=atoi(argv[1]);

    if ((n < 1) || (n > MAX_THREAD)) {
        printf ("The no of thread should between 1 and %d.\n",MAX_THREAD);
        exit(1);
    }

    threads = (pthread_t *)malloc(n * sizeof(*threads));
    pthread_attr_init(&pthread_custom_attr);

    p = (parm *)malloc(n * sizeof(parm));
    /* Start up thread */

    tid = syscall(SYS_gettid);
    for (i=0; i<n; i++) {
        prio = getpriority(PRIO_PROCESS, tid);
        printf("[%d] root thread nice value: %d\n", tid, prio);

        p[i].id=i;
        pthread_create(&threads[i], &pthread_custom_attr, hello, (void *)(p+i));
    }

    /* Synchronize the completion of each thread. */

    for (i=0; i<n; i++) {
        pthread_join(threads[i],NULL);
    }
    free(p);
}



SVN revision: 52039
2010-09-09 11:48:31 +00:00
Lucas De Marchi be1b6d32ef Fix common misspellings
Following misspellings were fixed:

alledgedly->allegedly
cant->can't
carefull->careful
consistant->consistent
currenly->currently
dependancy->dependency
descripters->descriptors
doesnt->doesn't
dosen't->doesn't
existant->existent
exmaple->example
inbetween->between
independant->independent
isnt->isn't
mroe->more
neccessary->necessary
occured->occurred
occurence->occurrence
parrallel->parallel
particualr->particular
preceeding->preceding
recieved->received
recieves->receives
seperate->separate
substraction->subtraction
succesfully->successfully
successfull->successful
sucess->success
supress->suppress
usefull->useful
witht->with



SVN revision: 51986
2010-09-08 11:23:42 +00:00
Cedric BAIL d098e05951 * ecore: fix error detection of ecore_pipe_add.
SVN revision: 51926
2010-09-06 16:36:44 +00:00
Carsten Haitzler 9049befccf make 1 func to set lower pri - fall back to setpriority on linux and
try it there only.



SVN revision: 51885
2010-09-04 14:32:50 +00:00
Carsten Haitzler 05cf40fc4d same - back to RR.
SVN revision: 51878
2010-09-04 05:40:38 +00:00
Carsten Haitzler 2c397940de rr->other
SVN revision: 51873
2010-09-04 00:54:53 +00:00
Cedric BAIL b3dd293384 * ecore: ecore_thread are not here to bring your computer down, so
reduce their priority too.


SVN revision: 51862
2010-09-03 13:39:53 +00:00
Carsten Haitzler 2aebc5b458 fix ecore_thread to use pthread correctly. should build on windows now
too.



SVN revision: 51621
2010-08-25 00:26:01 +00:00
Mike Blumenkrantz 236d58f0de ecore_thread_pool -> ecore_thread_local
SVN revision: 51272
2010-08-18 08:56:44 +00:00
Vincent Torri aaffd2acac fix compilation without thread support
SVN revision: 51267
2010-08-17 19:21:47 +00:00
Cedric BAIL 2531cd8114 * ecore: fix cancel from another thread.
SVN revision: 51119
2010-08-14 16:15:09 +00:00
Mike Blumenkrantz a475971aaa convert all function pointers to typedefs, add doxy stubs for typedefs.
note: I've chosen to consolidate typedefs where possible to simplify things

my time is limited this week, so feel free to expand on the doxy stubs I've added if you know what they do


SVN revision: 50803
2010-08-04 02:55:20 +00:00
Mike Blumenkrantz bec24bf71f fix random value generator.
SPANK SPANK SPANK!!!


SVN revision: 50750
2010-08-02 19:36:37 +00:00
Mike Blumenkrantz 122ec75b01 return void* for data functions; depend on user not to be stupid (hahahahahah)
fix doxy to display correctly and be accurate once again
TODO: add functions to rwlock global data while threads are modifying it?


SVN revision: 50692
2010-07-30 20:33:32 +00:00
Mike Blumenkrantz d25cc594f9 remove ecore_thread_pool_data_wait, make thread data struct private again, return void* on _set(), fix global_wait to not mutex longer than wait time when no data added
SVN revision: 50687
2010-07-30 15:56:18 +00:00
Mike Blumenkrantz 7c45637e38 add data freeing support to ecore thread data api
TO FUTURE MIKE: you were too tired to update the doxy last night and instead of writing the doxy updates you fell asleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee


SVN revision: 50682
2010-07-30 08:52:18 +00:00
Mike Blumenkrantz 1ddcb2340a fix threadless compile
SVN revision: 50528
2010-07-27 03:59:04 +00:00
Mike Blumenkrantz 24a6c8ce55 ecore_thread_cancel is now nullsafe, returning EINA_TRUE
SVN revision: 50523
2010-07-26 20:41:54 +00:00
Mike Blumenkrantz d214a77221 rename function typedefs
SVN revision: 50506
2010-07-26 07:19:27 +00:00
Mike Blumenkrantz 854ccebd14 whoops
SVN revision: 50504
2010-07-26 05:47:33 +00:00
Mike Blumenkrantz d5b507adcc add typedefs for ecore thread function types because I'm tired of typing them out
SVN revision: 50499
2010-07-26 04:20:18 +00:00
Mike Blumenkrantz 034e320ac1 fix longstanding leak
SVN revision: 50470
2010-07-24 02:05:35 +00:00
Mike Blumenkrantz bc9b536b14 correctly init some variables that I missed somehow. I blame Sachiel.
SVN revision: 50465
2010-07-23 22:28:18 +00:00
Mike Blumenkrantz 15f3719964 shut up eina
SVN revision: 50460
2010-07-23 17:52:50 +00:00
Mike Blumenkrantz 2e9651eeca fix leak in thread_shutdown, use lots of mutexes and conditionals instead of sleeps to wait in data_wait functions
SVN revision: 50459
2010-07-23 17:30:21 +00:00
Mike Blumenkrantz f10870c933 whoops
SVN revision: 50455
2010-07-23 16:40:40 +00:00
Mike Blumenkrantz e488119c47 +ecore_thread_{global,pool}_data_wait, to allow waiting for data in the global or pool data contexts and simulate g_async_queue in a less mutexy fashion
SVN revision: 50454
2010-07-23 16:24:35 +00:00
Mike Blumenkrantz 4436081e5b add threadsafe global data to threads, allowing for communication between threads and other threads and threads and main loop
SVN revision: 50453
2010-07-23 15:33:22 +00:00
Mike Blumenkrantz 8ed22a2023 rename mutex
SVN revision: 50451
2010-07-23 13:35:14 +00:00
Mike Blumenkrantz 680ec26e8a fix doxy
SVN revision: 50450
2010-07-23 13:12:42 +00:00
Mike Blumenkrantz 9efdf6c9d4 remove unnecessary mutexes, expand pthread self member to short_run threads, make thread pool data work on short_run threads, ecore_thread_pool_data_modify_or_add -> ecore_thread_pool_data_set
SVN revision: 50449
2010-07-23 13:08:38 +00:00
Mike Blumenkrantz c85f521ffa +ecore_thread_pool_data_modify_or_add
SVN revision: 50443
2010-07-23 04:17:41 +00:00
Mike Blumenkrantz 92cd8f2705 api change to ecore_thread_pool_data_add, now has 4th argument "direct" to avoid copying key value if desired
SVN revision: 50442
2010-07-23 03:39:52 +00:00
Mike Blumenkrantz ebd21717c6 +ecore_thread_pool_data_{add,find,del}: start of ecore_thread_pool api. these calls are used from heavy_run to manage data within a thread pool. more to come
SVN revision: 50438
2010-07-22 20:28:34 +00:00
Mike Blumenkrantz 0ffbf90242 should probably make thread functions threadsafe. and compile.
SVN revision: 50411
2010-07-21 08:33:25 +00:00
Mike Blumenkrantz 977be45e37 fix some function variables and a cedric-requested rename
SVN revision: 50409
2010-07-21 07:09:51 +00:00
Mike Blumenkrantz 00023656af man I fail at formatting
SVN revision: 50406
2010-07-21 04:26:57 +00:00
Mike Blumenkrantz 82d7183f47 +ecore_thread_total_get to return total number of pending jobs
SVN revision: 50405
2010-07-21 04:03:40 +00:00
Mike Blumenkrantz 35ca9e3e12 +ecore_thread_max_reset, ecore_thread_avail_get for more thread functionality, also fix formatting
SVN revision: 50399
2010-07-21 02:12:10 +00:00
Mike Blumenkrantz ec1d528178 +ecore_thread_max_{set,get} to return/set the max number of threads ecore will attempt to run simultaneously
SVN revision: 50397
2010-07-21 01:04:28 +00:00
Mike Blumenkrantz 5701a455d1 some variable renames to make this easier to understand
SVN revision: 50376
2010-07-20 09:40:53 +00:00
Mike Blumenkrantz 75d478dfac +ecore_thread_active_get, ecore_thread_pending_get, ecore_thread_pending_long_get to retrieve number of threads present with given status
SVN revision: 50375
2010-07-20 09:40:18 +00:00
Mike Blumenkrantz 952dd2bd44 note: '/*' is not how you begin a doxygen code block
SVN revision: 50372
2010-07-20 05:25:02 +00:00
Cedric BAIL 3015da94da * ecore: fix build without thread.
NOTE: if you build ecore without pthread support, you really should know
	that it is a bad idea. Only people without pthread support on their
	device/C library should disable it.


SVN revision: 50200
2010-07-12 14:39:06 +00:00
Vincent Torri 3e15fef7b8 fix warnings
SVN revision: 50174
2010-07-10 11:09:40 +00:00
Vincent Torri 5ae1fc61e1 fix spaces
SVN revision: 50173
2010-07-10 11:08:20 +00:00
Cedric BAIL f424ca1e1e * ecore: for the 50 000 commits, why not adding some docs ?
SVN revision: 50000
2010-07-02 16:01:21 +00:00
Cedric BAIL 062f4c3920 * ecore: fix long run thread, now that I have a nice user.
SVN revision: 49994
2010-07-02 11:15:20 +00:00
Cedric BAIL d1fcb71f84 * ecore: add ecore_long_run facility with notify to main loop.
SVN revision: 49948
2010-06-30 13:25:28 +00:00
Cedric BAIL fbe9064310 * ecore: Ecore callback really should return Eina_Bool.
SVN revision: 49829
2010-06-24 16:15:56 +00:00
Iván Briano e0dedc5eb9 Release lock before returning
SVN revision: 47980
2010-04-12 21:51:35 +00:00
Hannes Janetzek 5fd3adcc68 make ecore thread cancel work. someone knowing the internals should check this again.
SVN revision: 47866
2010-04-09 04:52:04 +00:00
Cedric BAIL 816974ff0b * ecore: Match what doc when disabling thread support in ecore.
SVN revision: 46467
2010-02-25 15:26:38 +00:00
Sebastian Dransfeld 0a9456ccf7 Remove duplication from ecore headers
Clean up Ecore.h and ecore_private.h

SVN revision: 44664
2009-12-22 21:15:12 +00:00
Cedric BAIL 78fdf79b00 * ecore: Cleanup some warning.
SVN revision: 44631
2009-12-21 16:17:29 +00:00
Cedric BAIL 579f2e5447 * evas_preload, ecore_thread: On memory allocation failure do call the cancel function too.
SVN revision: 44624
2009-12-21 12:25:32 +00:00
Vincent Torri 14513477b9 fix warnings and returned value when no pthread
SVN revision: 44569
2009-12-19 11:43:44 +00:00
Vincent Torri 1b7b929a09 * link correctly ecore against pthread
* use the efl_pthread.m4 macro
 * add configure output for pthread support in ecore


SVN revision: 43627
2009-11-11 23:43:58 +00:00
Vincent Torri a206a8b183 fix compilation when no pthread is available
Cedric: returning false in ecore_thread_cancel is good ?

SVN revision: 43548
2009-11-08 22:16:17 +00:00
Cedric BAIL 6310f0ef55 * ecore_thread: Add possibility to cancel Ecore_Thread.
WARNING: THIS BREAK API AND ABI !!!


SVN revision: 43501
2009-11-06 22:15:04 +00:00
Vincent Torri 43d3c84907 no need for ref count in ecore_thread init/shutdown functions
SVN revision: 42991
2009-10-10 03:24:56 +00:00
Vincent Torri d8acbfc6f6 rename ecore_thread_init and ecore_thread_shutdown to fit usual private function names
SVN revision: 42240
2009-09-04 05:49:54 +00:00
Lars Munch 023b8909af Added missing pthread guard
Patch from Vincent Torri



SVN revision: 42005
2009-08-26 05:59:56 +00:00
Lars Munch 2e7e9169e7 Fix building without pthread support
SVN revision: 41880
2009-08-20 06:09:15 +00:00
Carsten Haitzler 447051bf3c dont use #ifdeffed out calls
SVN revision: 41726
2009-08-13 00:30:59 +00:00
Cedric BAIL 7db27df3c8 * ecore_thread: Fix the remaining comment from Vincent.
SVN revision: 41581
2009-08-04 09:13:49 +00:00
Cedric BAIL 13cea2628b * ecore_thread: Another dead lock spotted by Sachiel.
SVN revision: 41570
2009-08-03 14:09:09 +00:00
Cedric BAIL e7f691a9f2 * ecore_thread: Prevent mutex lock, thanks to Sachiel.
SVN revision: 41564
2009-08-03 08:19:33 +00:00
Cedric BAIL 2bb8e5ad8e * ecore_thread_run: Add a facility to run heavy code in another thread
that still integrate cleanly with the EFL.

	ecore_thread_run need two callbacks :

	* func_heavy is called from another thread and should not use the
	EFL except Eina, but carefully.

	* func_end is called when func_heavy is done, but from inside ecore
	main loop, so you can at this point call every EFL functions without
	fear.

	Note :

	The system automatically detect how many CPU you have and will spread
	the load on all of them.

	You must not assume that the result will come in the same order you
	requested it. Depend on each CPU load and how heavy the function on it
	are.



SVN revision: 41555
2009-07-31 17:06:11 +00:00