Commit Graph

114 Commits

Author SHA1 Message Date
Mike McCormack bfffcce2fe ecore: Create a lockless ecore_event_handler_del
Signed-off-by: Mike McCormack <mj.mccormack@samsung.com>

SVN revision: 62375
2011-08-12 05:22:16 +00:00
Mike McCormack a541e19c16 ecore: Use eina locks for _ecore_lock()
Always count lock calls too.

Signed-off-by: Mike McCormack <mj.mccormack@samsung.com>

SVN revision: 62372
2011-08-12 05:21:49 +00:00
Mike McCormack 5c8256e337 ecore: Add main loop thread safety
Thread safety is disabled by default.
Enable it with --enable-thread-safety

Should cover timers, events, animators, idlers and fd handlers.

Tested with Enlightenment and elementary_test.

Signed-off-by: Mike McCormack <mj.mccormack@samsung.com>

SVN revision: 61851
2011-07-28 12:01:16 +00:00
Iván Briano 4da2c481b5 Fix some double frees. The hash frees the data itself.
SVN revision: 61292
2011-07-12 13:36:19 +00:00
Iván Briano a5b1673a70 Little errors no one cares about, but make thread-less case work as expected
SVN revision: 61129
2011-07-07 18:39:25 +00:00
Mike McCormack 18193e9918 ecore: Fix thread check for quicklaunch
Signed-off-by: Mike McCormack <mj.mccormack@samsung.com>

SVN revision: 61109
2011-07-07 10:11:13 +00:00
Iván Briano 693af50513 Expand Ecore_Thread docs.
Thanks cedric for technical advice.
Thanks discomfitor for helping when English vanished.
Thanks myself for keeping both of them busy so they don't break SVN *too* much.


SVN revision: 61095
2011-07-06 18:08:21 +00:00
Mike McCormack f7ec79e13e ecore: Add function to check we're the main loop thread
Rearrange the the order of startup to avoid triggering
the thread checks in ecore_event_type_new().

Signed-off-by: Mike McCormack <mj.mccormack@samsung.com>

SVN revision: 61040
2011-07-05 11:13:20 +00:00
Cedric BAIL 94718fa484 ecore: forgotten eina_threads_init/shutdown.
SVN revision: 60801
2011-06-29 08:24:13 +00:00
Iván Briano 0365a18df7 It doesn't look like this matters, so let's fix the build.
And if it does matter, I hope it breaks something from cedric. One femur, for example. Or both.


SVN revision: 60789
2011-06-29 02:32:37 +00:00
Cedric BAIL 5d473313b0 ecore: do count threads only in the main loop.
NOTE: for an unknow reason I always get the wrong number
of threads when doing the computation from the thread.
Even if I use volatile and mutex. So to avoid that move
that stuff in the main loop. It increase the complexity
of the code, but at least it work.


SVN revision: 60767
2011-06-28 15:53:19 +00:00
Cedric BAIL edfeab7295 ecore: actually limit the number of pipe in the cache.
SVN revision: 60763
2011-06-28 14:53:34 +00:00
Vincent Torri d9e7ffbf87 Ecore: ecore_thread : free resources, spotted by Ulrich Eckhardt
SVN revision: 60057
2011-06-07 22:21:25 +00:00
Christopher Michael 61ec1408bd Ecore: Fix shadow declaration of variable 'time'.
SVN revision: 59720
2011-05-27 02:06:26 +00:00
Vincent Torri 223bcd6866 Ecore : ecore_thread: use Sleep() on Windows, instead of usleep()
usleep() does not exists on Windows. Use Sleep() instead. But the
resolution timers are not good on Windows. the sleep will be around
50ms at best.


SVN revision: 59466
2011-05-17 07:17:53 +00:00
Daniel Juyung Seo 6ef3841a37 Ecore: Removed trailing whitespaces.
SVN revision: 58753
2011-04-20 14:15:33 +00:00
Cedric BAIL ab3150b53e ecore: add ecore_thread_reschedule.
SVN revision: 57797
2011-03-16 13:16:14 +00:00
Christopher Michael c0096e92ad Ecore_Thread: Fix yet another doxy typo.
SVN revision: 57326
2011-02-25 18:42:44 +00:00
Christopher Michael 4ba275a120 Ecore_Thread: Fix doxy typo.
SVN revision: 57325
2011-02-25 18:41:37 +00:00
Vincent Torri a3ffd27636 remove win7 code and fix other minor problems
SVN revision: 55023
2010-11-26 18:41:43 +00:00
Vincent Torri 95f36c0e18 more fixes, but needs to remove Windows 7 code, now...
SVN revision: 55019
2010-11-26 15:34:30 +00:00
Vincent Torri 6b4b7bc42d add native win32 thread support in ecore_thread. Not tested a lot at all.
SVN revision: 55014
2010-11-26 13:50:31 +00:00
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