Replace Main->lock with an anoynous structure pointer

This way it's not needed to include BLI_threads.h from the
BKE_main.h which helps avoiding adding PThreads includes to
each library which uses Main on Windows.

From the API point of view it's now MainLock* and to lock or
unlock the main you're to use BKE_main_(un)lock().

This solves compilation error on Windows with SCons.
This commit is contained in:
Sergey Sharybin 2014-06-26 14:55:40 +06:00
parent 33e8451d4b
commit 6135556f45
4 changed files with 26 additions and 10 deletions

@ -84,6 +84,9 @@ void BKE_libblock_free_data(struct Main *bmain, struct ID *id);
struct Main *BKE_main_new(void);
void BKE_main_free(struct Main *mainvar);
void BKE_main_lock(struct Main *bmain);
void BKE_main_unlock(struct Main *bmain);
void BKE_main_id_tag_idcode(struct Main *mainvar, const short type, const bool tag);
void BKE_main_id_tag_listbase(struct ListBase *lb, const bool tag);
void BKE_main_id_tag_all(struct Main *mainvar, const bool tag);

@ -41,7 +41,6 @@
*
*/
#include "DNA_listBase.h"
#include "BLI_threads.h"
#ifdef __cplusplus
extern "C" {
@ -49,6 +48,7 @@ extern "C" {
struct EvaluationContext;
struct Library;
struct MainLock;
typedef struct Main {
struct Main *next, *prev;
@ -98,7 +98,7 @@ typedef struct Main {
/* Evaluation context used by viewport */
struct EvaluationContext *eval_ctx;
SpinLock lock;
struct MainLock *lock;
} Main;
#define MAIN_VERSION_ATLEAST(main, ver, subver) \

@ -71,6 +71,7 @@
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
#include "BLI_threads.h"
#include "BLF_translation.h"
#include "BKE_action.h"
@ -747,14 +748,14 @@ void *BKE_libblock_alloc(Main *bmain, short type, const char *name)
id = alloc_libblock_notest(type);
if (id) {
BLI_spin_lock(&bmain->lock);
BKE_main_lock(bmain);
BLI_addtail(lb, id);
id->us = 1;
id->icon_id = 0;
*( (short *)id->name) = type;
new_id(lb, id, name);
/* alphabetic insertion: is in new_id */
BLI_spin_unlock(&bmain->lock);
BKE_main_unlock(bmain);
}
DAG_id_type_tag(bmain, type);
return id;
@ -1008,7 +1009,7 @@ void BKE_libblock_free_ex(Main *bmain, void *idv, bool do_id_user)
}
/* avoid notifying on removed data */
BLI_spin_lock(&bmain->lock);
BKE_main_lock(bmain);
if (free_notifier_reference_cb)
free_notifier_reference_cb(id);
@ -1016,7 +1017,7 @@ void BKE_libblock_free_ex(Main *bmain, void *idv, bool do_id_user)
BLI_remlink(lb, id);
BKE_libblock_free_data(bmain, id);
BLI_spin_unlock(&bmain->lock);
BKE_main_unlock(bmain);
MEM_freeN(id);
}
@ -1048,7 +1049,8 @@ Main *BKE_main_new(void)
Main *bmain = MEM_callocN(sizeof(Main), "new main");
bmain->eval_ctx = MEM_callocN(sizeof(EvaluationContext),
"EvaluationContext");
BLI_spin_init(&bmain->lock);
bmain->lock = MEM_mallocN(sizeof(SpinLock), "main lock");
BLI_spin_init(bmain->lock);
return bmain;
}
@ -1111,11 +1113,22 @@ void BKE_main_free(Main *mainvar)
}
}
BLI_spin_end(&mainvar->lock);
BLI_spin_end(mainvar->lock);
MEM_freeN(mainvar->lock);
MEM_freeN(mainvar->eval_ctx);
MEM_freeN(mainvar);
}
void BKE_main_lock(struct Main *bmain)
{
BLI_spin_lock(bmain->lock);
}
void BKE_main_unlock(struct Main *bmain)
{
BLI_spin_unlock(bmain->lock);
}
/* ***************** ID ************************ */

@ -780,13 +780,13 @@ void test_object_materials(Main *bmain, ID *id)
return;
}
BLI_spin_lock(&bmain->lock);
BKE_main_lock(bmain);
for (ob = bmain->object.first; ob; ob = ob->id.next) {
if (ob->data == id) {
BKE_material_resize_object(ob, *totcol, false);
}
}
BLI_spin_unlock(&bmain->lock);
BKE_main_unlock(bmain);
}
void assign_material_id(ID *id, Material *ma, short act)